diff options
Diffstat (limited to 'Libraries/Button/button_task.c')
-rw-r--r-- | Libraries/Button/button_task.c | 207 |
1 files changed, 207 insertions, 0 deletions
diff --git a/Libraries/Button/button_task.c b/Libraries/Button/button_task.c new file mode 100644 index 0000000..fb5a8c9 --- /dev/null +++ b/Libraries/Button/button_task.c @@ -0,0 +1,207 @@ +#include "head_task.h" +#include "tsl_user.h" +#include "nixie_driver_process.h" + +#include "button_handler.h" + +// FreeRTOS includes +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "semphr.h" + + +// Номера сенсорных кнопушек +//enum { +// TKEY_NUM_1 = 0, +// TKEY_NUM_2 +//}; + +#define TKEY_NUM_1 0 +#define TKEY_NUM_2 1 + +// Эти определения пойдут в модуль обработки кнопушек уровня пользователя - Button_Module + +#define TEST_TKEY(NB) ((MyTKeys[(NB)].p_Data->StateId == TSL_STATEID_DETECT) ||\ + (MyTKeys[(NB)].p_Data->StateId == TSL_STATEID_DEB_RELEASE_DETECT)) + +#define TEST_LINROT(NB) ((MyLinRots[(NB)].p_Data->StateId == TSL_STATEID_DETECT) ||\ + (MyLinRots[(NB)].p_Data->StateId == TSL_STATEID_DEB_RELEASE_DETECT)) + +// For debug purpose with STMStudio +uint8_t DS[TSLPRM_TOTAL_TKEYS + TSLPRM_TOTAL_LNRTS]; // To store the States (one per object) +int16_t DD[TSLPRM_TOTAL_TKEYS + (TSLPRM_TOTAL_LNRTS * 3)]; // To store the Deltas (one per channel) + +//static uint8_t touch_tube_bufer [MAX_TUBES] = {0}; + +// Битовая переменная, в которой будут устанавливаться соответствующие +// номерам нажатых кнопушек биты +static volatile uint8_t tkey_buttons_bits = 0; + + +static void ProcessSensors ( void ); + + +// ---------------------------------------------------------------------------- +// Ф-я которая будет возвращать значение битовой переменной +// и вызываться из модуля button_handler.c (ф-я Button_ProcessFSM ();) +// ---------------------------------------------------------------------------- +uint8_t Button_GetCurrButtons ( void ) +{ + uint8_t curr_buts_bits = tkey_buttons_bits; + return curr_buts_bits; +} + +// ---------------------------------------------------------------------------- +// +// ---------------------------------------------------------------------------- +void ProcessFSM_ButtonTask ( void ) +{ + /* Execute STMTouch Driver state machine */ + if (TSL_user_Action () == TSL_STATUS_OK) + { + ProcessSensors (); // Execute sensors related tasks + + // Обработчик нажатий кнопушек (автомат) + //Button_ProcessFSM (); + } + Button_ProcessFSM (); + taskYIELD(); +} + + +/** + * @brief Manage the activity on sensors when touched/released (example) + * @param None + * @retval None + */ +static void ProcessSensors ( void ) +{ + uint32_t idx; + //uint32_t idxch; + uint32_t idx_ds = 0; + uint32_t idx_dd = 0; + //uint32_t touched = 0; +#if USE_LCD > 0 + static uint32_t started = 0; +#endif + +#if TSLPRM_TOTAL_TKEYS > 0 + // Read all TKeys + for (idx = 0; idx < TSLPRM_TOTAL_TKEYS; idx++) + { + // STMStudio debug + DS[idx_ds++] = MyTKeys[idx].p_Data->StateId; + DD[idx_dd++] = MyTKeys[idx].p_ChD->Delta; +// if (TEST_TKEY(idx)) +// { +// touched = 1; +// } + } +#endif + +#if TSLPRM_TOTAL_LNRTS > 0 + uint32_t idxch; + // Read all Linear and Rotary sensors + for (idx = 0; idx < TSLPRM_TOTAL_LNRTS; idx++) + { + // STMStudio debug + DS[idx_ds++] = MyLinRots[idx].p_Data->StateId; + for (idxch = 0; idxch < MyLinRots[idx].NbChannels; idxch++) + { + DD[idx_dd++] = MyLinRots[idx].p_ChD[idxch].Delta; + } +// if (TEST_LINROT(idx)) +// { +// touched = 1; +// } + } +#endif + + + // Тут можно поменять кнопки местами + + if (TEST_TKEY(TKEY_NUM_2)) + { + tkey_buttons_bits |= 1 << TKEY_NUM_1; + GPIOB->ODR ^= GPIO_Pin_2; + } + else + { + tkey_buttons_bits &= ~(1 << TKEY_NUM_1); + GPIOB->ODR ^= GPIO_Pin_2; + } + + if (TEST_TKEY(TKEY_NUM_1)) + { + tkey_buttons_bits |= 1 << TKEY_NUM_2; + GPIOB->ODR ^= GPIO_Pin_2; + + } + else + { + tkey_buttons_bits &= ~(1 << TKEY_NUM_2); + GPIOB->ODR ^= GPIO_Pin_2; + } + +} + +/** + * @brief Executed when a sensor is in Off state + * @param None + * @retval None + */ +void MyTKeys_OffStateProcess(void) +{ + /* Add here your own processing when a sensor is in Off state */ +} + +void MyLinRots_OffStateProcess(void) +{ + /* Add here your own processing when a sensor is in Off state */ +} + +/** + * @brief Executed at each timer interruption (option must be enabled) + * @param None + * @retval None + */ +void TSL_CallBack_TimerTick(void) +{ +} + +/** + * @brief Executed when a sensor is in Error state + * @param None + * @retval None + */ +void MyTKeys_ErrorStateProcess(void) +{ + /* Add here your own processing when a sensor is in Error state */ + //TSL_linrot_SetStateOff(); + TSL_tkey_SetStateOff (); + while(1) + { + } +} + +void MyLinRots_ErrorStateProcess(void) +{ + /* Add here your own processing when a sensor is in Error state */ + TSL_linrot_SetStateOff(); + //TSL_tkey_SetStateOff (); + while(1) + { + } +} + + +// ---------------------------------------------------------------------------- +// Задача ОС, реализующая обработку нажатий кнопушек +// Здесь обрабатывается уже результат обработки сенсорных нажатий +// ---------------------------------------------------------------------------- +void Button_Task ( void *pvParameters ) +{ + while(1)ProcessFSM_ButtonTask (); + //vTaskDelete(NULL); +}
\ No newline at end of file |