API Documentation v0.0.1
Loading...
Searching...
No Matches
Board Class Reference

Public Member Functions

void setupRotaryEncoder (int encSwPin, int encAPin, int encBPin)
 Sets up the rotary encoder with switch and encoder pins.
 
void registerChannel (Channel *channel)
 Registers a channel with the board.
 
void updateLeds ()
 Update the physical LED state.
 
int handleModeChange ()
 Handles mode change button press and returns current mode.
 
void processMode ()
 Processes the current mode.
 
void fillSolid (const CRGB &color, int brightness=-1)
 Fills all channels with a solid color.
 
void setAllLightsOff ()
 Turns off all lights in all channels and resets brightness state.
 
void updateInstrumentLights (uint16_t newValue)
 Updates all channels with new instrument lighting value.
 
void updateConsoleLights (uint16_t newValue)
 Updates all channels with new console lighting value.
 
void updateFloodLights (uint16_t newValue)
 Updates all channels with new flood lighting value.
 

Static Public Member Functions

static BoardgetInstance ()
 Gets or createsthe singleton instance of the Board class.
 
static void onInstrIntLtChange (unsigned int newValue)
 Callback for instrument lighting changes from DCS-BIOS.
 
static void onConsolesDimmerChange (unsigned int newValue)
 Callback for console dimmer changes from DCS-BIOS.
 
static void onFloodDimmerChange (unsigned int newValue)
 Callback for flood lighting changes from DCS-BIOS.
 

Public Attributes

DcsBios::IntegerBuffer instrIntLtBuffer {FA_18C_hornet_INSTR_INT_LT, onInstrIntLtChange}
 
DcsBios::IntegerBuffer consolesDimmerBuffer {FA_18C_hornet_CONSOLES_DIMMER, onConsolesDimmerChange}
 
DcsBios::IntegerBuffer floodDimmerBuffer {FA_18C_hornet_FLOOD_DIMMER, onFloodDimmerChange}
 

Detailed Description

Definition at line 45 of file Board.h.

Member Function Documentation

◆ getInstance()

static Board * Board::getInstance ( )
inlinestatic

Gets or createsthe singleton instance of the Board class.

See also
This method is called by setup() in 2A13-BACKLIGHT_CONTROLLER.ino

Definition at line 96 of file Board.h.

96 {
97 return instance ? instance : (instance = new Board()); }
Definition Board.h:45

◆ setupRotaryEncoder()

void Board::setupRotaryEncoder ( int encSwPin,
int encAPin,
int encBPin )
inline

Sets up the rotary encoder with switch and encoder pins.

Parameters
encSwPinPin number for the encoder switch
encAPinPin number for encoder A
encBPinPin number for encoder B
See also
This method is called by setup() in 2A13-BACKLIGHT_CONTROLLER.ino

Definition at line 106 of file Board.h.

106 {
107 this->encSwPin = encSwPin;
108 pinMode(encSwPin, INPUT_PULLUP); // Initialize mode change pin
109 encoder = new RotaryEncoder(encAPin, encBPin, RotaryEncoder::LatchMode::TWO03);
110 }

◆ registerChannel()

void Board::registerChannel ( Channel * channel)
inline

Registers a channel with the board.

Parameters
channelPointer to the channel to register
See also
This method is called by setup() in 2A13-BACKLIGHT_CONTROLLER.ino

Definition at line 117 of file Board.h.

117 {
118 channels[channelCount++] = channel;
119 }

◆ updateLeds()

void Board::updateLeds ( )
inline

Update the physical LED state.

See also
This method is called by loop() in 2A13-BACKLIGHT_CONTROLLER.ino

Definition at line 125 of file Board.h.

125 {
126 if (LedUpdateState::getInstance()->getUpdateFlag()) {
127 updCountdown = (updCountdown == 0) ? 32 : updCountdown; // Countdown logic allows to collect LED updates
128 updCountdown--; // from 32 loop() calls into one FastLED.show()
129 if (updCountdown == 0) { // Trigger FastLED.show() at end of countdown
130 cli();
131 FastLED.show();
132 LedUpdateState::getInstance()->setUpdateFlag(false); // Reset update flag
133 sei();
134 }
135 }
136 }
void setUpdateFlag(bool requireUpdate)
Sets the LED update flag in an atomic operation.
static LedUpdateState * getInstance()
Gets the singleton instance of the LedUpdateState class.

References LedUpdateState::getInstance(), and LedUpdateState::setUpdateFlag().

◆ handleModeChange()

int Board::handleModeChange ( )
inline

Handles mode change button press and returns current mode.

