begin placing elements, add skip BT check

This commit is contained in:
Sem van der Hoeven
2024-11-12 23:34:56 +01:00
parent 21c166aadf
commit 2f325e3254
2 changed files with 40 additions and 50 deletions

View File

@@ -21,6 +21,7 @@ Program to create a car monitor display using:
#include "bars.h" #include "bars.h"
#define DEBUG 1 #define DEBUG 1
#define SKIP_BT_CHECK 1
// #define RTT_MR 0x400E1A30U // #define RTT_MR 0x400E1A30U
#define MS(x) x * 1000 #define MS(x) x * 1000
@@ -49,6 +50,18 @@ Program to create a car monitor display using:
#define COLOR_ORANGE 255, 96, 33 #define COLOR_ORANGE 255, 96, 33
/****************************************/
/* x and y positions for several gauges */
/****************************************/
/* box that holds temperature gauges */
#define TEMP_BOX_PADDING 5
#define TEMP_BOX_X_START 300
#define TEMP_BOX_Y_START TEMP_BOX_PADDING
#define TEMP_BOX_CONTENT_WIDTH 180 // witdth of the box to calculate the content in it
#define TEMP_BOX_WIDTH TEMP_BOX_CONTENT_WIDTH - TEMP_BOX_PADDING // width of the box to draw the outline
#define TEMP_BOX_HEIGHT 200 - TEMP_BOX_PADDING
#define TEMP_BOX_COLOR VGA_GRAY
enum DeviceLabel enum DeviceLabel
{ {
DEV_CPU = 0, DEV_CPU = 0,
@@ -315,6 +328,11 @@ void on_main_enter()
#endif #endif
Timer0.attachInterrupt(query_slow_obd2_values); Timer0.attachInterrupt(query_slow_obd2_values);
Timer0.start(MS(5000)); Timer0.start(MS(5000));
// draw section for temps
display.setColor(TEMP_BOX_COLOR);
display.drawRect(TEMP_BOX_X_START, TEMP_BOX_Y_START, TEMP_BOX_X_START + TEMP_BOX_WIDTH, TEMP_BOX_Y_START + TEMP_BOX_HEIGHT);
display.setColor(VGA_AQUA); display.setColor(VGA_AQUA);
} }
@@ -539,8 +557,6 @@ void setup()
statemachine_register_state(&init_state, STATE_INIT); statemachine_register_state(&init_state, STATE_INIT);
statemachine_register_state(&main_state, STATE_CAR_INFO); statemachine_register_state(&main_state, STATE_CAR_INFO);
// TODO remove
// statemachine_register_state(&main_state, 0);
statemachine_init(); statemachine_init();
display.clrScr(); display.clrScr();
@@ -568,6 +584,10 @@ void setup()
Serial.println(elm327.elm327->connected); Serial.println(elm327.elm327->connected);
#endif #endif
#if (SKIP_BT_CHECK == 1)
update_percent(10);
#endif
display.clrScr(); display.clrScr();
display.setFont(OCR_A_Extended_M); display.setFont(OCR_A_Extended_M);
@@ -575,32 +595,5 @@ void setup()
void loop() void loop()
{ {
statemachine_loop();
bar_draw_horizontal(0, 0, 200, 10, bar_1_x, 100, VGA_AQUA, 1, &display);
bar_draw_horizontal(0, 20, 200, 11, bar_2_x, 100, VGA_FUCHSIA, 0, &display);
bar_draw_vertical(0, 50, 20, 100, bar_3_y, 100, VGA_BLUE, 1, &display);
bar_1_x++;
if (bar_1_x > 100)
{
bar_1_x = 0;
bar_clear_part_horizontal(0,0,200,10,bar_1_x,100,VGA_BLACK,0,&display);
}
bar_2_x++;
if (bar_2_x > 100)
{
bar_2_x = 10;
bar_clear_part_horizontal(0,20,200,11,bar_2_x,100,VGA_BLACK,1,&display);
}
bar_3_y++;
if (bar_3_y > 100)
{
bar_3_y = 50;
bar_clear_part_vertical(0,50,20,100,bar_3_y,100,VGA_BLACK,0,&display);
}
delay(50);
// statemachine_loop();
} }

View File

