changed LED behavior of the ESP32, to distiguish between stationary and mobile mode,

disabled WiFi state LED,
added reboot esp32 command
main
Jonas Arnold 4 years ago
parent 65f0029ac7
commit d4df711355
  1. 24
      ADIS_ESP32_Eclipse/main/challenge_app.c
  2. 1
      ADIS_ESP32_Eclipse/main/challenge_nvs.c
  3. 11
      ADIS_ESP32_Eclipse/main/led.c
  4. 2
      ADIS_ESP32_Eclipse/main/led.h
  5. 12
      ADIS_ESP32_Eclipse/main/wifi.c

@ -17,7 +17,7 @@
#include "McuUtility.h" #include "McuUtility.h"
#include "challenge_com.h" #include "challenge_com.h"
#include "challenge_nvs.h" #include "challenge_nvs.h"
#include "led.h"
/* LOCAL Var */ /* LOCAL Var */
/* identifies robot Mode for the challenge: true = robot is stationary, false = robot is moveable */ /* identifies robot Mode for the challenge: true = robot is stationary, false = robot is moveable */
@ -28,7 +28,7 @@ static TaskHandle_t appTaskHandle; /* task handle */
/* local function declarations */ /* local function declarations */
static void Challenge_App_SetRobotMode(bool modeStationary, bool storeToNvs); static void Challenge_App_SetRobotMode(bool modeStationary, bool storeToNvs);
static void Challenge_App_RebootEsp32(void);
static void appTask(void *pv){ static void appTask(void *pv){
/*Task argument not used /*Task argument not used
@ -76,7 +76,9 @@ BaseType_t res;
void Challenge_App_Init(void){ void Challenge_App_Init(void){
Challenge_Nvs_Init(); Challenge_Nvs_Init();
Challenge_Nvs_GetRobotModeFromNVS(&_robotModeStationary); bool retrievedMode = false;
Challenge_Nvs_GetRobotModeFromNVS(&retrievedMode);
Challenge_App_SetRobotMode(retrievedMode, false); // do not store to NVS, not required
res = xTaskCreate(appTask, "ChallengeAppTask", 4096/sizeof(StackType_t), (void*)"ARG_0", tskIDLE_PRIORITY, &appTaskHandle); res = xTaskCreate(appTask, "ChallengeAppTask", 4096/sizeof(StackType_t), (void*)"ARG_0", tskIDLE_PRIORITY, &appTaskHandle);
if(res != pdPASS){ if(res != pdPASS){
@ -91,11 +93,23 @@ bool Challenge_App_GetRobotMode(void){
static void Challenge_App_SetRobotMode(bool modeStationary, bool storeToNvs){ static void Challenge_App_SetRobotMode(bool modeStationary, bool storeToNvs){
_robotModeStationary = modeStationary; _robotModeStationary = modeStationary;
ESP_LOGI(TAG, "Changed robot mode to %s", _robotModeStationary?(unsigned char*)"stationary":(unsigned char*)"mobile"); ESP_LOGI(TAG, "Changed robot mode to %s", _robotModeStationary?(unsigned char*)"stationary":(unsigned char*)"mobile");
// update led behavior to be able to differentiate the robots
if(modeStationary){
LED_SetOnOffTime(5000, 1000);
} else{
LED_SetOnOffTime(500, 500);
}
if(storeToNvs){ if(storeToNvs){
Challenge_Nvs_StoreRobotModeToNVS(modeStationary); Challenge_Nvs_StoreRobotModeToNVS(modeStationary);
} }
} }
static void Challenge_App_RebootEsp32(void){
fflush(stdout);
esp_restart();
}
/*********/ /*********/
/* SHELL */ /* SHELL */
/*********/ /*********/
@ -111,6 +125,7 @@ static uint8_t PrintHelp(const McuShell_StdIOType *io) {
McuShell_SendHelpStr((unsigned char*)" help|status", (unsigned char*)"Shows Challenge help or status\r\n", io->stdOut); McuShell_SendHelpStr((unsigned char*)" help|status", (unsigned char*)"Shows Challenge help or status\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)" setMode s(tationary)", (unsigned char*)"Sets the mode of this robot to stationary\r\n", io->stdOut); McuShell_SendHelpStr((unsigned char*)" setMode s(tationary)", (unsigned char*)"Sets the mode of this robot to stationary\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)" setMode m(mobile)", (unsigned char*)"Sets the mode of this robot to mobile\r\n", io->stdOut); McuShell_SendHelpStr((unsigned char*)" setMode m(mobile)", (unsigned char*)"Sets the mode of this robot to mobile\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)" reboot", (unsigned char*)"Reboots the ESP32\r\n", io->stdOut);
return ERR_OK; return ERR_OK;
} }
@ -129,6 +144,9 @@ uint8_t Challenge_ParseShellCommand(const unsigned char* cmd, bool *handled, con
McuUtility_strcmp((char*)cmd, (char*)"challenge setMode m")==0 ) { McuUtility_strcmp((char*)cmd, (char*)"challenge setMode m")==0 ) {
*handled = TRUE; *handled = TRUE;
Challenge_App_SetRobotMode(false, true); // set mobile Challenge_App_SetRobotMode(false, true); // set mobile
}else if (McuUtility_strcmp((char*)cmd, (char*)"challenge reboot")==0) {
*handled = TRUE;
Challenge_App_RebootEsp32();
} }
return ERR_OK; return ERR_OK;
} }