Returns
The current mode after handling the button press
See also
This method is called by loop() in 2A13-BACKLIGHT_CONTROLLER.ino

Definition at line 144 of file Board.h.

144 {
145 static bool lastButtonState = HIGH;
146 static unsigned long lastButtonPressTime = 0;
147 const unsigned long BUTTON_WAIT = 1000; // Wait time in milliseconds between button presses
148
149 bool currentButtonState = digitalRead(encSwPin); // Read the state of the encoder switch
150 unsigned long currentTime = millis(); // Get current time in milliseconds
151
152 if (currentButtonState == LOW && lastButtonState == HIGH) { // Button has just been pressed
153 if (currentTime - lastButtonPressTime < BUTTON_WAIT) { // Only process if 1 sec passed since last press
154 lastButtonState = currentButtonState;
155 return currentMode;
156 }
157 lastButtonPressTime = currentTime; // Update last press time
158 int previousMode = currentMode; // Store previous mode
159 currentMode = (currentMode % 3) + 1; // Cycle to next mode
160
161 if (currentMode == MODE_NORMAL) {
163 sendDcsBiosMessage("CONSOLES_DIMMER", String(dcs_brightness_console).c_str()); // Send DCS-BIOS message to reset console dimmer
164 sendDcsBiosMessage("INST_PNL_DIMMER", String(dcs_brightness_instrument).c_str()); // Send DCS-BIOS message to reset instrument lighting
165 sendDcsBiosMessage("FLOOD_DIMMER", String(dcs_brightness_flood).c_str()); // Send DCS-BIOS message to reset floodlights dimmer
166 }
167 if (currentMode == MODE_MANUAL) {
168 mode2_brightness = 64; // Reset to 25% brightness
169 fillSolid(NVIS_GREEN_A); // Apply the brightness immediately
170 }
171 if (currentMode == MODE_RAINBOW) {
172 mode3_brightness = 64; // Reset to 25% brightness
173 encoder->tick(); // Update encoder state
174 rotary_pos = encoder->getPosition(); // Sync encoder position to avoid false change detection
175 setAllLightsOff(); // Clear any previous state
176 }
177
178 lastButtonState = currentButtonState;
179 delay(10); // Small delay to debounce switch
180 } else {
181 lastButtonState = currentButtonState;
182 }
183 return currentMode;
184 }
void setAllLightsOff()
Turns off all lights in all channels and resets brightness state.
Definition Board.h:270
void fillSolid(const CRGB &color, int brightness=-1)
Fills all channels with a solid color.
Definition Board.h:257

References fillSolid(), and setAllLightsOff().

◆ processMode()

void Board::processMode ( )
inline

Processes the current mode.

See also
This method is called by loop() in 2A13-BACKLIGHT_CONTROLLER.ino

Definition at line 190 of file Board.h.

190 {
191 int newPos = 0;
192 switch(currentMode) {
193 case MODE_NORMAL: // MODE 1: LEDs controlled by DCS BIOS
194 {
195 DcsState currentDcsState = getDcsState();
196 if (currentDcsState == DcsState::EXITED && prevDcsState != DcsState::EXITED) {
197 setAllLightsOff(); // DCS just exited: turn off all lights
198 } else if (prevDcsState == DcsState::EXITED &&
199 currentDcsState != DcsState::EXITED &&
200 currentDcsState != DcsState::PAUSED) {
201 for (int i = 0; i < channelCount; i++) { // DCS became active again: restore last known brightness
202 channels[i]->updateInstrLights(dcs_brightness_instrument);
203 channels[i]->updateConsoleLights(dcs_brightness_console);
204 channels[i]->updateFloodLights(dcs_brightness_flood);
205 }
207 }
208 // PAUSED: do nothing - keep current light state
209 prevDcsState = currentDcsState;
210 DcsBios::loop();
211 }
212 break;
213 case MODE_MANUAL: // MODE 2: LEDs controlled manually through BKLT switch
214 encoder->tick();
215 newPos = encoder->getPosition();
216 if (newPos != rotary_pos) {
217 RotaryEncoder::Direction direction = encoder->getDirection();
218 if (direction == RotaryEncoder::Direction::CLOCKWISE) {
219 mode2_brightness = (mode2_brightness < 224) ? mode2_brightness + 32 : 255; // Add 32 or cap at 255
220 } else {
221 mode2_brightness = (mode2_brightness > 32) ? mode2_brightness - 32 : 0; // Subtract 32 or cap at 0
222 }
223 rotary_pos = newPos;
224 fillSolid(NVIS_GREEN_A);
225 }
226 break;
227 case MODE_RAINBOW: // MODE 3: Rainbow test mode
228 encoder->tick();
229 newPos = encoder->getPosition();
230 if (newPos != rotary_pos) {
231 RotaryEncoder::Direction direction = encoder->getDirection();
232 if (direction == RotaryEncoder::Direction::CLOCKWISE) {
233 mode3_brightness = (mode3_brightness < 224) ? mode3_brightness + 32 : 255; // Add 32 or cap at 255
234 } else {
235 mode3_brightness = (mode3_brightness > 32) ? mode3_brightness - 32 : 0; // Subtract 32 or cap at 0
236 }
237 rotary_pos = newPos;
238 }
239 for (int i = 0; i < channelCount; i++) {
240 fill_rainbow(channels[i]->getLeds(), channels[i]->getLedCount(), thisHue, deltaHue);
241 // Scale down brightness to reduce maximum brightness
242 nscale8_video(channels[i]->getLeds(), channels[i]->getLedCount(), mode3_brightness);
243 }
244 thisHue++; // Increment the hue for the next frame
246 break;
247 }
248 }
DcsState getDcsState()
Determine the current DCS connection state (heartbeat-only variant)
void updateInstrLights(uint16_t brightness, const CRGB &color=NVIS_GREEN_A)
Updates backlights for all panels in this channel.
Definition Channel.h:166
void updateConsoleLights(uint16_t brightness, const CRGB &color=NVIS_GREEN_A)
Updates console lights for all panels in this channel.
Definition Channel.h:180
void updateFloodLights(uint16_t brightness)
Updates flood lights for all panels in this channel.
Definition Channel.h:193

