Commit a25803e121c42d092d4bc823f17122e024e638d4

Authored by Calvin Bulla
2 parents 00cd350b bd09bcc3
Exists in master and in 1 other branch dev

Merge branch 'dev' of bizet.dis.ulpgc.es:ediaz/heisenwave into dev

ino/lib/heisenwave/heisenwave.h
... ... @@ -18,5 +18,6 @@
18 18  
19 19 #define HW_HELO_SIZE 16
20 20 #define HW_DATE_SIZE 4
  21 +#define HW_GDATA_SIZE 32
21 22  
22 23 #endif
... ...
ino/src/sketch.ino
... ... @@ -2,17 +2,52 @@
2 2 #include <LCD.h>
3 3 #include <Time.h>
4 4  
5   -uint8_t unix_time[4] = {0,0,0,0};
6 5 char ino_alias[16];
  6 +uint8_t last_second = 0;
  7 +uint8_t lcd_swap = 0;
7 8 LCD lcd;
8 9  
  10 +void print_time_lcd() {
  11 + bool alias_turn;
  12 + char buffer[4];
  13 + lcd.clear_screen();
  14 +
  15 + if (++lcd_swap >= 10) {
  16 + lcd_swap = 0;
  17 + }
  18 +
  19 + if (lcd_swap < 5) {
  20 + lcd.print(ino_alias);
  21 + } else {
  22 + lcd.set_cursor(3,1);
  23 + lcd.print(dayShortStr(day()));
  24 + lcd.print("/");
  25 + lcd.print(monthShortStr(month()));
  26 + lcd.print("/");
  27 + sprintf(buffer, "%d", year());
  28 + lcd.print(buffer);
  29 + }
  30 +
  31 + lcd.set_cursor(5,2);
  32 +
  33 + sprintf(buffer, "%d", hour());
  34 + if (strlen(buffer) < 2) lcd.print("0");
  35 + lcd.print(buffer);lcd.print(":");
  36 + sprintf(buffer, "%d", minute());
  37 + if (strlen(buffer) < 2) lcd.print("0");
  38 + lcd.print(buffer);lcd.print(":");
  39 + sprintf(buffer, "%d", second());
  40 + if (strlen(buffer) < 2) lcd.print("0");
  41 + lcd.print(buffer);
  42 +}
  43 +
9 44 void setup() {
10 45 Serial.begin(115200);
11 46  
12 47 lcd.clear_screen();
13 48 lcd.backlight(true);
14 49 lcd.print("Waiting HELO...");
15   -
  50 +
16 51 while (Serial.available() < 1);
17 52  
18 53 if (Serial.read() == HW_HELO) {
... ... @@ -39,28 +74,55 @@ void setup() {
39 74 }
40 75  
41 76 void loop() {
42   - while (Serial.available() < 1);
43   -
44   - switch (Serial.read()) {
45   - case HW_SMPL_RATE:
46   -
47   - break;
48   - case HW_DTIME_GET:
49   -
50   - break;
51   - case HW_DTIME_SET:
52   - while (Serial.available() < HW_DATE_SIZE);
53   -
54   - for (uint8_t i = 0; i < HW_DATE_SIZE; i++) {
55   - unix_time[i] = Serial.read();
  77 + if (last_second != second()) {
  78 + print_time_lcd();
  79 + last_second = second();
  80 + }
  81 +
  82 + if (Serial.available() < 1) {
  83 + switch (Serial.read()) {
  84 + case HW_SMPL_RATE:
  85 + {
  86 + break;
56 87 }
57   -
58   - break;
59   - case HW_SLEEP:
60   -
61   - break;
62   - case HW_GET_DATA:
63   -
64   - break;
  88 + case HW_DTIME_GET:
  89 + {
  90 + uint32_t timestamp = now();
  91 +
  92 + Serial.write(HW_ACK);
  93 + for (byte i = 0; i < 4; i++) {
  94 + Serial.write((timestamp >> (8*i)) & 0xFF);
  95 + }
  96 +
  97 + break;
  98 + }
  99 + case HW_DTIME_SET:
  100 + {
  101 + while (Serial.available() < HW_DATE_SIZE);
  102 +
  103 + uint32_t unix_time = 0;
  104 + for (uint8_t i = HW_DATE_SIZE-1; i >= 0; i++) {
  105 + unix_time += Serial.read() << (8*i);
  106 + }
  107 + setTime(unix_time);
  108 +
  109 + Serial.write(HW_ACK);
  110 +
  111 + break;
  112 + }
  113 + case HW_SLEEP:
  114 + {
  115 + break;
  116 + }
  117 + case HW_GET_DATA:
  118 + {
  119 + while (Serial.available() < HW_GDATA_SIZE);
  120 +
  121 + break;
  122 + }
  123 + default:
  124 + // Command ignored
  125 + break;
  126 + }
65 127 }
66 128 }
... ...