tdse-tp3_04-interactive_menu

Index Commits Files Refs
app/inc/task_sensor_attribute.h (7602B)
   1 /*
   2  * Copyright (c) 2023 Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>.
   3  * All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions are met:
   7  *
   8  * 1. Redistributions of source code must retain the above copyright
   9  *    notice, this list of conditions and the following disclaimer.
  10  *
  11  * 2. Redistributions in binary form must reproduce the above copyright
  12  *    notice, this list of conditions and the following disclaimer in the
  13  *    documentation and/or other materials provided with the distribution.
  14  *
  15  * 3. Neither the name of the copyright holder nor the names of its
  16  *    contributors may be used to endorse or promote products derived from
  17  *    this software without specific prior written permission.
  18  *
  19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  28  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  29  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30  * POSSIBILITY OF SUCH DAMAGE.
  31  *
  32  * @file   : task_sensor_attribute.h
  33  * @date   : Set 26, 2023
  34  * @author : Juan Manuel Cruz <jcruz@fi.uba.ar> <jcruz@frba.utn.edu.ar>
  35  * @version    v1.0.0
  36  */
  37 
  38 #ifndef TASK_INC_TASK_SENSOR_ATTRIBUTE_H_
  39 #define TASK_INC_TASK_SENSOR_ATTRIBUTE_H_
  40 
  41 /********************** CPP guard ********************************************/
  42 #ifdef __cplusplus
  43 extern "C" {
  44 #endif
  45 
  46 /********************** inclusions *******************************************/
  47 
  48 /********************** macros ***********************************************/
  49 
  50 /********************** typedef **********************************************/
  51 /* Sensor Statechart - State Transition Table */
  52 /*     ------------------------+-----------------------+-----------------------+-----------------------+------------------------
  53  *     | Current               | Event                 |                       | Next                  |                       |
  54  *     | State                 | (Parameters)          | [Guard]               | State                 | Actions               |
  55  *     |=======================+=======================+=======================+=======================+=======================|
  56  *     | INICIAL               |                       |                       | ST_BTN_XX_UP          |                       |
  57  *     |-----------------------+-----------------------+-----------------------+-----------------------+-----------------------|
  58  *     | ST_BTN_XX_UP          | EV_BTN_XX_UP          |                       | ST_BTN_XX_UP          |                       |
  59  *     |                       +-----------------------+-----------------------+-----------------------+-----------------------|
  60  *     |                       | EV_BTN_XX_DOWN        |                       | ST_BTN_XX_FALLING     | tick = TICK_MAX       |
  61  *     |-----------------------+-----------------------+-----------------------+-----------------------+-----------------------|
  62  *     | ST_BTN_XX_FALLING     | EV_BTN_XX_UP          | [tick == 0]           | ST_BTN_XX_UP          |                       |
  63  *     |                       |                       +-----------------------+-----------------------+-----------------------|
  64  *     |                       |                       | [tick >  0]           | ST_BTN_XX_FALLING     | tick--                |
  65  *     |                       +-----------------------+-----------------------+-----------------------+-----------------------|
  66  *     |                       | EV_BTN_XX_DOWN        | [tick == 0]           | ST_BTN_XX_DOWN        | put_event_task_system |
  67  *     |                       |                       |                       |                       |  (event)              |
  68  *     |                       |                        +-----------------------+-----------------------+-----------------------|
  69  *     |                       |                       | [tick >  0]           | ST_BTN_XX_FALLING     | tick--                |
  70  *     |-----------------------+-----------------------+-----------------------+-----------------------+-----------------------|
  71  *    | ST_BTN_XX_DOWN        | EV_BTN_XX_UP          |                       | ST_BTN_XX_RISING      | tick = TICK_MAX       |
  72  *     |                       +-----------------------+-----------------------+-----------------------+-----------------------|
  73  *     |                       | EV_BTN_XX_DOWN        |                       | ST_BTN_XX_DOWN        |                       |
  74  *     |-----------------------+-----------------------+-----------------------+-----------------------+-----------------------|
  75  *     | ST_BTN_XX_RISING      | EV_BTN_XX_UP          | [tick == 0]           | ST_BTN_XX_UP          | put_event_task_system |
  76  *     |                       |                       |                       |                       |  (event)              |
  77  *     |                       |                        +-----------------------+-----------------------+-----------------------|
  78  *     |                       |                       | [tick >  0]           | ST_BTN_XX_RISING      | tick--                |
  79  *     |                       +-----------------------+-----------------------+-----------------------+-----------------------|
  80  *     |                       | EV_BTN_XX_DOWN        | [tick == 0]           | ST_BTN_XX_DOWN        |                       |
  81  *     |                       |                        +-----------------------+-----------------------+-----------------------|
  82  *     |                       |                       | [tick >  0]           | ST_BTN_XX_RISING      | tick--                |
  83  *     ------------------------+-----------------------+-----------------------+-----------------------+------------------------
  84  */
  85 
  86 /* Events to excite Task Sensor */
  87 typedef enum task_sensor_ev {EV_BTN_XX_UP,
  88                              EV_BTN_XX_DOWN} task_sensor_ev_t;
  89 
  90 /* States of Task Sensor */
  91 typedef enum task_sensor_st {ST_BTN_XX_UP,
  92                              ST_BTN_XX_FALLING,
  93                              ST_BTN_XX_DOWN,
  94                              ST_BTN_XX_RISING} task_sensor_st_t;
  95 
  96 /* Identifier of Task Sensor */
  97 typedef enum task_sensor_id {ID_BTN_ENT,
  98                              ID_BTN_NEX,
  99                              ID_BTN_ESC} task_sensor_id_t;
 100 
 101 typedef struct
 102 {
 103     task_sensor_id_t    identifier;
 104     GPIO_TypeDef *        gpio_port;
 105     uint16_t            pin;
 106     GPIO_PinState        pressed;
 107     uint32_t            tick_max;
 108     task_sensor_ev_t    signal_up;
 109     task_sensor_ev_t    signal_down;
 110 } task_sensor_cfg_t;
 111 
 112 typedef struct
 113 {
 114     uint32_t            tick;
 115     task_sensor_st_t    state;
 116     task_sensor_ev_t    event;
 117 } task_sensor_dta_t;
 118 
 119 /********************** external data declaration ****************************/
 120 extern task_sensor_dta_t task_sensor_dta_list[];
 121 
 122 /********************** external functions declaration ***********************/
 123 
 124 /********************** End of CPP guard *************************************/
 125 #ifdef __cplusplus
 126 }
 127 #endif
 128 
 129 #endif /* TASK_INC_TASK_SENSOR_ATTRIBUTE_H_ */
 130 
 131 /********************** end of file ******************************************/