From e08b84c102c2daf380c39e0d85266a680cbf61ff Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Sun, 26 Nov 2023 22:57:19 +0100 Subject: [PATCH] Add intro animation --- .vscode/c_cpp_properties.json | 17 ++++++++++++++++ due_obd2/due_obd2.ino | 37 ++++++++++++++++++++++++++++++++++- due_obd2/obd2_util.h | 11 +++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 due_obd2/obd2_util.h diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..e70bc12 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,17 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "/home/sem/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/Device/ATMEL/sam3xa/include" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/due_obd2/due_obd2.ino b/due_obd2/due_obd2.ino index 1ff291f..d4c0c77 100644 --- a/due_obd2/due_obd2.ino +++ b/due_obd2/due_obd2.ino @@ -13,6 +13,7 @@ Program to create a car monitor display using: // #include "obd2_timer.h" #include "obd2_display.h" #include "statemachine.h" +#include "obd2_util.h" #define DEBUG 1 // #define RTT_MR 0x400E1A30U @@ -30,6 +31,9 @@ Program to create a car monitor display using: #define FLAG_INIT_UPDATE_TEXT_POS 0x01 #define FLAG_INIT_CLEAR_POS 0x02 #define FLAG_INIT_UPDATE_PERCENT_POS 0x03 +#define FLAG_LOGO_UPDATE 0x00 + +#define LOGO_TEXT_WIDTH 16 extern uint8_t BigFont[]; extern uint8_t SmallFont[]; @@ -44,6 +48,12 @@ char init_text[] PROGMEM = "Initialising..."; char text_temp[2] = {'a', '\0'}; int init_percent = 0; +char logo_text[] PROGMEM = "DS3 OBD2 display"; +int logo_pos_y = 0; +int last_logo_pos_y = 0; +int logo_pos_i = 0; +char logo_flag = 0; + void on_init_enter(); void on_init_run(); void on_init_exit(); @@ -88,6 +98,8 @@ void on_init_enter() Timer1.attachInterrupt(update_percent_test); Timer1.start(MS(60)); + logo_flag |= (1 << FLAG_LOGO_UPDATE); + Serial.println("Entering init state!"); } @@ -105,7 +117,7 @@ void on_init_run() 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()) - (INIT_PERCENTAGE_WIDTH/2); - Serial.println(x_position); + // 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 } @@ -124,6 +136,29 @@ void on_init_run() display.print("%", percent_x_pos + (INIT_PERCENTAGE_WIDTH-1) * display.getFontXsize(), display.getDisplayYSize() / 2 + 50); free(percent_text); } + + logo_pos_i+= 3; + last_logo_pos_y = logo_pos_y; + logo_pos_y = logo_step(logo_pos_i); + + if (logo_flag & (1 << FLAG_LOGO_UPDATE)) + { + if (logo_pos_y >= 124) + { + logo_flag &= ~(1 << FLAG_LOGO_UPDATE); + Serial.println("Stopping update"); + } + if (logo_pos_i > 20) + { + display.setColor(VGA_BLACK); + display.print(logo_text, CENTER, last_logo_pos_y); + display.setColor(VGA_AQUA); + display.print(logo_text, CENTER, logo_pos_y); + + Serial.println(logo_pos_y); + } + + } } void on_init_exit() diff --git a/due_obd2/obd2_util.h b/due_obd2/obd2_util.h new file mode 100644 index 0000000..ea9cd9e --- /dev/null +++ b/due_obd2/obd2_util.h @@ -0,0 +1,11 @@ +#ifndef OBD2_UTIL_H +#define OBD2_UTIL_H + +#include + +float logo_step(float x) +{ + return (float)(25 / (0.2 + exp((double)((-0.08 * x) + 3)))); +} + +#endif \ No newline at end of file