mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-14 19:51:04 +00:00
add updating init percent and add getting OBD2 PIDS
This commit is contained in:
@@ -118,6 +118,12 @@ state_t main_state =
|
||||
/* Standard Arduino Mega/Due shield : <display model>,38,39,40,41 */
|
||||
UTFT display(ILI9486, 38, 39, 40, 41);
|
||||
|
||||
void update_percent(uint8_t amount)
|
||||
{
|
||||
init_percent += amount;
|
||||
init_flag |= (1 << FLAG_INIT_UPDATE_PERCENT_POS);
|
||||
}
|
||||
|
||||
/****************************/
|
||||
/*INIT STATE*/
|
||||
/****************************/
|
||||
@@ -136,12 +142,13 @@ void on_init_enter()
|
||||
Timer2.start(MS(100));
|
||||
|
||||
// TODO change to update when initializing bluetooth..
|
||||
Timer1.attachInterrupt(update_percent_test);
|
||||
Timer1.start(MS(60));
|
||||
// Timer1.attachInterrupt(update_percent_test);
|
||||
// Timer1.start(MS(60));
|
||||
|
||||
Timer3.attachInterrupt(update_ram_kb);
|
||||
|
||||
logo_flag |= (1 << FLAG_LOGO_UPDATE);
|
||||
init_flag |= (1 << FLAG_INIT_UPDATE_PERCENT_POS);
|
||||
}
|
||||
|
||||
void on_init_run()
|
||||
@@ -214,6 +221,7 @@ void on_init_run()
|
||||
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));
|
||||
update_percent(1);
|
||||
break;
|
||||
}
|
||||
case DEV_RAM:
|
||||
@@ -229,6 +237,7 @@ void on_init_run()
|
||||
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));
|
||||
update_percent(1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -255,6 +264,7 @@ void on_init_run()
|
||||
if (logo_pos_y >= LOGO_MAX_POS_Y)
|
||||
{
|
||||
logo_flag &= ~(1 << FLAG_LOGO_UPDATE);
|
||||
update_percent(10);
|
||||
}
|
||||
if (logo_pos_i > LOGO_MIN_STEP)
|
||||
{
|
||||
@@ -308,21 +318,6 @@ void update_init_text()
|
||||
init_flag |= (1 << FLAG_INIT_UPDATE_TEXT_POS);
|
||||
}
|
||||
|
||||
void update_percent_test()
|
||||
{
|
||||
init_percent++;
|
||||
if (init_percent > 100)
|
||||
{
|
||||
init_percent = 0;
|
||||
}
|
||||
init_flag |= (1 << FLAG_INIT_UPDATE_PERCENT_POS);
|
||||
|
||||
/* count KB up */
|
||||
if (init_device_info == DEV_RAM && (0 == (init_flag & (1 << FLAG_DEVICE_LABEL_SHOULD_UPDATE_POS))))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void update_device_info()
|
||||
{
|
||||
if (init_flag & (1 << FLAG_DEVICE_LABEL_SHOULD_UPDATE_POS))
|
||||
@@ -337,9 +332,6 @@ void update_device_info()
|
||||
init_device_info = DEV_RAM;
|
||||
device_label_i = 0;
|
||||
Timer3.start(50);
|
||||
#if (DEBUG == 1)
|
||||
Serial.println("DEV RAM");
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case DEV_RAM:
|
||||
@@ -349,6 +341,7 @@ void update_device_info()
|
||||
Timer3.stop();
|
||||
init_device_info = DEV_DISPLAY;
|
||||
device_label_i = 0;
|
||||
update_percent(10);
|
||||
}
|
||||
break;
|
||||
case DEV_DISPLAY:
|
||||
@@ -357,6 +350,7 @@ void update_device_info()
|
||||
{
|
||||
init_device_info = DEV_DONE;
|
||||
// init_flag &= ~(1 << FLAG_DEVICE_LABEL_UPDATE_POS);
|
||||
update_percent(10);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -369,6 +363,7 @@ void update_device_info()
|
||||
{
|
||||
case DEV_CPU:
|
||||
device_label_i++;
|
||||
update_percent(1);
|
||||
if (device_label_i > DEV_LABEL_LENGTH)
|
||||
{
|
||||
init_device_info = DEV_RAM;
|
||||
@@ -378,6 +373,7 @@ void update_device_info()
|
||||
break;
|
||||
case DEV_RAM:
|
||||
device_label_i++;
|
||||
update_percent(1);
|
||||
if (device_label_i > DEV_LABEL_LENGTH)
|
||||
{
|
||||
init_device_info = DEV_DISPLAY;
|
||||
@@ -387,6 +383,7 @@ void update_device_info()
|
||||
break;
|
||||
case DEV_DISPLAY:
|
||||
device_label_i++;
|
||||
update_percent(1);
|
||||
if (device_label_i > DEV_LABEL_LENGTH)
|
||||
{
|
||||
device_label_i = 0;
|
||||
@@ -411,6 +408,11 @@ void update_ram_kb()
|
||||
init_flag |= (1 << FLAG_DEVICE_LABEL_UPDATE_POS);
|
||||
}
|
||||
|
||||
void bt_state_changed()
|
||||
{
|
||||
update_percent(10);
|
||||
}
|
||||
|
||||
void setup()
|
||||
|
||||
{
|
||||
@@ -447,6 +449,7 @@ void setup()
|
||||
display.print("Waiting for ELM327", (display.getDisplayXSize() / 2) - ((18 * display.getFontXsize()) / 2), 160);
|
||||
|
||||
obd2_elm327_init(&elm327);
|
||||
elm327.on_state_change = &bt_state_changed;
|
||||
#if (DEBUG == 1)
|
||||
Serial.println("done with elm327 init");
|
||||
Serial.println(elm327.elm327->connected);
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
#include "ELMduino.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#include "obd2_elm327.h"
|
||||
|
||||
#define KM_IN_MILES 1.6093440
|
||||
|
||||
ELM327 elm327_obj;
|
||||
|
||||
char bt_states[3][BT_STATE_LENGTH] = {"Initializing", "Connecting ", "Connected "};
|
||||
char bt_states[2][BT_STATE_LENGTH] = {"Initializing", "Connected "};
|
||||
|
||||
char obd2_elm327_init(obd2_elm327_t *elm327)
|
||||
{
|
||||
|
||||
ELM327_SERIAL.begin(ELM327_BAUD);
|
||||
|
||||
|
||||
elm327->bt_state = BT_INITIALISING;
|
||||
elm327->elm327 = &elm327_obj;
|
||||
|
||||
@@ -31,21 +33,81 @@ void obd2_elm327_process(obd2_elm327_t *elm327)
|
||||
{
|
||||
if (elm327->bt_state != BT_CONNECTED)
|
||||
{
|
||||
__UINT32_TYPE__ bt_state = digitalRead(BT_STATE_PIN);
|
||||
__UINT8_TYPE__ bt_state = elm327->elm327->connected;
|
||||
|
||||
if (bt_state != elm327->bt_state)
|
||||
{
|
||||
if (bt_state)
|
||||
{
|
||||
elm327->bt_state = BT_CONNECTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
elm327->bt_state = BT_INITIALISING;
|
||||
}
|
||||
// 0 for initialising, 1 for connected
|
||||
elm327->bt_state = bt_state == 1 ? BT_CONNECTED : BT_INITIALISING;
|
||||
elm327->on_state_change();
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO read from Serial2 to read OBD2 data */
|
||||
/* TODO maybe change to switch statement */
|
||||
|
||||
float rpm = elm327->elm327->rpm();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->rpm = (uint16_t)rpm;
|
||||
}
|
||||
|
||||
float throttle = elm327->elm327->throttle();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->throttle_percent = (uint8_t)throttle;
|
||||
}
|
||||
|
||||
float coolant_temp = elm327->elm327->engineCoolantTemp();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->engine_coolant_temp = (uint8_t)coolant_temp;
|
||||
}
|
||||
|
||||
float intake_air_temp = elm327->elm327->intakeAirTemp();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->intake_air_temp = (uint8_t)intake_air_temp;
|
||||
}
|
||||
|
||||
float ambient_air_temp = elm327->elm327->ambientAirTemp();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->ambient_air_temp = (uint8_t) ambient_air_temp;
|
||||
}
|
||||
|
||||
float engine_oil_temp = elm327->elm327->oilTemp();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->engine_oil_temp = engine_oil_temp;
|
||||
}
|
||||
|
||||
float engine_load = elm327->elm327->engineLoad();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->engine_load = (uint8_t)engine_load;
|
||||
}
|
||||
|
||||
float battery_voltage = elm327->elm327->batteryVoltage();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->battery_voltage = battery_voltage;
|
||||
}
|
||||
|
||||
float fuel_pressure = elm327->elm327->fuelPressure();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->fuel_pressure = fuel_pressure;
|
||||
}
|
||||
|
||||
float speed = elm327->elm327->mph();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->speed = (uint8_t)(speed * KM_IN_MILES);
|
||||
}
|
||||
|
||||
float manifold_pressure = elm327->elm327->manifoldPressure();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->manifold_pressure = (uint8_t)manifold_pressure;
|
||||
}
|
||||
}
|
||||
@@ -58,8 +58,7 @@ Be sure to disconnect the TX and RX pins from the BT module when programming the
|
||||
enum BluetoothState
|
||||
{
|
||||
BT_INITIALISING = 0,
|
||||
BT_CONNECTING = 1,
|
||||
BT_CONNECTED = 2
|
||||
BT_CONNECTED = 1
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -73,6 +72,17 @@ typedef struct obt2_elm327_tag
|
||||
ELM327 *elm327;
|
||||
enum BluetoothState bt_state;
|
||||
void (*on_state_change)();
|
||||
uint16_t rpm;
|
||||
uint8_t throttle_percent;
|
||||
uint8_t engine_coolant_temp;
|
||||
uint8_t intake_air_temp;
|
||||
uint8_t ambient_air_temp;
|
||||
float engine_oil_temp;
|
||||
uint8_t engine_load;
|
||||
float battery_voltage;
|
||||
float fuel_pressure;
|
||||
uint8_t speed;
|
||||
uint8_t manifold_pressure;
|
||||
} obd2_elm327_t;
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,6 +46,7 @@ void setup()
|
||||
void loop()
|
||||
{
|
||||
float tempRPM = myELM327.rpm();
|
||||
float t = myELM327.
|
||||
|
||||
// float tempval3 = myELM327.fuelInjectTiming();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user