Commit d155657d29ae12c36bf7df4832c2b9abd3778af8
1 parent
78a12192
Exists in
master
and in
1 other branch
Moving LCD
Showing
3 changed files
with
332 additions
and
238 deletions
Show diff stats
ino/lib/LCD/LCD.cpp
1 | 1 | #include "LCD.h" |
2 | 2 | |
3 | 3 | LCD::LCD() { |
4 | - lcd_addr = LCD_DEFAULT_ADDRESS >> 1; | |
5 | - Wire.begin(); | |
4 | + lcd_addr = LCD_DEFAULT_ADDRESS >> 1; | |
5 | + rowpos = 0; | |
6 | + set_timeout(1); | |
7 | + for(uint8_t i = 0; i < LCD_HEIGHT; ++i) { | |
8 | + for(uint8_t j = 0; j < LCD_ROW_SIZE; ++j) { | |
9 | + rows[i][j] = ' '; | |
10 | + } | |
11 | + } | |
12 | + Wire.begin(); | |
6 | 13 | } |
7 | 14 | |
8 | 15 | LCD::LCD(byte lcd_addr) { |
9 | - this->lcd_addr = lcd_addr >> 1; | |
10 | - Wire.begin(); | |
16 | + this->lcd_addr = lcd_addr >> 1; | |
17 | + Wire.begin(); | |
11 | 18 | } |
12 | 19 | |
13 | 20 | bool LCD::is_alive() { |
14 | - Wire.beginTransmission(lcd_addr); | |
15 | - return Wire.endTransmission() == 0; | |
21 | + Wire.beginTransmission(lcd_addr); | |
22 | + return Wire.endTransmission() == 0; | |
16 | 23 | } |
17 | 24 | |
18 | 25 | void LCD::command(byte cmd) { |
19 | - Wire.write(LCD_COMMAND); | |
20 | - Wire.write(cmd); | |
26 | + Wire.write(LCD_COMMAND); | |
27 | + Wire.write(cmd); | |
21 | 28 | } |
22 | 29 | |
23 | 30 | void LCD::backlight(bool state) { |
24 | - Wire.beginTransmission(lcd_addr); | |
25 | - if (state) { | |
26 | - command(LCD_BACKLIGHT_ON); | |
27 | - } else { | |
28 | - command(LCD_BACKLIGHT_OFF); | |
29 | - } | |
30 | - Wire.endTransmission(); | |
31 | + Wire.beginTransmission(lcd_addr); | |
32 | + if (state) { | |
33 | + command(LCD_BACKLIGHT_ON); | |
34 | + } else { | |
35 | + command(LCD_BACKLIGHT_OFF); | |
36 | + } | |
37 | + Wire.endTransmission(); | |
31 | 38 | } |
32 | 39 | |
33 | 40 | void LCD::set_type(byte type) { |
34 | - Wire.beginTransmission(lcd_addr); | |
35 | - command(LCD_SET_DISPLAY_TYPE); | |
36 | - Wire.write(type); | |
37 | - Wire.endTransmission(); | |
41 | + Wire.beginTransmission(lcd_addr); | |
42 | + command(LCD_SET_DISPLAY_TYPE); | |
43 | + Wire.write(type); | |
44 | + Wire.endTransmission(); | |
38 | 45 | } |
39 | 46 | |
40 | 47 | void LCD::change_address(byte addr) { |
41 | - Wire.beginTransmission(lcd_addr); | |
42 | - command(LCD_CHANGE_ADDRESS); | |
43 | - command(LCD_CHANGE_ADDRESS_1); | |
44 | - command(LCD_CHANGE_ADDRESS_2); | |
45 | - command(LCD_CHANGE_ADDRESS_3); | |
46 | - Wire.write(addr); | |
47 | - Wire.endTransmission(); | |
48 | - | |
49 | - lcd_addr = addr; | |
48 | + Wire.beginTransmission(lcd_addr); | |
49 | + command(LCD_CHANGE_ADDRESS); | |
50 | + command(LCD_CHANGE_ADDRESS_1); | |
51 | + command(LCD_CHANGE_ADDRESS_2); | |
52 | + command(LCD_CHANGE_ADDRESS_3); | |
53 | + Wire.write(addr); | |
54 | + Wire.endTransmission(); | |
55 | + | |
56 | + lcd_addr = addr; | |
50 | 57 | } |
51 | 58 | |
52 | 59 | void LCD::print(char *string) { |
53 | - Wire.beginTransmission(lcd_addr); | |
54 | - Wire.write(LCD_COMMAND); | |
55 | - uint8_t length = strlen(string); | |
56 | - for (int i = 0; i < length; i++) { | |
57 | - Wire.write(*string++); | |
58 | - } | |
59 | - Wire.endTransmission(); | |
60 | + Wire.beginTransmission(lcd_addr); | |
61 | + Wire.write(LCD_COMMAND); | |
62 | + uint8_t length = strlen(string); | |
63 | + for (int i = 0; i < length; i++) { | |
64 | + Wire.write(*string++); | |
65 | + } | |
66 | + Wire.endTransmission(); | |
60 | 67 | } |
61 | 68 | |
62 | 69 | void LCD::clear_screen() { |
63 | - Wire.beginTransmission(lcd_addr); | |
64 | - command(LCD_CLEAR_SCREEN); | |
65 | - Wire.endTransmission(); | |
70 | + Wire.beginTransmission(lcd_addr); | |
71 | + command(LCD_CLEAR_SCREEN); | |
72 | + Wire.endTransmission(); | |
66 | 73 | } |
67 | 74 | |
68 | 75 | void LCD::cursor_home() { |
69 | - Wire.beginTransmission(lcd_addr); | |
70 | - command(LCD_CURSOR_HOME); | |
71 | - Wire.endTransmission(); | |
76 | + Wire.beginTransmission(lcd_addr); | |
77 | + command(LCD_CURSOR_HOME); | |
78 | + Wire.endTransmission(); | |
72 | 79 | } |
73 | 80 | |
74 | 81 | void LCD::set_cursor(byte x, byte y) { |
75 | - Wire.beginTransmission(lcd_addr); | |
76 | - command(LCD_SET_CURSOR_COORDS); | |
77 | - Wire.write(y); | |
78 | - Wire.write(x); | |
79 | - Wire.endTransmission(); | |
82 | + Wire.beginTransmission(lcd_addr); | |
83 | + command(LCD_SET_CURSOR_COORDS); | |
84 | + Wire.write(y); | |
85 | + Wire.write(x); | |
86 | + Wire.endTransmission(); | |
80 | 87 | } |
81 | 88 | |
82 | 89 | void LCD::hide_cursor() { |
83 | - Wire.beginTransmission(lcd_addr); | |
84 | - command(LCD_HIDE_CURSOR); | |
85 | - Wire.endTransmission(); | |
90 | + Wire.beginTransmission(lcd_addr); | |
91 | + command(LCD_HIDE_CURSOR); | |
92 | + Wire.endTransmission(); | |
86 | 93 | } |
87 | 94 | |
88 | 95 | void LCD::underline_cursor() { |
89 | - Wire.beginTransmission(lcd_addr); | |
90 | - command(LCD_SHOW_UNDERLINE_CURSOR); | |
91 | - Wire.endTransmission(); | |
96 | + Wire.beginTransmission(lcd_addr); | |
97 | + command(LCD_SHOW_UNDERLINE_CURSOR); | |
98 | + Wire.endTransmission(); | |
92 | 99 | } |
93 | 100 | |
94 | 101 | void LCD::blink_cursor() { |
95 | - Wire.beginTransmission(lcd_addr); | |
96 | - command(LCD_SHOW_BLINKING_CURSOR); | |
97 | - Wire.endTransmission(); | |
102 | + Wire.beginTransmission(lcd_addr); | |
103 | + command(LCD_SHOW_BLINKING_CURSOR); | |
104 | + Wire.endTransmission(); | |
98 | 105 | } |
99 | 106 | |
100 | 107 | void LCD::backspace() { |
101 | - Wire.beginTransmission(lcd_addr); | |
102 | - command(LCD_BACKSPACE); | |
103 | - Wire.endTransmission(); | |
108 | + Wire.beginTransmission(lcd_addr); | |
109 | + command(LCD_BACKSPACE); | |
110 | + Wire.endTransmission(); | |
111 | +} | |
112 | + | |
113 | +void LCD::set_timeout(uint8_t ticks) { | |
114 | + tick_ovf = ticks; | |
115 | + // Force next update | |
116 | + tick_cnt = ticks; | |
117 | +} | |
118 | + | |
119 | +void LCD::row(uint8_t idx, const char *str, uint8_t len, uint8_t pos) { | |
120 | + // Trim extra chars | |
121 | + if(len > LCD_ROW_SIZE) { | |
122 | + len = LCD_ROW_SIZE; | |
123 | + } | |
124 | + int ovf = len + pos - LCD_ROW_SIZE; | |
125 | + if(ovf > 0) { | |
126 | + // Copy overflow first | |
127 | + len -= ovf; | |
128 | + memcpy(rows[idx], &str[len], ovf); | |
129 | + } | |
130 | + memcpy(&rows[idx][pos], str, len); | |
131 | +} | |
132 | + | |
133 | +bool LCD::tick() { | |
134 | + // Check Timeout | |
135 | + if(++tick_cnt < tick_ovf) { | |
136 | + return false; | |
137 | + } | |
138 | + tick_cnt = 0; | |
139 | + | |
140 | + clear_screen(); | |
141 | + print_frame(); | |
142 | + | |
143 | + if(++rowpos == LCD_ROW_SIZE) { | |
144 | + rowpos = 0; | |
145 | + return true; | |
146 | + } | |
147 | + return false; | |
104 | 148 | } |
105 | 149 | |
150 | +void LCD::print_frame() { | |
151 | + for(uint8_t i = 0; i < LCD_HEIGHT; ++i) { | |
152 | + set_cursor(1, i+1); | |
153 | + Wire.beginTransmission(lcd_addr); | |
154 | + Wire.write(LCD_COMMAND); | |
155 | + uint8_t towrite = LCD_ROW_SIZE - rowpos; | |
156 | + if(towrite < LCD_WIDTH) { | |
157 | + // Leftovers | |
158 | + Wire.write(&rows[i][rowpos], towrite); | |
159 | + Wire.write(rows[i], LCD_WIDTH - towrite); | |
160 | + } else { | |
161 | + // No leftovers | |
162 | + Wire.write(&rows[i][rowpos], LCD_WIDTH); | |
163 | + } | |
164 | + Wire.endTransmission(); | |
165 | + } | |
166 | +} | ... | ... |
ino/lib/LCD/LCD.h
... | ... | @@ -45,6 +45,10 @@ |
45 | 45 | #define LCD_DEFAULT_ADDRESS byte(0xC6) |
46 | 46 | #define LCD_MAX_CHANCE 500 |
47 | 47 | |
48 | +#define LCD_ROW_SIZE 32 | |
49 | +#define LCD_WIDTH 16 | |
50 | +#define LCD_HEIGHT 2 | |
51 | + | |
48 | 52 | class LCD { |
49 | 53 | public: |
50 | 54 | static const byte GLCD_20X4 = 3; |
... | ... | @@ -67,7 +71,18 @@ class LCD { |
67 | 71 | void blink_cursor(); |
68 | 72 | void underline_cursor(); |
69 | 73 | void backspace(); |
74 | + | |
75 | + void set_timeout(uint8_t ticks); | |
76 | + void print_frame(); | |
77 | + void row(uint8_t idx, const char *str, uint8_t len, uint8_t pos = 0); | |
78 | + // true if frame finishes | |
79 | + bool tick(); | |
70 | 80 | private: |
81 | + char rows[LCD_HEIGHT][LCD_ROW_SIZE]; | |
82 | + uint8_t tick_cnt; | |
83 | + uint8_t tick_ovf; | |
84 | + uint8_t rowpos; | |
85 | + | |
71 | 86 | uint8_t lcd_addr; |
72 | 87 | |
73 | 88 | void command(byte cmd); | ... | ... |
ino/src/sketch.ino
... | ... | @@ -13,7 +13,7 @@ uint8_t last_second = 0; |
13 | 13 | // LCD stuff |
14 | 14 | |
15 | 15 | LCD lcd; |
16 | -char ino_alias[16]; | |
16 | +char ino_alias[17] = "Waiting Waiting "; | |
17 | 17 | uint8_t lcd_swap = 0; |
18 | 18 | |
19 | 19 | // ADC stuff |
... | ... | @@ -28,251 +28,269 @@ volatile bool transfer_active = false; |
28 | 28 | volatile bool transfer_ready = false; |
29 | 29 | |
30 | 30 | struct time_formated { |
31 | - uint8_t seconds, minutes, hours, day, month, year; | |
31 | + uint8_t seconds, minutes, hours, day, month, year; | |
32 | 32 | }; |
33 | 33 | |
34 | 34 | // ISR routines |
35 | 35 | |
36 | 36 | ISR(ADC_vect) { |
37 | - buffer[index++] = ADCH; | |
37 | + buffer[index++] = ADCH; | |
38 | 38 | |
39 | - if (index == 0) { | |
40 | - buffer = (buffer == frame_1)? frame_2 : frame_1; | |
41 | - pc_buffer = (buffer == frame_1)? frame_2 : frame_1; | |
39 | + if (index == 0) { | |
40 | + buffer = (buffer == frame_1)? frame_2 : frame_1; | |
41 | + pc_buffer = (buffer == frame_1)? frame_2 : frame_1; | |
42 | 42 | |
43 | - // will this double buffer system be enough?... | |
44 | - // if transfer = true => not enough!... | |
45 | - // we could disable interrupts while send_data...? | |
43 | + // will this double buffer system be enough?... | |
44 | + // if transfer = true => not enough!... | |
45 | + // we could disable interrupts while send_data...? | |
46 | 46 | |
47 | - transfer_ready = true; | |
48 | - } | |
47 | + transfer_ready = true; | |
48 | + } | |
49 | 49 | } |
50 | 50 | |
51 | 51 | ISR(TIMER1_COMPA_vect) { |
52 | - TCNT1 = 0; // we won't lose ticks | |
53 | - timestamp++; // inc. 1 sec | |
52 | + TCNT1 = 0; // we won't lose ticks | |
53 | + timestamp++; // inc. 1 sec | |
54 | 54 | } |
55 | 55 | |
56 | 56 | // Procedures && functions |
57 | 57 | |
58 | 58 | void getTimeFormated(struct time_formated &tf) { |
59 | - // Modified version from <Time.h> | |
60 | - | |
61 | - uint8_t year = 0; | |
62 | - uint8_t month = 0; | |
63 | - uint8_t monthLength = 0; | |
64 | - uint32_t time; | |
65 | - unsigned long days = 0; | |
66 | - uint8_t monthDays[] = {31,28,31,30,31,30,31,31,30,31,30,31}; | |
67 | - | |
68 | - time = (uint32_t) timestamp; | |
69 | - tf.seconds = time % 60; | |
70 | - time /= 60; // minutes | |
71 | - tf.minutes = time % 60; | |
72 | - time /= 60; // hours | |
73 | - tf.hours = time % 24; | |
74 | - time /= 24; // days | |
75 | - | |
76 | - while ((unsigned)(days += (LEAP_YEAR(year) ? 366 : 365)) <= time) { | |
77 | - year++; | |
59 | + // Modified version from <Time.h> | |
60 | + | |
61 | + uint8_t year = 0; | |
62 | + uint8_t month = 0; | |
63 | + uint8_t monthLength = 0; | |
64 | + uint32_t time; | |
65 | + unsigned long days = 0; | |
66 | + uint8_t monthDays[] = {31,28,31,30,31,30,31,31,30,31,30,31}; | |
67 | + | |
68 | + time = (uint32_t) timestamp; | |
69 | + tf.seconds = time % 60; | |
70 | + time /= 60; // minutes | |
71 | + tf.minutes = time % 60; | |
72 | + time /= 60; // hours | |
73 | + tf.hours = time % 24; | |
74 | + time /= 24; // days | |
75 | + | |
76 | + while ((unsigned)(days += (LEAP_YEAR(year) ? 366 : 365)) <= time) { | |
77 | + year++; | |
78 | + } | |
79 | + | |
80 | + tf.year = year; | |
81 | + | |
82 | + days -= LEAP_YEAR(year) ? 366 : 365; | |
83 | + time -= days; // days in current year | |
84 | + days = 0; | |
85 | + | |
86 | + for (month = 0; month < 12; month++) { | |
87 | + if (month == 1) { // february | |
88 | + if (LEAP_YEAR(year)) { | |
89 | + monthLength = 29; | |
90 | + } else { | |
91 | + monthLength = 28; | |
92 | + } | |
93 | + } else { | |
94 | + monthLength = monthDays[month]; | |
78 | 95 | } |
79 | - | |
80 | - tf.year = year; | |
81 | - | |
82 | - days -= LEAP_YEAR(year) ? 366 : 365; | |
83 | - time -= days; // days in current year | |
84 | - days = 0; | |
85 | - | |
86 | - for (month = 0; month < 12; month++) { | |
87 | - if (month == 1) { // february | |
88 | - if (LEAP_YEAR(year)) { | |
89 | - monthLength = 29; | |
90 | - } else { | |
91 | - monthLength = 28; | |
92 | - } | |
93 | - } else { | |
94 | - monthLength = monthDays[month]; | |
95 | - } | |
96 | 96 | |
97 | - if (time >= monthLength) { | |
98 | - time -= monthLength; | |
99 | - } else { | |
100 | - break; | |
101 | - } | |
97 | + if (time >= monthLength) { | |
98 | + time -= monthLength; | |
99 | + } else { | |
100 | + break; | |
102 | 101 | } |
102 | + } | |
103 | 103 | |
104 | - tf.month = month + 1; | |
105 | - tf.day = time + 1; | |
104 | + tf.month = month + 1; | |
105 | + tf.day = time + 1; | |
106 | 106 | } |
107 | 107 | |
108 | -void send_data() { | |
109 | - if (transfer_active && transfer_ready) { | |
110 | - Serial.write(HW_NEW_FRAME); | |
111 | - | |
112 | - for (int i = 0; i < SIZE; i++) { | |
113 | - Serial.write(pc_buffer[i]); | |
114 | - } | |
108 | +void process_frame() { | |
109 | + if (transfer_active && transfer_ready) { | |
110 | + // We can send a new Frame | |
111 | + Serial.write(HW_NEW_FRAME); | |
115 | 112 | |
116 | - transfer_ready = false; | |
113 | + for (int i = 0; i < SIZE; i++) { | |
114 | + Serial.write(pc_buffer[i]); | |
117 | 115 | } |
116 | + | |
117 | + transfer_ready = false; | |
118 | + } | |
118 | 119 | } |
119 | 120 | |
120 | 121 | void print_time_lcd() { |
121 | - struct time_formated tf; | |
122 | - getTimeFormated(tf); | |
123 | - | |
124 | - bool alias_turn; | |
125 | - char buffer[4]; | |
126 | - lcd.clear_screen(); | |
127 | - | |
128 | - if (++lcd_swap >= 10) { | |
129 | - lcd_swap = 0; | |
130 | - } | |
122 | + struct time_formated tf; | |
123 | + getTimeFormated(tf); | |
124 | + | |
125 | + bool alias_turn; | |
126 | + char buffer[4]; | |
127 | + lcd.clear_screen(); | |
128 | + | |
129 | + if (++lcd_swap >= 10) { | |
130 | + lcd_swap = 0; | |
131 | + } | |
132 | + | |
133 | + if (lcd_swap < 5) { | |
134 | + lcd.print(ino_alias); | |
135 | + } else { | |
136 | + lcd.set_cursor(3,1); | |
137 | + sprintf(buffer, "%d", tf.day); | |
138 | + lcd.print(buffer); | |
139 | + lcd.print("/"); | |
140 | + sprintf(buffer, "%d", tf.month); | |
141 | + lcd.print(buffer); | |
142 | + lcd.print("/"); | |
143 | + sprintf(buffer, "%d", tf.year+1970); | |
144 | + lcd.print(buffer); | |
145 | + } | |
146 | + | |
147 | + lcd.set_cursor(5,2); | |
148 | + | |
149 | + sprintf(buffer, "%d", tf.hours); | |
150 | + if (strlen(buffer) < 2) lcd.print("0"); | |
151 | + lcd.print(buffer);lcd.print(":"); | |
152 | + sprintf(buffer, "%d", tf.minutes); | |
153 | + if (strlen(buffer) < 2) lcd.print("0"); | |
154 | + lcd.print(buffer);lcd.print(":"); | |
155 | + sprintf(buffer, "%d", tf.seconds); | |
156 | + if (strlen(buffer) < 2) lcd.print("0"); | |
157 | + lcd.print(buffer); | |
158 | +} | |
131 | 159 | |
132 | - if (lcd_swap < 5) { | |
133 | - lcd.print(ino_alias); | |
134 | - } else { | |
135 | - lcd.set_cursor(3,1); | |
136 | - sprintf(buffer, "%d", tf.day); | |
137 | - lcd.print(buffer); | |
138 | - lcd.print("/"); | |
139 | - sprintf(buffer, "%d", tf.month); | |
140 | - lcd.print(buffer); | |
141 | - lcd.print("/"); | |
142 | - sprintf(buffer, "%d", tf.year+1970); | |
143 | - lcd.print(buffer); | |
144 | - } | |
160 | +void update_time() { | |
161 | + struct time_formated tf; | |
162 | + char buf[32]; | |
163 | + getTimeFormated(tf); | |
145 | 164 | |
146 | - lcd.set_cursor(5,2); | |
165 | + uint8_t len = sprintf(buf, | |
166 | + "%d/%d/%d %s%d:%s%d:%s%d", | |
167 | + tf.day, tf.month, tf.year + 1970, | |
168 | + ((tf.hours < 10)?"0":""), tf.hours, | |
169 | + ((tf.minutes < 10)?"0":""), tf.minutes, | |
170 | + ((tf.seconds < 10)?"0":""), tf.seconds); | |
147 | 171 | |
148 | - sprintf(buffer, "%d", tf.hours); | |
149 | - if (strlen(buffer) < 2) lcd.print("0"); | |
150 | - lcd.print(buffer);lcd.print(":"); | |
151 | - sprintf(buffer, "%d", tf.minutes); | |
152 | - if (strlen(buffer) < 2) lcd.print("0"); | |
153 | - lcd.print(buffer);lcd.print(":"); | |
154 | - sprintf(buffer, "%d", tf.seconds); | |
155 | - if (strlen(buffer) < 2) lcd.print("0"); | |
156 | - lcd.print(buffer); | |
172 | + | |
173 | + lcd.row(1, buf, len, 4); | |
157 | 174 | } |
158 | 175 | |
159 | 176 | void hardware_setup() { |
160 | - // ADC - Max prescaler | |
161 | - | |
162 | - ADCSRA |= (0<<ADPS2) | (0<<ADPS1) | (1<<ADPS0) | (1<<ADATE) | (1<<ADEN) | (1<<ADIE); | |
163 | - ADMUX |= (1<<REFS0) | (1<<ADLAR); | |
164 | - ADMUX &= ~(1<<REFS1); | |
165 | - ADCSRB &= ~((1<<ADTS2) | (1<<ADTS1) | (1<<ADTS0)); | |
166 | - ADCSRA |= (1<<ADSC); | |
167 | - | |
168 | - // Timer 1 | |
169 | - | |
170 | - TCCR1A = 0; | |
171 | - TCCR1B = 0; // stop | |
172 | - TCNT1 = 0; | |
173 | - TIFR1 = 0; | |
174 | - OCR1A = ONE_SECOND_TCKS; | |
175 | - TIMSK1 = (1 << OCIE1A) | (1 << TOIE1); | |
176 | - TCCR1B = (1 << CS12) | (1 << CS10); | |
177 | + // ADC - Max prescaler | |
178 | + | |
179 | + ADCSRA |= (0<<ADPS2) | (0<<ADPS1) | (1<<ADPS0) | (1<<ADATE) | (1<<ADEN) | (1<<ADIE); | |
180 | + ADMUX |= (1<<REFS0) | (1<<ADLAR); | |
181 | + ADMUX &= ~(1<<REFS1); | |
182 | + ADCSRB &= ~((1<<ADTS2) | (1<<ADTS1) | (1<<ADTS0)); | |
183 | + ADCSRA |= (1<<ADSC); | |
184 | + | |
185 | + // Timer 1 | |
186 | + | |
187 | + TCCR1A = 0; | |
188 | + TCCR1B = 0; // stop | |
189 | + TCNT1 = 0; | |
190 | + TIFR1 = 0; | |
191 | + OCR1A = ONE_SECOND_TCKS; | |
192 | + TIMSK1 = (1 << OCIE1A) | (1 << TOIE1); | |
193 | + TCCR1B = (1 << CS12) | (1 << CS10); | |
177 | 194 | } |
178 | 195 | |
179 | 196 | // Main |
180 | 197 | |
181 | 198 | void setup() { |
182 | - ino_alias[0] = 'A'; | |
183 | - hardware_setup(); | |
184 | - Serial.begin(115200); | |
199 | + hardware_setup(); | |
200 | + Serial.begin(115200); | |
185 | 201 | |
186 | - timestamp = 1431447151; // testing purposes | |
202 | + timestamp = 1431447151; // testing purposes | |
187 | 203 | |
188 | - lcd.clear_screen(); | |
189 | - lcd.backlight(true); | |
204 | + lcd.clear_screen(); | |
205 | + lcd.backlight(true); | |
206 | + lcd.hide_cursor(); | |
190 | 207 | |
191 | - //Serial.write(HW_ACK); | |
192 | - Serial.write("HW"); | |
193 | - Serial.write(HW_INO_VERSION_MAJOR); | |
194 | - Serial.write(HW_INO_VERSION_MINOR); | |
208 | + char *wait = "Waiting Waiting"; | |
209 | + lcd.row(0, wait, strlen(wait)); | |
210 | + lcd.set_timeout(1); | |
211 | + | |
212 | + Serial.write("HW"); | |
213 | + Serial.write(HW_INO_VERSION_MAJOR); | |
214 | + Serial.write(HW_INO_VERSION_MINOR); | |
195 | 215 | } |
196 | 216 | |
197 | 217 | void loop() { |
198 | - send_data(); | |
199 | - | |
200 | - uint8_t current; | |
201 | - struct time_formated tf; | |
202 | - getTimeFormated(tf); | |
203 | - | |
204 | - if (current = tf.seconds, last_second != current) { | |
205 | - print_time_lcd(); | |
206 | - last_second = current; | |
207 | - } | |
208 | - | |
209 | - if (Serial.available() < 1) { | |
210 | - switch (Serial.read()) { | |
211 | - case HW_HELO: | |
218 | + //process_frame(); | |
219 | + | |
220 | + uint8_t current; | |
221 | + struct time_formated tf; | |
222 | + getTimeFormated(tf); | |
223 | + | |
224 | + if (current = tf.seconds, last_second != current) { | |
225 | + //print_time_lcd(); | |
226 | + update_time(); | |
227 | + lcd.tick(); | |
228 | + last_second = current; | |
229 | + } | |
230 | + | |
231 | + if (Serial.available() < 1) { | |
232 | + switch (Serial.read()) { | |
233 | + case HW_HELO: | |
212 | 234 | { |
213 | - while (Serial.available() < HW_HELO_SIZE); | |
214 | - | |
215 | - for (byte i = 0; i < HW_HELO_SIZE; i++) { | |
216 | - ino_alias[i] = Serial.read(); | |
217 | - } | |
235 | + while (Serial.available() < HW_HELO_SIZE); | |
218 | 236 | |
219 | - Serial.write(HW_ACK); | |
237 | + for (byte i = 0; i < HW_HELO_SIZE; i++) { | |
238 | + ino_alias[i] = Serial.read(); | |
239 | + } | |
220 | 240 | } |
221 | - case HW_SMPL_RATE: | |
241 | + case HW_SMPL_RATE: | |
222 | 242 | { |
223 | - // change register | |
224 | - | |
225 | - break; | |
243 | + // change register | |
244 | + break; | |
226 | 245 | } |
227 | - case HW_DTIME_GET: | |
246 | + case HW_DTIME_GET: | |
228 | 247 | { |
229 | - Serial.write(HW_ACK); | |
230 | - //Serial.write(×tamp, sizeof(uint32_t)); | |
248 | + //TODO Not used | |
249 | + // Serial.write(HW_ACK); | |
250 | + // Serial.write(×tamp, sizeof(uint32_t)); | |
231 | 251 | |
232 | - break; | |
252 | + break; | |
233 | 253 | } |
234 | - case HW_DTIME_SET: | |
254 | + case HW_DTIME_SET: | |
235 | 255 | { |
236 | - while (Serial.available() < HW_DATE_SIZE); | |
237 | - | |
238 | - uint32_t unix_time = 0; | |
239 | - for (uint8_t i = HW_DATE_SIZE-1; i >= 0; i--) { | |
240 | - unix_time += Serial.read() << (8*i); | |
241 | - } | |
242 | - timestamp = unix_time; | |
256 | + while (Serial.available() < HW_DATE_SIZE); | |
243 | 257 | |
244 | - Serial.write(HW_ACK); | |
258 | + uint32_t unix_time = 0; | |
259 | + for (uint8_t i = HW_DATE_SIZE-1; i >= 0; i--) { | |
260 | + unix_time += Serial.read() << (8*i); | |
261 | + } | |
262 | + timestamp = unix_time; | |
245 | 263 | |
246 | - break; | |
264 | + break; | |
247 | 265 | } |
248 | - case HW_SLEEP: | |
266 | + case HW_SLEEP: | |
249 | 267 | { |
250 | - SMCR = 0; // (mode) low power reduction | |
251 | - SMCR |= (1 << SE); | |
252 | - asm volatile("sleep"); | |
268 | + SMCR = 0; // (mode) low power reduction | |
269 | + SMCR |= (1 << SE); | |
270 | + asm volatile("sleep"); | |
253 | 271 | |
254 | - // ZzZzZ | |
272 | + // ZzZzZ | |
255 | 273 | |
256 | - SMCR = 0; | |
274 | + SMCR = 0; | |
257 | 275 | |
258 | - break; | |
276 | + break; | |
259 | 277 | } |
260 | - case HW_GET_DATA: | |
278 | + case HW_GET_DATA: | |
261 | 279 | { |
262 | - transfer_active = true; | |
280 | + transfer_active = true; | |
263 | 281 | |
264 | - break; | |
282 | + break; | |
265 | 283 | } |
266 | - case HW_STOP_DATA: | |
284 | + case HW_STOP_DATA: | |
267 | 285 | { |
268 | - // Stop sending chunks? | |
269 | - transfer_active = false; | |
286 | + // Stop sending chunks? | |
287 | + transfer_active = false; | |
270 | 288 | |
271 | - break; | |
272 | - } | |
273 | - default: | |
274 | - // This should never happen, command ignored | |
275 | - break; | |
289 | + break; | |
276 | 290 | } |
291 | + default: | |
292 | + // This should never happen, command ignored | |
293 | + break; | |
277 | 294 | } |
295 | + } | |
278 | 296 | } | ... | ... |