Add intro animation

This commit is contained in:
Sem van der Hoeven
2023-11-26 22:57:19 +01:00
parent e0af359cdd
commit e08b84c102
3 changed files with 64 additions and 1 deletions

17
.vscode/c_cpp_properties.json vendored Normal file
View File

@@ -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
}

View File

@@ -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()

11
due_obd2/obd2_util.h Normal file
View File

@@ -0,0 +1,11 @@
#ifndef OBD2_UTIL_H
#define OBD2_UTIL_H
#include <math.h>
float logo_step(float x)
{
return (float)(25 / (0.2 + exp((double)((-0.08 * x) + 3))));
}
#endif