API Documentation v0.0.1
Loading...
Searching...
No Matches
LedUpdateState.h
1/**********************************************************************************************************************
2 * ____ _ _ _
3 * / __ \ | | | | | |
4 * | | | |_ __ ___ _ __ | |__| | ___ _ __ _ __ ___| |_
5 * | | | | '_ \ / _ \ '_ \| __ |/ _ \| '__| '_ \ / _ \ __|
6 * | |__| | |_) | __/ | | | | | | (_) | | | | | | __/ |_
7 * \____/| .__/ \___|_| |_|_| |_|\___/|_| |_| |_|\___|\__|
8 * | |
9 * |_|
10 * ----------------------------------------------------------------------------------
11 *
12 * @file LedUpdateState.h
13 * @author Ulukaii
14 * @date 24.05.2025
15 * @version t 0.3.2
16 * @copyright Copyright 2016-2025 OpenHornet. See 2A13-BACKLIGHT_CONTROLLER.ino for details.
17 * @brief This class serves just one purpose: track whether the LEDs need to be updated.
18 * The flag can be set by any panel as it processes DCS-BIOS updates.
19 * Then, the flag is read by board.h in each loop and if TRUE, used to trigger the update of the LEDs.
20 * @details Technical implementation: singleton state machine and using interrupt pausing to ensure atomicity
21 * when writing the flag.
22 *********************************************************************************************************************/
23
24#ifndef __LED_UPDATE_STATE_H
25#define __LED_UPDATE_STATE_H
26
27#include <Arduino.h>
28#include <avr/interrupt.h> // For interrupt control functions
29
31private:
32 static LedUpdateState* instance;
33 volatile bool ledsNeedUpdate; // volatile to prevent compiler optimization
34
39 LedUpdateState() { // Private constructor to enforce singleton pattern
40 ledsNeedUpdate = false;
41 }
42
43public:
50 if (!instance) {
51 instance = new LedUpdateState();
52 }
53 return instance;
54 }
55
61 void setUpdateFlag(bool requireUpdate) {
62 cli(); // Disable interrupts (same as noInterrupts())
63 ledsNeedUpdate = requireUpdate;
64 sei(); // Re-enable interrupts (same as interrupts())
65 }
66
72 bool getUpdateFlag() const {
73 return ledsNeedUpdate;
74 }
75};
76
77// Initialize static instance pointer
78LedUpdateState* LedUpdateState::instance = nullptr;
79
80#endif
void setUpdateFlag(bool requireUpdate)
Sets the LED update flag in an atomic operation.
static LedUpdateState * getInstance()
Gets the singleton instance of the LedUpdateState class.
bool getUpdateFlag() const
Gets the current state of the LED update flag.