diff --git a/due_obd2/obd2_bt.c b/due_obd2/obd2_bt.c index 8213cf3..5cd0184 100644 --- a/due_obd2/obd2_bt.c +++ b/due_obd2/obd2_bt.c @@ -32,19 +32,28 @@ void obd2_bt_get_state(obd2_bt_t *bt, char *state) default: strcpy(state, "Unknown "); break; - } + } } void obd2_bt_process(obd2_bt_t *bt) { - __UINT32_TYPE__ bt_state = digitalRead(BT_STATE_PIN); - if (bt_state) + if (bt->state != BT_CONNECTED) { - bt->state = BT_CONNECTED; + __UINT32_TYPE__ bt_state = digitalRead(BT_STATE_PIN); + + if (bt_state != bt->state) + { + if (bt_state) + { + bt->state = BT_CONNECTED; + } + else + { + bt->state = BT_INITIALISING; + } + bt->on_state_change(); + } } - else - { - bt->state = BT_INITIALISING; - } - bt->on_state_change(); + + /* TODO read from Serial1 to read OBD2 data */ } \ No newline at end of file