|
22 | 22 | //////////////////////////////////////////////////////////////////////////////////////// |
23 | 23 |
|
24 | 24 | inline constexpr uint8_t noOfDigitLocations{ 4 }; |
25 | | -inline constexpr uint8_t noOfPossibleCharacters{ 11 }; |
| 25 | +inline constexpr uint8_t noOfPossibleCharacters{ 14 }; |
26 | 26 | inline constexpr uint8_t UPDATE_PERIOD_FOR_DISPLAYED_DATA{ 50 }; // mains cycles |
27 | 27 | inline constexpr uint8_t DISPLAY_SHUTDOWN_IN_HOURS{ 8 }; // auto-reset after this period of inactivity |
28 | 28 |
|
29 | | -inline constexpr uint32_t displayShutdown_inMainsCycles{DISPLAY_SHUTDOWN_IN_HOURS * mainsCyclesPerHour }; |
| 29 | +inline constexpr uint32_t displayShutdown_inMainsCycles{ DISPLAY_SHUTDOWN_IN_HOURS * mainsCyclesPerHour }; |
30 | 30 | inline constexpr uint8_t MAX_DISPLAY_TIME_COUNT{ 10 }; // no of processing loops between display updates |
31 | 31 |
|
32 | 32 | inline uint8_t charsForDisplay[noOfDigitLocations]{ 20, 20, 20, 20 }; // all blank |
@@ -71,6 +71,9 @@ inline constexpr uint8_t digitValueMap[noOfPossibleCharacters][noOfDigitSelectio |
71 | 71 | HIGH, LOW, LOW, LOW, // '8' <- element 8 |
72 | 72 | HIGH, LOW, LOW, HIGH, // '9' <- element 9 |
73 | 73 | HIGH, HIGH, HIGH, HIGH, // ' ' <- element 10 |
| 74 | + LOW, HIGH, HIGH, HIGH, // 'F' <- element 11 |
| 75 | + HIGH, LOW, HIGH, LOW, // 'r' <- element 12 |
| 76 | + LOW, LOW, HIGH, LOW, // 'C' <- element 13 |
74 | 77 | }; |
75 | 78 |
|
76 | 79 | // a tidy means of identifying the DP status data when accessing the above table |
@@ -213,6 +216,9 @@ inline constexpr uint8_t segMap[noOfPossibleCharacters][noOfSegmentsPerDigit - 1 |
213 | 216 | ON, ON, ON, ON, ON, ON, ON, // '8' <- element 8 |
214 | 217 | ON, ON, ON, ON, OFF, ON, ON, // '9' <- element 9 |
215 | 218 | OFF, OFF, OFF, OFF, OFF, OFF, OFF, // ' ' <- element 10 |
| 219 | + ON, OFF, OFF, ON, ON, ON, ON, // 'F' <- element 11 |
| 220 | + OFF, OFF, OFF, OFF, ON, OFF, ON, // 'r' <- element 12 |
| 221 | + ON, OFF, OFF, ON, ON, ON, OFF, // 'C' <- element 13 |
216 | 222 | }; |
217 | 223 |
|
218 | 224 | /** |
@@ -332,33 +338,100 @@ inline void initializeDisplay() |
332 | 338 | } |
333 | 339 | } |
334 | 340 |
|
| 341 | +/** |
| 342 | + * @brief Displays "OFF" on the 7-segment display. |
| 343 | + * |
| 344 | + * @details This function configures the display to show "OFF" when diversion is disabled. |
| 345 | + * It displays the text right-aligned on the 4-digit display. |
| 346 | + * Uses the existing '0' character definition for 'O' to save memory. |
| 347 | + * |
| 348 | + * @ingroup 7SegDisplay |
| 349 | + */ |
| 350 | +inline void displayOff() |
| 351 | +{ |
| 352 | + if constexpr (!(TYPE_OF_DISPLAY == DisplayType::SEG || TYPE_OF_DISPLAY == DisplayType::SEG_HW)) |
| 353 | + { |
| 354 | + return; |
| 355 | + } |
| 356 | + |
| 357 | + // Set display to " OFF" (right-aligned) |
| 358 | + charsForDisplay[0] = 10; // Blank |
| 359 | + charsForDisplay[1] = 0; // 'O' (reusing '0' character) |
| 360 | + charsForDisplay[2] = 12; // 'F' |
| 361 | + charsForDisplay[3] = 12; // 'F' |
| 362 | +} |
| 363 | + |
| 364 | +/** |
| 365 | + * @brief Displays "FORC" on the 7-segment display for forced load override. |
| 366 | + * |
| 367 | + * @details This function configures the display to show "FORC" when a load is overridden. |
| 368 | + * Uses the existing '0' character definition for 'O' to save memory. |
| 369 | + * |
| 370 | + * @ingroup 7SegDisplay |
| 371 | + */ |
| 372 | +inline void displayForced() |
| 373 | +{ |
| 374 | + if constexpr (!(TYPE_OF_DISPLAY == DisplayType::SEG || TYPE_OF_DISPLAY == DisplayType::SEG_HW)) |
| 375 | + { |
| 376 | + return; |
| 377 | + } |
| 378 | + |
| 379 | + // Set display to "FORC" |
| 380 | + charsForDisplay[0] = 11; // 'F' |
| 381 | + charsForDisplay[1] = 0; // 'O' (reusing '0' character) |
| 382 | + charsForDisplay[2] = 12; // 'r' |
| 383 | + charsForDisplay[3] = 13; // 'C' |
| 384 | +} |
| 385 | + |
335 | 386 | /** |
336 | 387 | * @brief Configures the value for display on a 7-segment display. |
337 | 388 | * |
338 | | - * This function configures the value to be displayed on a 7-segment display. |
339 | | - * It handles both active energy display and a "walking dots" display when the |
340 | | - * energy display is not active. |
| 389 | + * @details This function controls what is shown on the 7-segment display based on |
| 390 | + * the system state. It handles multiple display modes: |
| 391 | + * - "FORC" when a load is in forced override mode |
| 392 | + * - "OFF" when diversion is disabled |
| 393 | + * - "Walking dots" when energy display is not active |
| 394 | + * - Energy values with appropriate decimal point placement |
341 | 395 | * |
342 | 396 | * @param _EDD_isActive A boolean indicating whether the energy display is active. |
343 | | - * @param _ValueToDisplay The value to be displayed, represented as a 16-bit unsigned integer. |
| 397 | + * @param _ValueToDisplay The energy value to be displayed (16-bit unsigned integer). |
| 398 | + * @param _diversionEnabled A boolean indicating if diversion is enabled (default=true). |
| 399 | + * @param _loadForced A boolean indicating if a load is in forced override mode (default=false). |
344 | 400 | * |
345 | | - * When the energy display is active, the function scales the value appropriately |
346 | | - * and assigns digits to the display characters. If the value exceeds 10,000, it |
347 | | - * is rescaled to fit within the display's constraints. The decimal point is placed |
348 | | - * after the first or second digit based on the value. |
| 401 | + * Display precedence order: |
| 402 | + * 1. Forced load status (shows "FOrC") |
| 403 | + * 2. Diversion enabled status (shows "OFF") |
| 404 | + * 3. Energy display inactive (shows walking dots) |
| 405 | + * 4. Energy value display |
349 | 406 | * |
350 | | - * When the energy display is not active, the function displays a "walking dots" |
351 | | - * pattern by cycling a dot through the display positions. |
| 407 | + * For energy value display: |
| 408 | + * - Values up to 9999 show with decimal point after first digit (e.g., 1.234) |
| 409 | + * - Values above 9999 are divided by 10 and shown with decimal point after second digit (e.g., 12.34) |
352 | 410 | * |
353 | 411 | * @ingroup 7SegDisplay |
354 | 412 | */ |
355 | | -inline void configureValueForDisplay(const bool _EDD_isActive, const uint16_t _ValueToDisplay) |
| 413 | +inline void configureValueForDisplay(const bool _EDD_isActive, const uint16_t _ValueToDisplay, const bool _diversionEnabled = false, |
| 414 | + const bool _loadForced = false) |
356 | 415 | { |
357 | 416 | if constexpr (!(TYPE_OF_DISPLAY == DisplayType::SEG || TYPE_OF_DISPLAY == DisplayType::SEG_HW)) |
358 | 417 | { |
359 | 418 | return; |
360 | 419 | } |
361 | 420 |
|
| 421 | + // Check for forced load first |
| 422 | + if (_loadForced) |
| 423 | + { |
| 424 | + displayForced(); |
| 425 | + return; |
| 426 | + } |
| 427 | + |
| 428 | + // If diversion is disabled, show "OFF" |
| 429 | + if (!_diversionEnabled) |
| 430 | + { |
| 431 | + displayOff(); |
| 432 | + return; |
| 433 | + } |
| 434 | + |
362 | 435 | if (!_EDD_isActive) |
363 | 436 | { |
364 | 437 | static uint8_t locationOfDot{ 0 }; |
|
0 commit comments