@ -156,6 +156,7 @@ bool Challenge_Nvs_GetRobotModeFromNVS(bool *mode){
if(notInitialized){ if(notInitialized){
success = Challenge_Nvs_StoreRobotModeToNVS(false); // initialize to false success = Challenge_Nvs_StoreRobotModeToNVS(false); // initialize to false
*mode = false; // set out variable to false too
} }
Challenge_Nvs_ReleaseMutex(); Challenge_Nvs_ReleaseMutex();

@ -22,7 +22,7 @@ static McuLED_Handle_t ledHandle;
static TaskHandle_t taskHandle; static TaskHandle_t taskHandle;
static bool blinkyIsRunning = false; static bool blinkyIsRunning = false;
#define LED_OFF_TIME_MS 1000 static uint32_t offTimeMs = 1000; /* default off time of LED */
static uint32_t onTimeMs = 10; /* default on time of LED */ static uint32_t onTimeMs = 10; /* default on time of LED */
/* red led on the shield is on IO10, LOW active */ /* red led on the shield is on IO10, LOW active */
@ -32,6 +32,13 @@ static uint32_t onTimeMs = 10; /* default on time of LED */
void LED_SetOnTime(uint32_t ms) { void LED_SetOnTime(uint32_t ms) {
onTimeMs = ms; onTimeMs = ms;
} }
void LED_SetOffTime(uint32_t ms) {
offTimeMs = ms;
}
void LED_SetOnOffTime(uint32_t onMs, uint32_t offMs){
onTimeMs = onMs;
offTimeMs = offMs;
}
void LED_On(void) { void LED_On(void) {
McuLED_On(ledHandle); McuLED_On(ledHandle);
@ -88,7 +95,7 @@ static void blinkyTask(void *pv) {
LED_On(); LED_On();
vTaskDelay(pdMS_TO_TICKS(onTimeMs)); vTaskDelay(pdMS_TO_TICKS(onTimeMs));
LED_Off(); LED_Off();
vTaskDelay(pdMS_TO_TICKS(LED_OFF_TIME_MS)); vTaskDelay(pdMS_TO_TICKS(offTimeMs));
} }
} }

@ -15,6 +15,8 @@ extern "C" {
#endif #endif
void LED_SetOnTime(uint32_t ms); void LED_SetOnTime(uint32_t ms);
void LED_SetOffTime(uint32_t ms);
void LED_SetOnOffTime(uint32_t onMs, uint32_t offMs);
void LED_Suspend(void); void LED_Suspend(void);
void LED_Resume(void); void LED_Resume(void);
void LED_GetStatus(unsigned char *buf, size_t bufSize); void LED_GetStatus(unsigned char *buf, size_t bufSize);

@ -258,15 +258,15 @@ static void WiFiTask(void *pv) {
McuLog_info("Initialize WiFi"); McuLog_info("Initialize WiFi");
initialise_wifi(); initialise_wifi();
#if PL_CONFIG_USE_BLINKY //#if PL_CONFIG_USE_BLINKY
LED_SetOnTime(LED_ON_TIME_MS_DISCONNECTED); // LED_SetOnTime(LED_ON_TIME_MS_DISCONNECTED);
#endif //#endif
for(;;) { for(;;) {
vTaskDelay(pdMS_TO_TICKS(5000)); vTaskDelay(pdMS_TO_TICKS(5000));
isConnected = xEventGroupGetBits(s_wifi_event_group)&WIFI_CONNECTED_BIT; isConnected = xEventGroupGetBits(s_wifi_event_group)&WIFI_CONNECTED_BIT;
#if PL_CONFIG_USE_BLINKY // #if PL_CONFIG_USE_BLINKY
LED_SetOnTime(isConnected?LED_ON_TIME_MS_CONNECTED:LED_ON_TIME_MS_DISCONNECTED); // LED_SetOnTime(isConnected?LED_ON_TIME_MS_CONNECTED:LED_ON_TIME_MS_DISCONNECTED);
#endif // #endif
if (state == WIFI_STATE_INIT && isConnected) { /* first connection */ if (state == WIFI_STATE_INIT && isConnected) { /* first connection */
state = WIFI_STATE_CONNECTED; state = WIFI_STATE_CONNECTED;
ESP_LOGI(TAG, "WiFi is connected."); ESP_LOGI(TAG, "WiFi is connected.");

Loading…
Cancel
Save