|
| 1 | +#include "displays.h" |
| 2 | +#include "settings.h" |
| 3 | +#include "http.h" |
| 4 | + |
| 5 | +const static byte charTo7Segment [] PROGMEM = { |
| 6 | + B00000000,B00110000,B01101101,B01111001,B00110011,B01011011,B01011111,B01110000,// 0 |
| 7 | + B01111111,B01111011,B01110111,B00011111,B00001101,B00111101,B01001111,B01000111,// 8 |
| 8 | + B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,// 16 |
| 9 | + B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,// 24 |
| 10 | + B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,// 32 !"#$%&' |
| 11 | + B00000000,B00000000,B00000000,B00000000,B10000000,B00000001,B10000000,B00000000,// 40 ()*+,-./ |
| 12 | + B01111110,B00110000,B01101101,B01111001,B00110011,B01011011,B01011111,B01110000,// 48 01234567 |
| 13 | + B01111111,B01111011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,// 56 89:;<=>? |
| 14 | + B00000000,B01110111,B01111111,B01001110,B00111101,B01001111,B01000111,B01011110,// 64 @ABCDEFG |
| 15 | + B00110111,B00000110,B00111100,B01010111,B00001110,B01010100,B01110110,B01111110,// 72 HIJKLMNO |
| 16 | + B01100111,B01101011,B01100110,B01011011,B00001111,B00111110,B00111110,B00101010,// 80 PQRSTUVW |
| 17 | + B00110111,B00111011,B01101101,B00000000,B00000000,B00000000,B00000000,B00001000,// 88 XYZ[\]^_ |
| 18 | + B00000000,B01111101,B00011111,B00001101,B00111101,B01101111,B01000111,B01111011,// 96 'abcdefg |
| 19 | + B00010111,B00000100,B00011000,B01010111,B00000110,B00010100,B00010101,B00011101,// 104 hijklmno |
| 20 | + B01100111,B01110011,B00000101,B01011011,B00001111,B00011100,B00011100,B00010100,// 112 pqrstuvw |
| 21 | + B00110111,B00111011,B01101101,B00000000,B00000000,B00000000,B00000000,B00000000 // 120 xyz{|}~ |
| 22 | +}; |
| 23 | + |
| 24 | +void Rocket7SegmentDisplay::setup() { |
| 25 | + ledControl.shutdown(0, false); |
| 26 | + ledControl.setIntensity(0, 7); |
| 27 | + ledControl.clearDisplay(0); |
| 28 | +} |
| 29 | + |
| 30 | +void Rocket7SegmentDisplay::loop() { |
| 31 | + if (!show_launch) { |
| 32 | + |
| 33 | + write(data); |
| 34 | + |
| 35 | + } else { |
| 36 | + |
| 37 | + int32_t time = launch_at_seconds - settings.time_downloaded - (millis() - httpClient.info_downloaded_millis) / 1000; |
| 38 | + boolean negative = false; |
| 39 | + if (time < 0) { |
| 40 | + negative = true; |
| 41 | + time = -time; |
| 42 | + } |
| 43 | + |
| 44 | + uint32_t seconds = time % 60; |
| 45 | + uint32_t minutes = (time / 60) % 60; |
| 46 | + uint32_t hours = (time / 60 / 60) % 24; |
| 47 | + uint32_t days = (time / 60 / 60 / 24); |
| 48 | + |
| 49 | + if (settings.launch.time_status == 'T') { |
| 50 | + ledControl.setDigit(0, 0, seconds % 10, false); |
| 51 | + ledControl.setDigit(0, 1, seconds / 10, false); |
| 52 | + |
| 53 | + ledControl.setDigit(0, 2, minutes % 10, true); |
| 54 | + ledControl.setDigit(0, 3, minutes / 10, false); |
| 55 | + |
| 56 | + ledControl.setDigit(0, 4, hours % 10, true); |
| 57 | + ledControl.setDigit(0, 5, hours / 10, false); |
| 58 | + |
| 59 | + ledControl.setDigit(0, 6, days % 10, true); |
| 60 | + |
| 61 | + if (negative) { |
| 62 | + ledControl.setDigit(0, 7, '-', false); |
| 63 | + } else { |
| 64 | + ledControl.setDigit(0, 7, days / 10, false); |
| 65 | + } |
| 66 | + } else { |
| 67 | + //ledControl.setDigit(); |
| 68 | + //memcpy(data, F(" days"), 8); |
| 69 | + ledControl.setChar(0, 0, ' ', false); |
| 70 | + ledControl.setChar(0, 1, ' ', false); |
| 71 | + ledControl.setChar(0, 2, ' ', false); |
| 72 | + ledControl.setChar(0, 3, ' ', false); |
| 73 | + ledControl.setChar(0, 4, ' ', false); |
| 74 | + |
| 75 | + ledControl.setDigit(0, 5, days % 10, true); |
| 76 | + |
| 77 | + ledControl.setDigit(0, 6, (days / 10) % 10, false); |
| 78 | + ledControl.setDigit(0, 7, days / 100, false); |
| 79 | + |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +void Rocket7SegmentDisplay::setMessage(char* message8Chars) { |
| 85 | + show_launch = false; |
| 86 | + |
| 87 | + memcpy(data, message8Chars, 8); |
| 88 | + loop(); |
| 89 | +} |
| 90 | + |
| 91 | +void Rocket7SegmentDisplay::setMessage(const __FlashStringHelper *message8Chars) { |
| 92 | + show_launch = false; |
| 93 | + |
| 94 | + PGM_P p = reinterpret_cast<PGM_P>(message8Chars); |
| 95 | + for(int i=0; i<8; i++) { |
| 96 | + data[i] = pgm_read_byte_near(p++); |
| 97 | + } |
| 98 | + loop(); |
| 99 | +} |
| 100 | + |
| 101 | +void Rocket7SegmentDisplay::setLaunch(int32_t launch_at_seconds, char* name8Chars) { |
| 102 | + show_launch = true; |
| 103 | + |
| 104 | + this->launch_at_seconds = launch_at_seconds; |
| 105 | + memcpy(data, name8Chars, 8); |
| 106 | +} |
| 107 | + |
| 108 | +void Rocket7SegmentDisplay::write(char* message8Chars) { |
| 109 | + for(int i = 0; i < 8; i++) { |
| 110 | + uint8_t b = 0; |
| 111 | + |
| 112 | + char chr = message8Chars[i]; |
| 113 | + if (chr >> 7) { |
| 114 | + chr &= 0x7F; |
| 115 | + b = 0x80; |
| 116 | + } |
| 117 | + b |= pgm_read_byte_near(charTo7Segment + chr); |
| 118 | + ledControl.setRow(0, 7-i, b); |
| 119 | + } |
| 120 | + |
| 121 | +} |
| 122 | + |
0 commit comments