mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-14 19:51:04 +00:00
add getting state string from bt driver
This commit is contained in:
@@ -14,21 +14,14 @@ Program to create a car monitor display using:
|
||||
#include "obd2_display.h"
|
||||
#include "statemachine.h"
|
||||
#include "obd2_util.h"
|
||||
#include "obd2_bt.h"
|
||||
|
||||
#define DEBUG 1
|
||||
// #define RTT_MR 0x400E1A30U
|
||||
|
||||
/* pins */
|
||||
#define PIN_BT_RX 19
|
||||
#define PIN_BT_TX 18
|
||||
#define PIN_BT_STATE 3 /* connected/disconnected state of BT */
|
||||
#define BT_SERIAL Serial1
|
||||
|
||||
#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
|
||||
@@ -69,7 +62,6 @@ char init_text[] PROGMEM = "Initialising...";
|
||||
char device_labels[3][11] PROGMEM = {"CPU : ", "RAM : ", "DISPLAY : "};
|
||||
char cpu_text[] PROGMEM = "ATSAM3X8E";
|
||||
char display_size_text[] PROGMEM = "480x320";
|
||||
char bt_states[3][13] PROGMEM = {"Initializing", "Connecting ", "Connected "};
|
||||
|
||||
/* initialising... variables */
|
||||
char should_clear = 1;
|
||||
@@ -94,6 +86,8 @@ char device_label_i = -1; /* counter in the current device label */
|
||||
|
||||
char bt_state = BT_INITIALISING;
|
||||
|
||||
obd2_bt_t bt;
|
||||
|
||||
void on_init_enter();
|
||||
void on_init_run();
|
||||
void on_init_exit();
|
||||
@@ -195,7 +189,10 @@ void on_init_run()
|
||||
display.setBackColor(VGA_FUCHSIA);
|
||||
display.setColor(VGA_BLACK);
|
||||
display.print("Bluetooth ", (display.getDisplayXSize() / 2) - (11 * display.getFontXsize()), initialization_y + 50);
|
||||
display.print(bt_states[bt_state], (display.getDisplayXSize() / 2) + display.getFontXsize(), initialization_y + 50);
|
||||
|
||||
char current_bt_state[BT_STATE_LENGTH];
|
||||
obd2_bt_get_state(&bt, (char *)current_bt_state);
|
||||
display.print(current_bt_state, (display.getDisplayXSize() / 2) + display.getFontXsize(), initialization_y + 50);
|
||||
display.setBackColor(VGA_BLACK);
|
||||
|
||||
/* update device labels and values (CPU, RAM, DISPLAY) */
|
||||
@@ -423,8 +420,6 @@ void setup()
|
||||
#if (DEBUG == 1)
|
||||
Serial.begin(9600);
|
||||
#endif
|
||||
/* Serial1 is bluetooth module, pin 18 and 19. */
|
||||
BT_SERIAL.begin(115200);
|
||||
|
||||
/* Init display */
|
||||
display.InitLCD();
|
||||
@@ -439,6 +434,10 @@ void setup()
|
||||
statemachine_register_state(&init_state, STATE_INIT);
|
||||
statemachine_register_state(&main_state, STATE_CAR_INFO);
|
||||
statemachine_init();
|
||||
|
||||
/* Serial1 is bluetooth module, pin 18 and 19. */
|
||||
Serial1.begin(BT_BAUD);
|
||||
obd2_bt_init(&bt);
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "wiring_digital.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "obd2_bt.h"
|
||||
|
||||
void obd2_bt_init(obd2_bt_t *bt)
|
||||
@@ -6,6 +7,34 @@ void obd2_bt_init(obd2_bt_t *bt)
|
||||
bt->state = BT_INITIALISING;
|
||||
}
|
||||
|
||||
void obd2_bt_get_state(obd2_bt_t *bt, char *state)
|
||||
{
|
||||
// char bt_states[3][13] = {"Initializing", "Connecting ", "Connected "};
|
||||
// char bt_states;
|
||||
// (void) bt_states;
|
||||
|
||||
if (sizeof(state) != BT_STATE_LENGTH)
|
||||
{
|
||||
/* result string must be of size 13 */
|
||||
return;
|
||||
}
|
||||
switch (bt->state)
|
||||
{
|
||||
case BT_INITIALISING:
|
||||
strcpy(state, "Initializing");
|
||||
break;
|
||||
case BT_CONNECTING:
|
||||
strcpy(state, "Connecting ");
|
||||
break;
|
||||
case BT_CONNECTED:
|
||||
strcpy(state, "Connected ");
|
||||
break;
|
||||
default:
|
||||
strcpy(state, "Unknown ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void obd2_bt_process(obd2_bt_t *bt)
|
||||
{
|
||||
__UINT32_TYPE__ bt_state = digitalRead(BT_STATE_PIN);
|
||||
|
||||
@@ -21,8 +21,23 @@ Be sure to disconnect the TX and RX pins from the BT module when programming the
|
||||
#ifndef OBD2_BT_H
|
||||
#define OBD2_BT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// #include <Arduino.h>
|
||||
// #include "obd2_util.h"
|
||||
|
||||
/* pins */
|
||||
#define PIN_BT_RX 19
|
||||
#define PIN_BT_TX 18
|
||||
|
||||
#define BT_STATE_PIN 3 /* state connection pin from bluetooth module -> level high on connected */
|
||||
|
||||
#define BT_BAUD 115200
|
||||
|
||||
#define BT_STATE_LENGTH 13 /* length of the string identifier used for the states */
|
||||
|
||||
enum BluetoothState
|
||||
{
|
||||
BT_INITIALISING = 0,
|
||||
@@ -38,6 +53,10 @@ typedef struct obt2_bt_tag
|
||||
|
||||
void obd2_bt_init(obd2_bt_t *bt);
|
||||
void obd2_bt_process(obd2_bt_t *bt);
|
||||
void obd2_bt_get_state(obd2_bt_t *bt, char *state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OBD2_BT_H
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define SIZE_OF(a) sizeof(a) / sizeof(a[0])
|
||||
|
||||
float logo_step(float x)
|
||||
{
|
||||
return (float)(25 / (0.2 + exp((double)((-0.08 * x) + 3))));
|
||||
|
||||
Reference in New Issue
Block a user