Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit f7fdc36

Browse files
committed
Use standard LedControl library
1 parent 9797d3f commit f7fdc36

10 files changed

+348
-384
lines changed

config.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#elif defined(STM32)
1515

16-
#define USE_8_SEGMENT_DISPLAY true
16+
#define USE_7_SEGMENT_DISPLAY true
1717
#define USE_2_LINE_CHAR_DISPLAY false
1818
#define USE_4_LINE_CHAR_DISPLAY false
1919
#define USE_GRAPH_DISPLAY true
@@ -43,17 +43,17 @@
4343

4444
#elif defined(ARDUINO_AVR_NANO)
4545

46-
#define USE_8_SEGMENT_DISPLAY true
46+
#define USE_7_SEGMENT_DISPLAY true
4747
#define USE_2_LINE_CHAR_DISPLAY false
4848
#define USE_4_LINE_CHAR_DISPLAY false
4949
#define USE_GRAPH_DISPLAY false
5050

5151
#define USE_ETHERNET true
5252
#define RUNNING_ON_WIFI_ESP8266 false
5353

54-
const int ETHERNET_BUFFER_SIZE = 400;
54+
const int ETHERNET_BUFFER_SIZE = 500;
5555

56-
const int LAUNCH_RAM = 120;
56+
const int LAUNCH_RAM = 400;
5757

5858
const byte PIN_BUTTON_INTENSITY = 2;
5959
const byte PIN_BUTTON_MENU = 3;

digit_display.cpp

Lines changed: 0 additions & 103 deletions
This file was deleted.

digit_display.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

display_7segment.cpp

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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+

display_char.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "displays.h"
2+
3+
#ifdef X
4+
5+
#include <LiquidCrystal_I2C.h>
6+
LiquidCrystal_I2C charDisplay1(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
7+
LiquidCrystal_I2C charDisplay2(0x26, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
8+
9+
charDisplay1.begin(16,2);
10+
charDisplay1.backlight();
11+
charDisplay1.clear();
12+
13+
charDisplay2.begin(20,4);
14+
charDisplay2.backlight();
15+
charDisplay2.clear();
16+
17+
18+
19+
charDisplay1.setCursor(0, 1);
20+
charDisplay1.print(buf);
21+
22+
charDisplay2.setCursor(0, 1);
23+
charDisplay2.print(buf);
24+
25+
26+
charDisplay2.setCursor(0,2);
27+
charDisplay2.print(settings.launch.destination);
28+
29+
charDisplay2.setCursor(0,3);
30+
charDisplay2.print(settings.launch.payload);
31+
#endif
32+

0 commit comments

Comments
 (0)