|
| 1 | +/* |
| 2 | +MIT License |
| 3 | +
|
| 4 | +Copyright (c) <2024> <Matthew Eshleman - https://covemountainsoftware.com> |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +of this software and associated documentation files (the "Software"), to deal |
| 8 | +in the Software without restriction, including without limitation the rights |
| 9 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +copies of the Software, and to permit persons to whom the Software is |
| 11 | +furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in all |
| 14 | +copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +SOFTWARE. |
| 23 | +*/ |
| 24 | + |
| 25 | +#ifndef BUTTON_SERVICE_H |
| 26 | +#define BUTTON_SERVICE_H |
| 27 | + |
| 28 | +#include <stdbool.h> |
| 29 | +#include "cmsExecutionOption.h" |
| 30 | + |
| 31 | +#ifdef __cplusplus |
| 32 | +extern "C" { |
| 33 | +#endif |
| 34 | + |
| 35 | +/** |
| 36 | + * Buttons supported on this product |
| 37 | + */ |
| 38 | +typedef enum ButtonFlag { |
| 39 | + BUTTON_ON_OFF = 0x1, |
| 40 | + BUTTON_FUNC_A = 0x2, |
| 41 | +} ButtonFlagT; |
| 42 | + |
| 43 | +typedef enum ButtonState { |
| 44 | + BUTTON_PRESSED, |
| 45 | + BUTTON_RELEASED, |
| 46 | +} ButtonStateT; |
| 47 | + |
| 48 | +/** |
| 49 | + * Initialize the Button Service. Does not start the thread, just prepares. |
| 50 | + */ |
| 51 | +void ButtonService_Init(); |
| 52 | + |
| 53 | +/** |
| 54 | + * Destroy the ButtonService. Typically only called in unit testing environment. |
| 55 | + */ |
| 56 | +void ButtonService_Destroy(); |
| 57 | + |
| 58 | +/** |
| 59 | + * Start the button service/thread. Init() must have been called first. |
| 60 | + * @param option |
| 61 | + */ |
| 62 | +void ButtonService_Start(ExecutionOptionT option); |
| 63 | + |
| 64 | +/** |
| 65 | + * typedef for the button service callback |
| 66 | + */ |
| 67 | +typedef void (*ButtonService_ButtonChangeCallback)(ButtonFlagT flags, ButtonStateT state, void *context); |
| 68 | + |
| 69 | +/** |
| 70 | + * Register callback to be executed from the button service |
| 71 | + * thread context. Guaranteed to NOT be called from an ISR context. |
| 72 | + * @param callback |
| 73 | + * @param context |
| 74 | + */ |
| 75 | +void ButtonService_RegisterButtonChangeCallback(ButtonService_ButtonChangeCallback callback, void *context); |
| 76 | + |
| 77 | +/****************************************************************************/ |
| 78 | +/***** Backdoor functionality provided for unit testing access only ********/ |
| 79 | +/****************************************************************************/ |
| 80 | + |
| 81 | +/** |
| 82 | + * provided for unit testing access only. For the button service, |
| 83 | + * will check if semaphore token is available or not (i.e. |
| 84 | + * the button ISR has occurred). |
| 85 | + * |
| 86 | + * @param option EXECUTION_OPTION_NORMAL - internal, normal thread use |
| 87 | + * EXECUTION_OPTION_UNIT_TEST - for unit testing |
| 88 | + * |
| 89 | + * @return true: an event was processed |
| 90 | + * false: no events, nothing processed. |
| 91 | + */ |
| 92 | +bool ButtonService_ProcessOneEvent(ExecutionOptionT option); |
| 93 | + |
| 94 | +/** |
| 95 | + * Fake/simulate the ISR that the button service relies upon |
| 96 | + */ |
| 97 | +void ButtonService_SimulateIsr(); |
| 98 | + |
| 99 | +#ifdef __cplusplus |
| 100 | +} |
| 101 | +#endif |
| 102 | + |
| 103 | +#endif //BUTTON_SERVICE_H |
0 commit comments