| 657 | } |
| 658 | |
| 659 | int timePrompt(int defaultTime) { |
| 660 | uint8_t digits[4] = {0,0,0,0}; |
| 661 | ulong currentIndex = 0; |
| 662 | |
| 663 | // If a valid time is passed (e.g., 1430), extract it into the digits array |
| 664 | if (defaultTime >= 0 && defaultTime <= 2359) { |
| 665 | digits[0] = (defaultTime / 1000) % 10; |
| 666 | digits[1] = (defaultTime / 100) % 10; |
| 667 | digits[2] = (defaultTime / 10) % 10; |
| 668 | digits[3] = defaultTime % 10; |
| 669 | } |
| 670 | |
| 671 | // X coordinates for the 4 digits (HHMM) |
| 672 | const int tX[4] = {93, 110, 131, 148}; |
| 673 | |
| 674 | for (;;) { |
| 675 | #if !OTA_APP |
| 676 | if (!noTimeout) checkTimeout(); |
| 677 | if (DEBUG_VERBOSE) printDebug(); |
| 678 | #endif |
| 679 | |
| 680 | // Update scroll |
| 681 | int scrollVec = TOUCH().getScrollVector(); |
| 682 | if (scrollVec != 0) { |
| 683 | |
| 684 | if (currentIndex == 0) { |
| 685 | // Isolate the Tens of Hours digit to prevent base-24 modulo bleeding |
| 686 | int d0 = digits[0] + scrollVec; |
| 687 | if (d0 > 2) d0 = 0; |
| 688 | if (d0 < 0) d0 = 2; |
| 689 | digits[0] = d0; |
| 690 | |
| 691 | // Reverse Clamp: If we wrapped to 2, ensure the hours digit isn't sitting at 4-9 |
| 692 | if (digits[0] == 2 && digits[1] > 3) { |
| 693 | digits[1] = 3; |
| 694 | } |
| 695 | } else { |
| 696 | // Convert current digits to total minutes for smooth carry-over |
| 697 | int total_mins = (digits[0] * 10 + digits[1]) * 60 + (digits[2] * 10 + digits[3]); |
| 698 | |
| 699 | // Apply the scroll vector based on cursor position |
| 700 | switch (currentIndex) { |
| 701 | case 1: total_mins += scrollVec * 60; break; // +/- 1 hour |
| 702 | case 2: total_mins += scrollVec * 10; break; // +/- 10 minutes |
| 703 | case 3: total_mins += scrollVec * 1; break; // +/- 1 minute |
| 704 | } |
| 705 | |
| 706 | // Wrap-around logic for 24-hour format (1440 minutes in a day) |
| 707 | total_mins = total_mins % 1440; |
| 708 | if (total_mins < 0) { |
| 709 | total_mins += 1440; // Wrap backwards (e.g. 00:00 - 1 min = 23:59) |
| 710 | } |
| 711 | |
| 712 | // Convert total minutes back to individual digits |
| 713 | int h = total_mins / 60; |
| 714 | int m = total_mins % 60; |
| 715 | |
| 716 | digits[0] = h / 10; |
no test coverage detected