Run separate task for regular checks like LED, push button, sound start/stop

pull/30/head
Pawel Jalocha 2020-09-25 01:30:17 +01:00
rodzic 849a5c599a
commit 8ed7d2f3e3
5 zmienionych plików z 74 dodań i 12 usunięć

Wyświetl plik

@ -30,7 +30,7 @@
static char Line[128];
FIFO<uint8_t, 8> KeyBuffer;
// FIFO<uint8_t, 8> KeyBuffer;
// ========================================================================================================================
@ -225,7 +225,12 @@ static void ProcessCtrlL(void) // print syste
}
void SleepIn(void)
{ xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
{
#ifdef WITH_SPIFFS
FlashLog_SaveReq=1;
vTaskDelay(1000);
#endif
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
Format_String(CONS_UART_Write, "Sleep-in\n");
xSemaphoreGive(CONS_Mutex);
@ -262,7 +267,7 @@ void SleepIn(void)
PowerMode=0;
for(int Idx=0; Idx<1500; Idx++)
{ LED_TimerCheck(1);
{ // LED_TimerCheck(1);
vTaskDelay(1); }
}
@ -327,7 +332,13 @@ static void ProcessInput(void)
if(Byte==0x03) ProcessCtrlC(); // if Ctrl-C received: print parameters
if(Byte==0x0C) ProcessCtrlL(); // if Ctrl-L received: list log files
if(Byte==0x16) ProcessCtrlV(); // if Ctrl-L received: suspend (verbose) printout
if(Byte==0x18) esp_restart() ; // if Ctrl-X received then restart
if(Byte==0x18)
{
#ifdef WITH_SPIFFS
FlashLog_SaveReq=1;
#endif
vTaskDelay(1000);
esp_restart(); } // if Ctrl-X received then restart
// if(Byte==0x19) Shutdown(); // if Ctrl-Y receiver: shutdown
#endif
NMEA.ProcessByte(Byte); // pass the byte through the NMEA processor
@ -368,6 +379,9 @@ void vTaskCTRL(void* pvParameters)
bool PowerOffRequest = AXP.readLongPressIRQ() /* || AXP.readShortPressIRQ() */ ;
if(PowerOffRequest)
{ PowerMode=0;
#ifdef WITH_SPIFFS
FlashLog_SaveReq=1;
#endif
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
Format_String(CONS_UART_Write, "Power-Off Request\n");
xSemaphoreGive(CONS_Mutex);
@ -405,11 +419,11 @@ void vTaskCTRL(void* pvParameters)
AXP.clearIRQ(); }
#endif
LED_TimerCheck(1); // update the LED flashes
#ifdef WITH_BEEPER
Play_TimerCheck(); // update the LED flashes
#endif
// LED_TimerCheck(1); // update the LED flashes
// #ifdef WITH_BEEPER
// Play_TimerCheck(); // update the LED flashes
// #endif
/*
int32_t PressRelease=Button_TimerCheck(); // 0 = no change
#ifdef DEBUG_PRINT
if(PressRelease!=0)
@ -427,7 +441,7 @@ void vTaskCTRL(void* pvParameters)
else // very long push
{ }
}
*/
uint32_t Time=TimeSync_Time();
bool TimeChange = Time!=PrevTime;
uint32_t Sec = (Time-1)%60;

Wyświetl plik

@ -1,7 +1,7 @@
#include "fifo.h"
#include "hal.h"
extern FIFO<uint8_t, 8> KeyBuffer;
// extern FIFO<uint8_t, 8> KeyBuffer;
#ifdef __cplusplus
extern "C"

Wyświetl plik

@ -495,6 +495,10 @@ uint8_t BARO_I2C = (uint8_t)I2C_BUS;
#define PIN_BUTTON GPIO_NUM_39
#endif
// ======================================================================================================
FIFO<uint8_t, 8> KeyBuffer;
// ======================================================================================================
// 48-bit unique ID of the chip
@ -1594,7 +1598,7 @@ void vApplicationIdleHook(void) // when RTOS is idle: should call "sleep until a
extern "C"
void vApplicationTickHook(void) // RTOS timer tick hook
{ LED_TimerCheck();
{ // LED_TimerCheck(1);
}
*/
@ -1937,6 +1941,38 @@ void IO_Configuration(void)
// ======================================================================================================
extern "C"
void vTaskTICK(void* pvParameters)
{
for( ; ; )
{ vTaskDelay(1);
LED_TimerCheck(1);
#ifdef WITH_BEEPER
Play_TimerCheck(); // update the LED flashes
#endif
int32_t PressRelease=Button_TimerCheck(); // 0 = no change
#ifdef DEBUG_PRINT
if(PressRelease!=0)
{ xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
Format_String(CONS_UART_Write, "Button: ");
Format_SignDec(CONS_UART_Write, PressRelease);
Format_String(CONS_UART_Write, "ms\n");
xSemaphoreGive(CONS_Mutex); }
#endif
if(PressRelease>0)
{ if(PressRelease<=700) // short button push: switch pages
{ KeyBuffer.Write(0x01); }
else if(PressRelease<=3000) // longer button push: some page action
{ KeyBuffer.Write(0x41); }
else // very long push
{ }
}
}
}
// ======================================================================================================
int NVS_Init(void)

Wyświetl plik

@ -8,6 +8,8 @@
#include "freertos/task.h"
#include "freertos/queue.h"
#include "fifo.h"
// ============================================================================================================
#define WITH_ESP32
@ -26,6 +28,10 @@
// ============================================================================================================
extern FIFO<uint8_t, 8> KeyBuffer;
// ============================================================================================================
extern uint8_t PowerMode; // 0=sleep/minimal power, 1=comprimize, 2=full power
// ============================================================================================================
@ -212,4 +218,9 @@ extern AXP192 AXP;
void Sleep(void);
#endif
#ifdef __cplusplus
extern "C"
#endif
void vTaskTICK(void* pvParameters);
#endif // __HAL_H__

Wyświetl plik

@ -110,6 +110,7 @@ void app_main(void)
#ifdef WITH_SOUND
xTaskCreate(vTaskSOUND, "SOUND", 2048, 0, tskIDLE_PRIORITY+3, 0);
#endif
xTaskCreate(vTaskTICK , "TICK", 1024, 0, tskIDLE_PRIORITY+2, 0);
// xTaskCreate(vTaskCTRL, "CTRL", 1536, 0, tskIDLE_PRIORITY+2, 0);
vTaskCTRL(0); // run directly the CTRL task, instead of creating a separate one.