@@ -3,7 +3,7 @@
#include "obd2_elm327.h" #include "obd2_elm327.h"
#define DEBUG 1 #define DEBUG_VALUES 1
#define KM_IN_MILES 1.6093440 #define KM_IN_MILES 1.6093440
#define RPM_MAX 7000 #define RPM_MAX 7000
@@ -90,10 +90,9 @@ void obd2_elm327_process_fast(obd2_elm327_t *elm327)
{ {
case ENGINE_LOAD_V: case ENGINE_LOAD_V:
{ {
#if (DEBUG == 1) #if (DEBUG_VALUES == 1)
float engine_load = 50;
current_value_fast = FUEL_PRESSURE_V; current_value_fast = FUEL_PRESSURE_V;
elm327->engine_load = (uint8_t)engine_load; elm327->engine_load = ++elm327->engine_load % 100;
elm327->value_updates |= (1 << UPDATE_ENGINE_LOAD_POS); elm327->value_updates |= (1 << UPDATE_ENGINE_LOAD_POS);
#else #else
float engine_load = elm327->elm327->engineLoad(); float engine_load = elm327->elm327->engineLoad();
@@ -113,9 +112,8 @@ void obd2_elm327_process_fast(obd2_elm327_t *elm327)
} }
case FUEL_PRESSURE_V: case FUEL_PRESSURE_V:
{ {
#if (DEBUG == 1) #if (DEBUG_VALUES == 1)
float fuel_pressure = 8; elm327->fuel_pressure = ++elm327->fuel_pressure % 20;
elm327->fuel_pressure = (uint16_t)fuel_pressure;
elm327->value_updates |= (1 << UPDATE_FUEL_PRESSURE_POS); elm327->value_updates |= (1 << UPDATE_FUEL_PRESSURE_POS);
current_value_fast = MANIFOLD_PRESSURE_V; current_value_fast = MANIFOLD_PRESSURE_V;
#else #else
@@ -136,9 +134,8 @@ void obd2_elm327_process_fast(obd2_elm327_t *elm327)
} }
case MANIFOLD_PRESSURE_V: case MANIFOLD_PRESSURE_V:
{ {
#if (DEBUG == 1) #if (DEBUG_VALUES == 1)
float manifold_pressure = 8; elm327->manifold_pressure = ++elm327->manifold_pressure % 20;
elm327->manifold_pressure = (uint8_t)manifold_pressure;
elm327->value_updates |= (1 << UPDATE_MANIFOLD_PRESSURE_POS); elm327->value_updates |= (1 << UPDATE_MANIFOLD_PRESSURE_POS);
current_value_fast = ENGINE_LOAD_V; current_value_fast = ENGINE_LOAD_V;
#else #else
@@ -167,8 +164,8 @@ void obd2_elm327_process_slow(obd2_elm327_t *elm327)
{ {
case COOLANT_TEMP_V: case COOLANT_TEMP_V:
{ {
#if (DEBUG == 1) #if (DEBUG_VALUES == 1)
elm327->engine_coolant_temp = 102; elm327->engine_coolant_temp = ++elm327->engine_coolant_temp % 150;
elm327->value_updates |= (1 << UPDATE_COOLANT_TEMP_POS); elm327->value_updates |= (1 << UPDATE_COOLANT_TEMP_POS);
current_value_slow = INTAKE_AIR_TEMP_V; current_value_slow = INTAKE_AIR_TEMP_V;
#else #else
@@ -189,8 +186,8 @@ void obd2_elm327_process_slow(obd2_elm327_t *elm327)
} }
case INTAKE_AIR_TEMP_V: case INTAKE_AIR_TEMP_V:
{ {
#if (DEBUG == 1) #if (DEBUG_VALUES == 1)
elm327->intake_air_temp = 40; elm327->intake_air_temp = ++elm327->intake_air_temp % 60;
elm327->value_updates |= (1 << UPDATE_INTAKE_AIR_TEMP_POS); elm327->value_updates |= (1 << UPDATE_INTAKE_AIR_TEMP_POS);
current_value_slow = AMBIENT_AIR_TEMP_V; current_value_slow = AMBIENT_AIR_TEMP_V;
#else #else
@@ -211,8 +208,8 @@ void obd2_elm327_process_slow(obd2_elm327_t *elm327)
} }
case AMBIENT_AIR_TEMP_V: case AMBIENT_AIR_TEMP_V:
{ {
#if (DEBUG == 1) #if (DEBUG_VALUES == 1)
elm327->ambient_air_temp = 20; elm327->ambient_air_temp = ++elm327->ambient_air_temp % 60;
elm327->value_updates |= (1 << UPDATE_AMBIENT_AIR_TEMP_POS); elm327->value_updates |= (1 << UPDATE_AMBIENT_AIR_TEMP_POS);
current_value_slow = OIL_TEMP_V; current_value_slow = OIL_TEMP_V;
#else #else
@@ -233,8 +230,8 @@ void obd2_elm327_process_slow(obd2_elm327_t *elm327)
} }
case OIL_TEMP_V: case OIL_TEMP_V:
{ {
#if (DEBUG == 1) #if (DEBUG_VALUES == 1)
elm327->engine_oil_temp = 80; elm327->engine_oil_temp = ++elm327->engine_oil_temp % 150;
elm327->value_updates |= (1 << UPDATE_OIL_TEMP_POS); elm327->value_updates |= (1 << UPDATE_OIL_TEMP_POS);
current_value_slow = FUEL_LEVEL_V; current_value_slow = FUEL_LEVEL_V;
#else #else
@@ -255,8 +252,8 @@ void obd2_elm327_process_slow(obd2_elm327_t *elm327)
} }
case FUEL_LEVEL_V: case FUEL_LEVEL_V:
{ {
#if (DEBUG == 1) #if (DEBUG_VALUES == 1)
elm327->fuel_level = 50; elm327->fuel_level = ++elm327->fuel_level % 100;
elm327->value_updates |= (1 << UPDATE_FUEL_LEVEL_POS); elm327->value_updates |= (1 << UPDATE_FUEL_LEVEL_POS);
current_value_slow = COOLANT_TEMP_V; current_value_slow = COOLANT_TEMP_V;
#else #else