mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-14 19:51:04 +00:00
finish displaying device labels
This commit is contained in:
@@ -26,6 +26,8 @@ Program to create a car monitor display using:
|
||||
#define MS(x) x * 1000
|
||||
#define S(x) MS(x) * 1000
|
||||
|
||||
#define SIZE_OF(a) sizeof(a) / sizeof(a[0])
|
||||
|
||||
#define INIT_TEXT_WIDTH 15
|
||||
#define INIT_PERCENTAGE_WIDTH 4
|
||||
#define FLAG_INIT_UPDATE_TEXT_POS 0x01
|
||||
@@ -33,7 +35,7 @@ Program to create a car monitor display using:
|
||||
#define FLAG_INIT_UPDATE_PERCENT_POS 0x03
|
||||
#define FLAG_DEVICE_LABEL_UPDATE_POS 0x04
|
||||
#define FLAG_DEVICE_LABEL_SHOULD_UPDATE_POS 0x05 /* 0 if label should be updated, 1 if valyue should be updated */
|
||||
#define FLAG_DEVICE_LABEL_UPDATE_KB_POS 0x06 /* count KB up */
|
||||
#define FLAG_DEVICE_LABEL_UPDATE_KB_POS 0x06 /* count KB up */
|
||||
|
||||
#define LOGO_MIN_STEP 20
|
||||
#define LOGO_MAX_POS_Y 124
|
||||
@@ -43,6 +45,7 @@ Program to create a car monitor display using:
|
||||
|
||||
#define RAM_AMOUNT_KB 96
|
||||
#define RAM_AMOUNT_B 98304
|
||||
#define RAM_TEXT_WIDTH 9
|
||||
#define DEV_LABEL_LENGTH 10
|
||||
|
||||
enum DeviceLabel
|
||||
@@ -82,7 +85,7 @@ char logo_flag = 0;
|
||||
|
||||
/* device info variables */
|
||||
char init_device_info = 0; /* wether we are drawing CPU (0), RAM (1) or DISPLAY (2) */
|
||||
char ram_kb_amount = 0; /* counts up to 96 to show the KB of ram */
|
||||
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 */
|
||||
|
||||
void on_init_enter();
|
||||
@@ -132,6 +135,8 @@ void on_init_enter()
|
||||
Timer1.attachInterrupt(update_percent_test);
|
||||
Timer1.start(MS(60));
|
||||
|
||||
Timer3.attachInterrupt(update_ram_kb);
|
||||
|
||||
logo_flag |= (1 << FLAG_LOGO_UPDATE);
|
||||
|
||||
Serial.println("Entering init state!");
|
||||
@@ -178,8 +183,36 @@ void on_init_run()
|
||||
/* draw device label values*/
|
||||
init_flag &= ~(1 << FLAG_DEVICE_LABEL_UPDATE_POS);
|
||||
display.setColor(VGA_FUCHSIA);
|
||||
display.setBackColor(VGA_BLACK);
|
||||
|
||||
int x_offset = 10 + 10 * display.getFontXsize();
|
||||
display.print(cpu_text, x_offset, 10 + 3);
|
||||
switch (init_device_info)
|
||||
{
|
||||
case DEV_CPU:
|
||||
{
|
||||
text_temp[0] = cpu_text[device_label_i];
|
||||
int x_position = x_offset + (device_label_i * display.getFontXsize());
|
||||
display.print(text_temp, x_position, 10 + (init_device_info * display.getFontYsize() + 3));
|
||||
break;
|
||||
}
|
||||
case DEV_RAM:
|
||||
{
|
||||
char *ram_text = (char *)malloc((RAM_TEXT_WIDTH) * sizeof(char));
|
||||
sprintf(ram_text, "%d B", ram_b_amount);
|
||||
display.print(ram_text, x_offset, 10 + (init_device_info * display.getFontYsize() + 3));
|
||||
free(ram_text);
|
||||
break;
|
||||
}
|
||||
case DEV_DISPLAY:
|
||||
{
|
||||
text_temp[0] = display_size_text[device_label_i];
|
||||
int x_position = x_offset + (device_label_i * display.getFontXsize());
|
||||
display.print(text_temp, x_position, 10 + (init_device_info * display.getFontYsize() + 3));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -260,7 +293,6 @@ void update_percent_test()
|
||||
/* count KB up */
|
||||
if (init_device_info == DEV_RAM && (0 == (init_flag & (1 << FLAG_DEVICE_LABEL_SHOULD_UPDATE_POS))))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,6 +301,37 @@ void update_device_info()
|
||||
if (init_flag & (1 << FLAG_DEVICE_LABEL_SHOULD_UPDATE_POS))
|
||||
{
|
||||
/* update device label values */
|
||||
switch (init_device_info)
|
||||
{
|
||||
case DEV_CPU:
|
||||
device_label_i++;
|
||||
if (device_label_i >= SIZE_OF(cpu_text))
|
||||
{
|
||||
init_device_info = DEV_RAM;
|
||||
device_label_i = 0;
|
||||
Timer3.start(50);
|
||||
Serial.println("DEV RAM");
|
||||
}
|
||||
break;
|
||||
case DEV_RAM:
|
||||
if (ram_b_amount >= RAM_AMOUNT_B)
|
||||
{
|
||||
Timer3.detachInterrupt();
|
||||
Timer3.stop();
|
||||
init_device_info = DEV_DISPLAY;
|
||||
device_label_i = 0;
|
||||
}
|
||||
break;
|
||||
case DEV_DISPLAY:
|
||||
device_label_i++;
|
||||
if (device_label_i >= SIZE_OF(display_size_text))
|
||||
{
|
||||
init_device_info = DEV_DONE;
|
||||
// init_flag &= ~(1 << FLAG_DEVICE_LABEL_UPDATE_POS);
|
||||
}
|
||||
break;
|
||||
}
|
||||
init_flag |= (1 << FLAG_DEVICE_LABEL_UPDATE_POS);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -279,7 +342,7 @@ void update_device_info()
|
||||
device_label_i++;
|
||||
if (device_label_i > DEV_LABEL_LENGTH)
|
||||
{
|
||||
init_device_info++;
|
||||
init_device_info = DEV_RAM;
|
||||
device_label_i = 0;
|
||||
// init_flag |= (1 << FLAG_DEVICE_LABEL_SHOULD_UPDATE_POS);
|
||||
}
|
||||
@@ -288,7 +351,7 @@ void update_device_info()
|
||||
device_label_i++;
|
||||
if (device_label_i > DEV_LABEL_LENGTH)
|
||||
{
|
||||
init_device_info++;
|
||||
init_device_info = DEV_DISPLAY;
|
||||
device_label_i = 0;
|
||||
// init_flag |= (1 << FLAG_DEVICE_LABEL_SHOULD_UPDATE_POS);
|
||||
}
|
||||
@@ -310,7 +373,17 @@ void update_device_info()
|
||||
}
|
||||
}
|
||||
|
||||
void update_ram_kb()
|
||||
{
|
||||
if (ram_b_amount < RAM_AMOUNT_B)
|
||||
{
|
||||
ram_b_amount++;
|
||||
}
|
||||
init_flag |= (1 << FLAG_DEVICE_LABEL_UPDATE_POS);
|
||||
}
|
||||
|
||||
void setup()
|
||||
|
||||
{
|
||||
|
||||
/* TODO change for TRNG (section 42 of datasheet)*/
|
||||
|
||||
Reference in New Issue
Block a user