References fillSolid(), getDcsState(), LedUpdateState::getInstance(), setAllLightsOff(), LedUpdateState::setUpdateFlag(), Channel::updateConsoleLights(), Channel::updateFloodLights(), and Channel::updateInstrLights().

◆ fillSolid()

void Board::fillSolid ( const CRGB & color,
int brightness = -1 )
inline

Fills all channels with a solid color.

Parameters
colorThe color to fill with
brightnessOptional brightness value (0-255). If not provided, uses current brightness
See also
This method is called by handleModeChange() and processMode() in Board.h, conditionally in MODE_MANUAL case

Definition at line 257 of file Board.h.

257 { // Fill all channels with a solid color
258 int targetBrightness = (brightness >= 0) ? brightness : this->mode2_brightness;
259 for (int i = 0; i < channelCount; i++) {
260 channels[i]->updateInstrLights(map(targetBrightness, 0, 255, 0, 65535), color);
261 channels[i]->updateConsoleLights(map(targetBrightness, 0, 255, 0, 65535), color);
262 }
264 }

References LedUpdateState::getInstance(), LedUpdateState::setUpdateFlag(), Channel::updateConsoleLights(), and Channel::updateInstrLights().

Referenced by handleModeChange(), and processMode().

◆ setAllLightsOff()

void Board::setAllLightsOff ( )
inline

Turns off all lights in all channels and resets brightness state.

See also
This method is called by handleModeChange() in Board.h

Definition at line 270 of file Board.h.

270 { // Turn off all lights and reset brightness state
271 for (int i = 0; i < channelCount; i++) {
272 channels[i]->setAllLightsOff();
273 }
275 }
void setAllLightsOff()
Turns off all lights in all panels of this channel and resets brightness state.
Definition Channel.h:205

References LedUpdateState::getInstance(), Channel::setAllLightsOff(), and LedUpdateState::setUpdateFlag().

Referenced by handleModeChange(), and processMode().

◆ updateInstrumentLights()

void Board::updateInstrumentLights ( uint16_t newValue)
inline

Updates all channels with new instrument lighting value.

Parameters
newValueThe new brightness value
See also
This method is conditionally called by onInstrIntLtChange() in Board.h

Definition at line 282 of file Board.h.

282 {
283 dcs_brightness_instrument = newValue; // In any mode, store the DCS-BIOS brightness value
284 if (currentMode != MODE_NORMAL) return; // But only in normal mode, actually send update to channels
285 for (int i = 0; i < channelCount; i++) {
286 channels[i]->updateInstrLights(newValue);
287 }
289
290 }

References LedUpdateState::getInstance(), LedUpdateState::setUpdateFlag(), and Channel::updateInstrLights().

Referenced by onInstrIntLtChange().

◆ updateConsoleLights()

void Board::updateConsoleLights ( uint16_t newValue)
inline

Updates all channels with new console lighting value.

