mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-15 20:21:03 +00:00
Added start of initialization animation
This commit is contained in:
@@ -25,30 +25,37 @@ Program to create a car monitor display using:
|
||||
#define MS(x) x * 1000
|
||||
#define S(x) MS(x) * 1000
|
||||
|
||||
#define INIT_TEXT_WIDTH 15
|
||||
#define FLAG_INIT_UPDATE_TEXT_POS 0x01
|
||||
#define FLAG_INIT_CLEAR_POS 0x02
|
||||
#define FLAG_INIT_UPDATE_PERCENT_POS 0x03
|
||||
|
||||
extern uint8_t BigFont[];
|
||||
extern uint8_t SmallFont[];
|
||||
extern uint8_t OCR_A_Extended_M[];
|
||||
|
||||
char should_clear = 1;
|
||||
char led_state = LOW;
|
||||
char flag = 0;
|
||||
char counter_temp = 0;
|
||||
char main_color = 0;
|
||||
char init_text_i = 0;
|
||||
char init_flag = 0;
|
||||
char init_text_i = -1;
|
||||
int init_text_x = 100;
|
||||
char init_text[] = "Initialising...";
|
||||
char text_temp[2] = {'a','\0'};
|
||||
char init_text[] PROGMEM = "Initialising...";
|
||||
char text_temp[2] = {'a', '\0'};
|
||||
int init_percent = 0;
|
||||
|
||||
void on_init_enter();
|
||||
void on_init_run();
|
||||
void on_init_exit();
|
||||
void on_main_enter();
|
||||
void on_main_run();
|
||||
void __state_none(){ /* do nothing */}
|
||||
void __state_none()
|
||||
{ /* do nothing */
|
||||
}
|
||||
|
||||
state_t init_state =
|
||||
{
|
||||
.id = STATE_INIT,
|
||||
.next = STATE_CAR_INFO,
|
||||
.next = STATE_INIT,
|
||||
.on_enter = &on_init_enter,
|
||||
.on_run = &on_init_run,
|
||||
.on_exit = &on_init_exit};
|
||||
@@ -65,25 +72,70 @@ state_t main_state =
|
||||
/* Standard Arduino Mega/Due shield : <display model>,38,39,40,41 */
|
||||
UTFT display(ILI9486, 38, 39, 40, 41);
|
||||
|
||||
/****************************/
|
||||
/*INIT STATE*/
|
||||
/****************************/
|
||||
|
||||
void on_init_enter()
|
||||
{
|
||||
display.clrScr();
|
||||
|
||||
Timer0.attachInterrupt(update_init_text);
|
||||
Timer0.start(MS(200));
|
||||
|
||||
// TODO change to update when initializing bluetooth..
|
||||
Timer1.attachInterrupt(update_percent_test);
|
||||
Timer1.start(MS(60));
|
||||
|
||||
Serial.println("Entering init state!");
|
||||
}
|
||||
|
||||
void on_init_run()
|
||||
{
|
||||
delay(500);
|
||||
Serial.println("init!");
|
||||
if (init_flag & (1 << FLAG_INIT_CLEAR_POS))
|
||||
{
|
||||
init_flag &= ~(1 << FLAG_INIT_CLEAR_POS);
|
||||
display.setColor(VGA_BLACK);
|
||||
/*clear only initializing text*/
|
||||
display.print(" ",(display.getDisplayXSize() / 2) - (INIT_TEXT_WIDTH * display.getFontXsize() / 2),display.getDisplayYSize() / 2 + 50);
|
||||
}
|
||||
if (init_flag & (1 << FLAG_INIT_UPDATE_TEXT_POS))
|
||||
{
|
||||
init_flag &= ~(1 << FLAG_INIT_UPDATE_TEXT_POS);
|
||||
display.setColor(VGA_AQUA);
|
||||
int x_position = (display.getDisplayXSize() / 2 - (INIT_TEXT_WIDTH * display.getFontXsize() / 2)) + (init_text_i * display.getFontXsize());
|
||||
Serial.println(x_position);
|
||||
text_temp[0] = init_text[init_text_i];
|
||||
display.print(text_temp, x_position, display.getDisplayYSize() / 2 + 50); // print as string with one character
|
||||
}
|
||||
if (init_flag & (1 << FLAG_INIT_UPDATE_PERCENT_POS))
|
||||
{
|
||||
init_flag &= ~(1 << FLAG_INIT_UPDATE_PERCENT_POS);
|
||||
int percent_x_pos = (display.getDisplayXSize() / 2 - (INIT_TEXT_WIDTH * display.getFontXsize() / 2)) + (INIT_TEXT_WIDTH * display.getFontXsize());
|
||||
display.setColor(VGA_BLACK);
|
||||
/*clear text region for percent*/
|
||||
display.print(" ", percent_x_pos, display.getDisplayYSize() / 2 + 50);
|
||||
|
||||
display.setColor(VGA_FUCHSIA);
|
||||
char *percent_text = (char *)malloc(3 * sizeof(char));
|
||||
sprintf(percent_text, "%d", init_percent);
|
||||
display.print(percent_text, percent_x_pos, display.getDisplayYSize() / 2 + 50);
|
||||
display.print("%", percent_x_pos + 3 * display.getFontXsize(), display.getDisplayYSize() / 2 + 50);
|
||||
free(percent_text);
|
||||
}
|
||||
}
|
||||
|
||||
void on_init_exit()
|
||||
{
|
||||
Serial.println("Exiting init state!");
|
||||
display.clrScr();
|
||||
Timer0.stop();
|
||||
}
|
||||
|
||||
/****************************/
|
||||
/*MAIN STATE*/
|
||||
/****************************/
|
||||
|
||||
void on_main_enter()
|
||||
{
|
||||
Serial.println("Entering main loop");
|
||||
@@ -95,9 +147,25 @@ void on_main_run()
|
||||
Serial.println("main!");
|
||||
}
|
||||
|
||||
void timer_handler()
|
||||
void update_init_text()
|
||||
{
|
||||
statemachine_next();
|
||||
init_text_i++;
|
||||
if (init_text_i == 15)
|
||||
{
|
||||
init_text_i = 0;
|
||||
init_flag |= (1 << FLAG_INIT_CLEAR_POS);
|
||||
}
|
||||
init_flag |= (1 << FLAG_INIT_UPDATE_TEXT_POS);
|
||||
}
|
||||
|
||||
void update_percent_test()
|
||||
{
|
||||
init_percent++;
|
||||
if (init_percent > 100)
|
||||
{
|
||||
init_percent = 0;
|
||||
}
|
||||
init_flag |= (1 << FLAG_INIT_UPDATE_PERCENT_POS);
|
||||
}
|
||||
|
||||
void setup()
|
||||
@@ -114,7 +182,7 @@ void setup()
|
||||
|
||||
/* Init display */
|
||||
display.InitLCD();
|
||||
display.setFont(BigFont);
|
||||
display.setFont(OCR_A_Extended_M);
|
||||
|
||||
#if (DEBUG == 1)
|
||||
Serial.println("Starting");
|
||||
@@ -125,10 +193,6 @@ void setup()
|
||||
statemachine_register_state(&init_state, STATE_INIT);
|
||||
statemachine_register_state(&main_state, STATE_CAR_INFO);
|
||||
statemachine_init();
|
||||
|
||||
Timer3.attachInterrupt(timer_handler);
|
||||
Timer3.start(S(5));
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
||||
Reference in New Issue
Block a user