diff --git a/software/dumber3/.cproject b/software/dumber3/.cproject
index 34090fd..dfa0378 100644
--- a/software/dumber3/.cproject
+++ b/software/dumber3/.cproject
@@ -327,28 +327,16 @@
-
-
-
-
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/software/dumber3/Application/application.c b/software/dumber3/Application/application.c
index e6c6fca..7ade529 100644
--- a/software/dumber3/Application/application.c
+++ b/software/dumber3/Application/application.c
@@ -29,7 +29,7 @@ typedef enum {
typedef struct {
APPLICATION_State state;
uint8_t cmd;
- uint16_t batteryVoltage;
+ uint16_t batteryState;
char batteryUpdate;
char inCharge;
int32_t distance;
@@ -143,7 +143,7 @@ void APPLICATION_MainThread(void* params) {
cmdSendAnswer(ANS_OK);
break;
case CMD_GET_BATTERY:
- cmdSendBatteryLevel(systemInfos.batteryVoltage);
+ cmdSendBatteryLevel(systemInfos.batteryState);
break;
case CMD_GET_VERSION:
cmdSendVersion();
@@ -177,25 +177,28 @@ void APPLICATION_MainThread(void* params) {
break;
-/* TODO
- * Revoir la gestion de la batterie ici
- */
-// case MSG_ID_BAT_CHARGE_OFF:
-// case MSG_ID_BAT_CHARGE_COMPLETE:
-// systemInfos.batteryVoltage = *((uint16_t*)msg.data);
-// systemInfos.batteryUpdate = 1;
-//
-// if (msg.id == MSG_ID_BAT_CHARGE_COMPLETE)
-// systemInfos.inCharge =1;
-// else
-// systemInfos.inCharge =0;
-// break;
-//
-// case MSG_ID_BAT_CHARGE_ON:
-// systemInfos.inCharge =1;
-// break;
-
- case MSG_ID_MOTEURS_STOP:
+ case MSG_ID_BAT_ADC_ERR:
+ /* depart en panic: error 2 */
+ break;
+ case MSG_ID_BAT_CHARGE_ERR:
+ /* depart en panic: error 3 */
+ break;
+ case MSG_ID_BAT_CHARGE_COMPLETE:
+ case MSG_ID_BAT_CHARGE_LOW:
+ case MSG_ID_BAT_CHARGE_MED:
+ case MSG_ID_BAT_CHARGE_HIGH:
+ systemInfos.batteryUpdate=1;
+ systemInfos.inCharge=1;
+ systemInfos.batteryState = msg.id;
+ break;
+ case MSG_ID_BAT_CRITICAL_LOW:
+ case MSG_ID_BAT_LOW:
+ case MSG_ID_BAT_MED:
+ case MSG_ID_BAT_HIGH:
+ systemInfos.batteryUpdate=1;
+ systemInfos.batteryState = msg.id;
+ break;
+ case MSG_ID_MOTEURS_END_OF_MOUVMENT:
systemInfos.endOfMouvement= 1;
break;
@@ -218,18 +221,43 @@ void APPLICATION_StateMachine() {
APPLICATION_TransitionToNewState(stateInCharge);
}
-/* TODO
- * Revoir la gestion de la batterie ici
- */
-// if (systemInfos.batteryUpdate) {
-// ledState = APPLICATION_BatteryLevel(systemInfos.batteryVoltage, systemInfos.state);
-//
-// if (ledState == leds_niveau_bat_0)
-// APPLICATION_TransitionToNewState(stateLowBatDisable);
-// else if (systemInfos.state==stateStartup) {
-// MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
-// }
-// }
+ if (systemInfos.batteryUpdate) {
+ ledState = leds_off;
+
+ if (systemInfos.batteryState==MSG_ID_BAT_CRITICAL_LOW) {
+ ledState = leds_bat_critical_low;
+ APPLICATION_TransitionToNewState(stateLowBatDisable);
+ } else if (systemInfos.state == stateInCharge) {
+ switch (systemInfos.batteryState) {
+ case MSG_ID_BAT_CHARGE_COMPLETE:
+ ledState= leds_bat_charge_complete;
+ break;
+ case MSG_ID_BAT_CHARGE_HIGH:
+ ledState= leds_bat_charge_high;
+ break;
+ case MSG_ID_BAT_CHARGE_MED:
+ ledState= leds_bat_charge_med;
+ break;
+ case MSG_ID_BAT_CHARGE_LOW:
+ ledState= leds_bat_charge_low;
+ break;
+ }
+ } else if (systemInfos.state==stateStartup) {
+ switch (systemInfos.batteryState) {
+ case MSG_ID_BAT_HIGH:
+ ledState= leds_bat_high;
+ break;
+ case MSG_ID_BAT_MED:
+ ledState= leds_bat_med;
+ break;
+ case MSG_ID_BAT_LOW:
+ ledState= leds_bat_low;
+ break;
+ }
+ }
+
+ LEDS_Set(ledState);
+ }
if (systemInfos.cmd != CMD_NONE) {
/* a newer command just arrived, process it
@@ -317,7 +345,7 @@ void APPLICATION_StateMachine() {
void APPLICATION_TransitionToNewState(APPLICATION_State new_state) {
LEDS_State ledState = leds_off;
- uint32_t data;
+ int32_t data;
switch (new_state) {
case stateStartup:
@@ -325,20 +353,20 @@ void APPLICATION_TransitionToNewState(APPLICATION_State new_state) {
break;
case stateIdle:
ledState = leds_idle;
- MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
+ LEDS_Set(ledState);
MESSAGE_SendMailbox(MOTEURS_Mailbox, MSG_ID_MOTEURS_STOP, APPLICATION_Mailbox, (void*)NULL);
systemTimeout.watchdogEnabled=0;
break;
case stateRun:
ledState = leds_run;
- MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
+ LEDS_Set(ledState);
MESSAGE_SendMailbox(MOTEURS_Mailbox, MSG_ID_MOTEURS_STOP, APPLICATION_Mailbox, (void*)NULL);
break;
case stateInMouvement:
ledState = leds_run;
- MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
+ LEDS_Set(ledState);
if (systemInfos.cmd == CMD_MOVE) {
data = systemInfos.distance;
@@ -349,19 +377,20 @@ void APPLICATION_TransitionToNewState(APPLICATION_State new_state) {
}
break;
case stateInCharge:
- ledState = APPLICATION_BatteryLevel(systemInfos.batteryVoltage, systemInfos.inCharge);
- MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
+ /* les leds sont gerées dans APPLICATION_StateMachine */
+ MESSAGE_SendMailbox(MOTEURS_Mailbox, MSG_ID_MOTEURS_STOP, APPLICATION_Mailbox, (void*)NULL);
systemTimeout.watchdogEnabled=0;
break;
case stateWatchdogDisable:
ledState = leds_erreur_1;
- MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
+ LEDS_Set(ledState);
+
systemTimeout.watchdogEnabled=0;
break;
case stateLowBatDisable:
ledState = leds_bat_critical_low;
LEDS_Set(ledState);
- //MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
+
systemTimeout.watchdogEnabled=0;
vTaskDelay(pdMS_TO_TICKS(4000)); // wait 4s
diff --git a/software/dumber3/Application/batterie.c b/software/dumber3/Application/batterie.c
index 4427322..317626e 100644
--- a/software/dumber3/Application/batterie.c
+++ b/software/dumber3/Application/batterie.c
@@ -117,20 +117,49 @@ int BATTERIE_LireTension(uint16_t *val) {
return 0;
}
-const uint8_t BATTERIE_NiveauBatteryNormal[5] = {
- 0
-};
+/*
+ * Il faut considerer ces valeurs comme les seuils de baculement dans une categorie
+ * ou une autre
+ *
+ * Seuil : critical low high
+ * Tension batterie: 2.9 critic 3.1 low 3.3 med 3.6 high 4.2
+ *
+ */
+#define BATTERIE_LEVEL_CRITICAL 200
+#define BATTERIE_LEVEL_LOW 300
+#define BATTERIE_LEVEL_HIGH 500
-const uint8_t BATTERIE_NiveauBatteryCharge[5] = {
- 0
-};
+#define BATTERIE_LEVEL_CHARGE_LOW 400
+#define BATTERIE_LEVEL_CHARGE_HIGH 700
uint16_t BATTERIE_BatteryLevel(uint8_t voltage, BATTERIE_StatusChargerTypedef chargerStatus) {
uint16_t msgId=0;
- /* TODO: A faire
- * Pour l'instant, testons les niveaux de batterie
- */
+ switch (chargerStatus) {
+ case CHARGEUR_CHARGE_COMPLETE:
+ msgId = MSG_ID_BAT_CHARGE_COMPLETE;
+ break;
+ case CHARGEUR_IN_CHARGE:
+ if (voltage<=BATTERIE_LEVEL_CHARGE_LOW)
+ msgId = MSG_ID_BAT_CHARGE_LOW;
+ else if (voltage>=BATTERIE_LEVEL_CHARGE_HIGH)
+ msgId = MSG_ID_BAT_CHARGE_HIGH;
+ else
+ msgId = MSG_ID_BAT_CHARGE_MED;
+ break;
+ case CHARGEUR_NOT_PLUGGED:
+ if (voltage<=BATTERIE_LEVEL_CRITICAL)
+ msgId = MSG_ID_BAT_CRITICAL_LOW;
+ else if (voltage<=BATTERIE_LEVEL_LOW)
+ msgId = MSG_ID_BAT_LOW;
+ else if (voltage>=BATTERIE_LEVEL_HIGH)
+ msgId = MSG_ID_BAT_HIGH;
+ else
+ msgId = MSG_ID_BAT_MED;
+ break;
+ default:
+ msgId = MSG_ID_BAT_CHARGE_ERR;
+ }
return msgId;
}
diff --git a/software/dumber3/Application/commands.c b/software/dumber3/Application/commands.c
index 135c81b..8bf7e56 100644
--- a/software/dumber3/Application/commands.c
+++ b/software/dumber3/Application/commands.c
@@ -247,18 +247,17 @@ void cmdSendString(char *str) {
MESSAGE_SendMailbox(XBEE_Mailbox, MSG_ID_XBEE_ANS, APPLICATION_Mailbox, (char*) answer);
}
-void cmdSendBatteryLevel(char level) {
+void cmdSendBatteryLevel(uint16_t batteryState) {
char* answer;
- char localLevel=level;
- if (localLevel<0) localLevel=0;
- else if (localLevel>2) localLevel=2;
-
- switch (localLevel) {
- case 2:
+ switch (batteryState) {
+ case MSG_ID_BAT_CHARGE_COMPLETE:
+ case MSG_ID_BAT_CHARGE_HIGH:
+ case MSG_ID_BAT_HIGH:
answer = cmdAddChecksum("2\r");
break;
- case 1:
+ case MSG_ID_BAT_CHARGE_MED:
+ case MSG_ID_BAT_MED:
answer = cmdAddChecksum("1\r");
break;
default:
diff --git a/software/dumber3/Application/commands.h b/software/dumber3/Application/commands.h
index 3a1caac..da961f1 100644
--- a/software/dumber3/Application/commands.h
+++ b/software/dumber3/Application/commands.h
@@ -81,7 +81,7 @@ typedef struct __attribute__((packed)) {
CMD_Generic* cmdDecode(char* cmd, uint8_t length);
void cmdSendAnswer(uint8_t ans);
void cmdSendString(char* str);
-void cmdSendBatteryLevel(char level);
+void cmdSendBatteryLevel(uint16_t batteryState);
void cmdSendVersion(void);
void cmdSendBusyState(uint8_t state);
diff --git a/software/dumber3/Application/messages.h b/software/dumber3/Application/messages.h
index b58a10c..fe3f944 100644
--- a/software/dumber3/Application/messages.h
+++ b/software/dumber3/Application/messages.h
@@ -46,6 +46,7 @@ extern QueueHandle_t XBEE_Mailbox;
#define MSG_ID_MOTEURS_STOP 0x40
#define MSG_ID_MOTEURS_MOVE 0x41
#define MSG_ID_MOTEURS_TURN 0x42
+#define MSG_ID_MOTEURS_END_OF_MOUVMENT 0x43
#define MSG_ID_XBEE_CMD 0x50
#define MSG_ID_XBEE_ANS 0x51
diff --git a/software/dumber3/TestsPlans/tests.c b/software/dumber3/TestsPlans/tests.c
index 44725bb..1de29a6 100644
--- a/software/dumber3/TestsPlans/tests.c
+++ b/software/dumber3/TestsPlans/tests.c
@@ -75,13 +75,12 @@ void TESTS_BasicTests(void* params) {
char str[100];
ledsState = leds_run;
- MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledsState); // show program is running
+ LEDS_Set(ledsState); // show program is running
switch (TESTS_Nbr) {
case LEDS_Tests: //Leds tests
while (ledsState<=leds_state_unknown) {
- //MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledsState);
LEDS_Set(ledsState);
vTaskDelay(pdMS_TO_TICKS(TESTS_PERIODE)); // wait 10s
ledsState++;