Release 1.01
ButtonController.h@0:b6d729ae4f27, 2019-07-25 (annotated)
- Committer:
- foxbrianr
- Date:
- Thu Jul 25 00:43:08 2019 +0000
- Revision:
- 0:b6d729ae4f27
- Child:
- 1:86f6ebbe4fd1
Baseline for testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
foxbrianr | 0:b6d729ae4f27 | 1 | #ifndef _BUTTON_CONTROLLER_ |
foxbrianr | 0:b6d729ae4f27 | 2 | #define _BUTTON_CONTROLLER_ |
foxbrianr | 0:b6d729ae4f27 | 3 | |
foxbrianr | 0:b6d729ae4f27 | 4 | #include "mbed.h" |
foxbrianr | 0:b6d729ae4f27 | 5 | #include "rtos.h" |
foxbrianr | 0:b6d729ae4f27 | 6 | #include "mcp23s08.h" |
foxbrianr | 0:b6d729ae4f27 | 7 | #include "Menu.h" |
foxbrianr | 0:b6d729ae4f27 | 8 | #include "Navigator.h" |
foxbrianr | 0:b6d729ae4f27 | 9 | |
foxbrianr | 0:b6d729ae4f27 | 10 | /** |
foxbrianr | 0:b6d729ae4f27 | 11 | * service to manage the external GPIO expander board. |
foxbrianr | 0:b6d729ae4f27 | 12 | */ |
foxbrianr | 0:b6d729ae4f27 | 13 | typedef enum |
foxbrianr | 0:b6d729ae4f27 | 14 | { |
foxbrianr | 0:b6d729ae4f27 | 15 | NO_BUTTON = 27, |
foxbrianr | 0:b6d729ae4f27 | 16 | BUTTON_UP = 26, |
foxbrianr | 0:b6d729ae4f27 | 17 | BUTTON_DOWN = 25, |
foxbrianr | 0:b6d729ae4f27 | 18 | BUTTON_MODE = 19, |
foxbrianr | 0:b6d729ae4f27 | 19 | BUTTON_SET = 11, |
foxbrianr | 0:b6d729ae4f27 | 20 | BUTTON_CLEAR = 0 |
foxbrianr | 0:b6d729ae4f27 | 21 | } tButtonValue ; |
foxbrianr | 0:b6d729ae4f27 | 22 | |
foxbrianr | 0:b6d729ae4f27 | 23 | typedef void (*t_ButtonPressCallback)(void); |
foxbrianr | 0:b6d729ae4f27 | 24 | |
foxbrianr | 0:b6d729ae4f27 | 25 | |
foxbrianr | 0:b6d729ae4f27 | 26 | /*** |
foxbrianr | 0:b6d729ae4f27 | 27 | * |
foxbrianr | 0:b6d729ae4f27 | 28 | * This class wrapps the communication with the GPIO expander over SPI bus. |
foxbrianr | 0:b6d729ae4f27 | 29 | * PIN 0 : Up |
foxbrianr | 0:b6d729ae4f27 | 30 | * PIN 1 : Down |
foxbrianr | 0:b6d729ae4f27 | 31 | * PIN 2 : Clear |
foxbrianr | 0:b6d729ae4f27 | 32 | * PIN 3 : Mode |
foxbrianr | 0:b6d729ae4f27 | 33 | * PIN 4 : Set |
foxbrianr | 0:b6d729ae4f27 | 34 | * PIN 5 : Enable Audio |
foxbrianr | 0:b6d729ae4f27 | 35 | * PIN 6 : na |
foxbrianr | 0:b6d729ae4f27 | 36 | * PIN 7 : na |
foxbrianr | 0:b6d729ae4f27 | 37 | * |
foxbrianr | 0:b6d729ae4f27 | 38 | * MASK = 0x1F; |
foxbrianr | 0:b6d729ae4f27 | 39 | * |
foxbrianr | 0:b6d729ae4f27 | 40 | */ |
foxbrianr | 0:b6d729ae4f27 | 41 | class ButtonController |
foxbrianr | 0:b6d729ae4f27 | 42 | { |
foxbrianr | 0:b6d729ae4f27 | 43 | public : |
foxbrianr | 0:b6d729ae4f27 | 44 | |
foxbrianr | 0:b6d729ae4f27 | 45 | Navigator * navigator; |
foxbrianr | 0:b6d729ae4f27 | 46 | mcp23s08 * spi_io_exp; |
foxbrianr | 0:b6d729ae4f27 | 47 | Mutex _mutex; |
foxbrianr | 0:b6d729ae4f27 | 48 | unsigned char currentValue; |
foxbrianr | 0:b6d729ae4f27 | 49 | unsigned char prevValue; |
foxbrianr | 0:b6d729ae4f27 | 50 | unsigned char confirmedValue; |
foxbrianr | 0:b6d729ae4f27 | 51 | unsigned int countsSinceChange; |
foxbrianr | 0:b6d729ae4f27 | 52 | unsigned char isServiced; |
foxbrianr | 0:b6d729ae4f27 | 53 | unsigned char isHeld; |
foxbrianr | 0:b6d729ae4f27 | 54 | |
foxbrianr | 0:b6d729ae4f27 | 55 | |
foxbrianr | 0:b6d729ae4f27 | 56 | CircularBuffer<uint8_t, 64> cmd_queue; |
foxbrianr | 0:b6d729ae4f27 | 57 | |
foxbrianr | 0:b6d729ae4f27 | 58 | ButtonController(Navigator * navigator); |
foxbrianr | 0:b6d729ae4f27 | 59 | ~ButtonController(); |
foxbrianr | 0:b6d729ae4f27 | 60 | |
foxbrianr | 0:b6d729ae4f27 | 61 | void pressButtonUp(void); |
foxbrianr | 0:b6d729ae4f27 | 62 | void pressButtonDown(void); |
foxbrianr | 0:b6d729ae4f27 | 63 | void pressButtonClear(void); |
foxbrianr | 0:b6d729ae4f27 | 64 | void pressButtonMode(void); |
foxbrianr | 0:b6d729ae4f27 | 65 | void pressButtonSet(void); |
foxbrianr | 0:b6d729ae4f27 | 66 | void releaseButton(void); |
foxbrianr | 0:b6d729ae4f27 | 67 | |
foxbrianr | 0:b6d729ae4f27 | 68 | void init(void); |
foxbrianr | 0:b6d729ae4f27 | 69 | void update(void); |
foxbrianr | 0:b6d729ae4f27 | 70 | void update(Navigator * navigator); |
foxbrianr | 0:b6d729ae4f27 | 71 | void update(Menu * menu); |
foxbrianr | 0:b6d729ae4f27 | 72 | void update(int currentValue, Menu * menu); |
foxbrianr | 0:b6d729ae4f27 | 73 | |
foxbrianr | 0:b6d729ae4f27 | 74 | uint8_t getCurrentState (); |
foxbrianr | 0:b6d729ae4f27 | 75 | }; |
foxbrianr | 0:b6d729ae4f27 | 76 | |
foxbrianr | 0:b6d729ae4f27 | 77 | |
foxbrianr | 0:b6d729ae4f27 | 78 | #endif |