mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-15 20:21:03 +00:00
add bluetooth state and progress bar
This commit is contained in:
@@ -48,6 +48,8 @@ Program to create a car monitor display using:
|
||||
#define RAM_TEXT_WIDTH 9
|
||||
#define DEV_LABEL_LENGTH 10
|
||||
|
||||
#define COLOR_ORANGE 255, 96, 33
|
||||
|
||||
enum DeviceLabel
|
||||
{
|
||||
DEV_CPU = 0,
|
||||
@@ -56,6 +58,13 @@ enum DeviceLabel
|
||||
DEV_DONE = 3
|
||||
};
|
||||
|
||||
enum BluetoothState
|
||||
{
|
||||
BT_INITIALISING = 0,
|
||||
BT_CONNECTING = 1,
|
||||
BT_CONNECTED = 2
|
||||
};
|
||||
|
||||
/* extern fonts */
|
||||
extern uint8_t BigFont[];
|
||||
extern uint8_t SmallFont[];
|
||||
@@ -66,6 +75,7 @@ char init_text[] PROGMEM = "Initialising...";
|
||||
char device_labels[3][11] PROGMEM = {"CPU : ", "RAM : ", "DISPLAY : "};
|
||||
char cpu_text[] PROGMEM = "ATSAM3X8E";
|
||||
char display_size_text[] PROGMEM = "480x320";
|
||||
char bt_states[3][13] PROGMEM = {"Initializing", "Connecting ", "Connected "};
|
||||
|
||||
/* initialising... variables */
|
||||
char should_clear = 1;
|
||||
@@ -88,6 +98,8 @@ char init_device_info = 0; /* wether we are drawing CPU (0), RAM (1) or DISPLAY
|
||||
uint32_t ram_b_amount = 0; /* counts up to 96 to show the KB of ram */
|
||||
char device_label_i = -1; /* counter in the current device label */
|
||||
|
||||
char bt_state = BT_INITIALISING;
|
||||
|
||||
void on_init_enter();
|
||||
void on_init_run();
|
||||
void on_init_exit();
|
||||
@@ -144,6 +156,9 @@ void on_init_enter()
|
||||
|
||||
void on_init_run()
|
||||
{
|
||||
uint16_t initialization_y = display.getDisplayYSize() / 2 + 50;
|
||||
|
||||
/* clear initialization text if necessary*/
|
||||
if (init_flag & (1 << FLAG_INIT_CLEAR_POS))
|
||||
{
|
||||
init_flag &= ~(1 << FLAG_INIT_CLEAR_POS);
|
||||
@@ -151,6 +166,7 @@ void on_init_run()
|
||||
/*clear only initializing text*/
|
||||
display.print(" ", (display.getDisplayXSize() / 2) - (INIT_TEXT_WIDTH * display.getFontXsize() / 2) - (INIT_PERCENTAGE_WIDTH / 2), display.getDisplayYSize() / 2 + 50);
|
||||
}
|
||||
/* update initialization text */
|
||||
if (init_flag & (1 << FLAG_INIT_UPDATE_TEXT_POS))
|
||||
{
|
||||
init_flag &= ~(1 << FLAG_INIT_UPDATE_TEXT_POS);
|
||||
@@ -158,24 +174,36 @@ void on_init_run()
|
||||
int x_position = (display.getDisplayXSize() / 2 - (INIT_TEXT_WIDTH * display.getFontXsize() / 2)) + (init_text_i * display.getFontXsize()) - (INIT_PERCENTAGE_WIDTH / 2);
|
||||
// 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
|
||||
display.print(text_temp, x_position, initialization_y); // print as string with one character
|
||||
}
|
||||
|
||||
/* update initialization percentage */
|
||||
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()) - (INIT_PERCENTAGE_WIDTH / 2);
|
||||
display.setBackColor(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((INIT_PERCENTAGE_WIDTH - 1) * sizeof(char));
|
||||
sprintf(percent_text, "%d", init_percent);
|
||||
display.print(percent_text, percent_x_pos, display.getDisplayYSize() / 2 + 50);
|
||||
display.print("%", percent_x_pos + (INIT_PERCENTAGE_WIDTH - 1) * display.getFontXsize(), display.getDisplayYSize() / 2 + 50);
|
||||
display.print(percent_text, percent_x_pos, initialization_y);
|
||||
display.print("%", percent_x_pos + (INIT_PERCENTAGE_WIDTH - 1) * display.getFontXsize(), initialization_y);
|
||||
free(percent_text);
|
||||
}
|
||||
|
||||
/* update initialization progress bar */
|
||||
display.setColor(COLOR_ORANGE);
|
||||
display.fillRect(0, initialization_y + display.getFontYsize() + 3, ((float)init_percent / 100.0) * display.getDisplayXSize(), initialization_y + display.getFontYsize() + 13);
|
||||
|
||||
/* update bluetooth state */
|
||||
display.setBackColor(VGA_FUCHSIA);
|
||||
display.setColor(VGA_BLACK);
|
||||
display.print("Bluetooth ", (display.getDisplayXSize() / 2) - (11 * display.getFontXsize()), initialization_y + 50);
|
||||
display.print(bt_states[bt_state], (display.getDisplayXSize() / 2) + display.getFontXsize(), initialization_y + 50);
|
||||
display.setBackColor(VGA_BLACK);
|
||||
|
||||
/* update device labels and values (CPU, RAM, DISPLAY) */
|
||||
if (init_flag & (1 << FLAG_DEVICE_LABEL_UPDATE_POS))
|
||||
{
|
||||
if (init_flag & (1 << FLAG_DEVICE_LABEL_SHOULD_UPDATE_POS))
|
||||
@@ -219,7 +247,7 @@ void on_init_run()
|
||||
/* draw device labels */
|
||||
init_flag &= ~(1 << FLAG_DEVICE_LABEL_UPDATE_POS);
|
||||
text_temp[0] = device_labels[init_device_info][device_label_i];
|
||||
display.setColor(VGA_AQUA);
|
||||
display.setColor(device_label_i == 8 ? VGA_GRAY : VGA_AQUA); /* make the ":" gray */
|
||||
int x_position = 10 + (device_label_i * display.getFontXsize());
|
||||
display.print(text_temp, x_position, 10 + (init_device_info * display.getFontYsize() + 3));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user