Parameters
newValueThe new brightness value
See also
This method is called by onConsolesDimmerChange() in Board.h

Definition at line 297 of file Board.h.

297 {
298 dcs_brightness_console = newValue; // In any mode, store the DCS-BIOS brightness value
299 if (currentMode != MODE_NORMAL) return; // But only in normal mode, actually send update to channels
300 for (int i = 0; i < channelCount; i++) {
301 channels[i]->updateConsoleLights(newValue);
302 }
304
305 }

References LedUpdateState::getInstance(), LedUpdateState::setUpdateFlag(), and Channel::updateConsoleLights().

Referenced by onConsolesDimmerChange().

◆ updateFloodLights()

void Board::updateFloodLights ( uint16_t newValue)
inline

Updates all channels with new flood lighting value.

Parameters
newValueThe new brightness value
See also
This method is called by onFloodDimmerChange() in Board.h

Definition at line 312 of file Board.h.

312 {
313 dcs_brightness_flood = newValue; // In any mode, store the DCS-BIOS brightness value
314 if (currentMode != MODE_NORMAL) return; // But only in normal mode, actually send update to channels
315 for (int i = 0; i < channelCount; i++) {
316 channels[i]->updateFloodLights(newValue);
317 }
319
320 }

References LedUpdateState::getInstance(), LedUpdateState::setUpdateFlag(), and Channel::updateFloodLights().

Referenced by onFloodDimmerChange().

◆ onInstrIntLtChange()

static void Board::onInstrIntLtChange ( unsigned int newValue)
inlinestatic

Callback for instrument lighting changes from DCS-BIOS.

Parameters
newValueThe new brightness value from DCS-BIOS
See also
This method is called by DCS-BIOS when instrument lighting changes

Definition at line 328 of file Board.h.

328 {
329 if (instance) instance->updateInstrumentLights(newValue);
330 }
void updateInstrumentLights(uint16_t newValue)
Updates all channels with new instrument lighting value.
Definition Board.h:282

References updateInstrumentLights().

◆ onConsolesDimmerChange()

static void Board::onConsolesDimmerChange ( unsigned int newValue)
inlinestatic

Callback for console dimmer changes from DCS-BIOS.

Parameters
newValueThe new brightness value from DCS-BIOS
See also
This method is called by DCS-BIOS when console dimmer changes

Definition at line 338 of file Board.h.

338 {
339 if (instance) instance->updateConsoleLights(newValue);
340 }
void updateConsoleLights(uint16_t newValue)
Updates all channels with new console lighting value.
Definition Board.h:297

References updateConsoleLights().

◆ onFloodDimmerChange()

static void Board::onFloodDimmerChange ( unsigned int newValue)
inlinestatic

Callback for flood lighting changes from DCS-BIOS.

Parameters
newValueThe new brightness value from DCS-BIOS
See also
This method is called by DCS-BIOS when flood lighting changes

Definition at line 348 of file Board.h.

348 {
349 if (instance) instance->updateFloodLights(newValue);
350 }
void updateFloodLights(uint16_t newValue)
Updates all channels with new flood lighting value.
Definition Board.h:312

References updateFloodLights().

Member Data Documentation

◆ instrIntLtBuffer

DcsBios::IntegerBuffer Board::instrIntLtBuffer {FA_18C_hornet_INSTR_INT_LT, onInstrIntLtChange}

Definition at line 331 of file Board.h.

331{FA_18C_hornet_INSTR_INT_LT, onInstrIntLtChange};
static void onInstrIntLtChange(unsigned int newValue)
Callback for instrument lighting changes from DCS-BIOS.
Definition Board.h:328

◆ consolesDimmerBuffer

DcsBios::IntegerBuffer Board::consolesDimmerBuffer {FA_18C_hornet_CONSOLES_DIMMER, onConsolesDimmerChange}

Definition at line 341 of file Board.h.

341{FA_18C_hornet_CONSOLES_DIMMER, onConsolesDimmerChange};
static void onConsolesDimmerChange(unsigned int newValue)
Callback for console dimmer changes from DCS-BIOS.
Definition Board.h:338

◆ floodDimmerBuffer

DcsBios::IntegerBuffer Board::floodDimmerBuffer {FA_18C_hornet_FLOOD_DIMMER, onFloodDimmerChange}

Definition at line 351 of file Board.h.

351{FA_18C_hornet_FLOOD_DIMMER, onFloodDimmerChange};
static void onFloodDimmerChange(unsigned int newValue)
Callback for flood lighting changes from DCS-BIOS.
Definition Board.h:348

The documentation for this class was generated from the following file: