Commit 2ccdcb3bb246e3a84a412a397399f790711a25b1

Authored by Enrique Díaz Roque
1 parent 4ebca48a
Exists in master and in 1 other branch dev

Quick update (ino)

ino/lib/heisenwave/heisenwave.h
... ... @@ -13,6 +13,7 @@
13 13 #define HW_DTIME_SET 6
14 14 #define HW_DTIME_GET 7
15 15 #define HW_SLEEP 8
  16 +#define HW_STOP_DATA 9
16 17  
17 18 // COMMANDS SIZE
18 19  
... ...
ino/src/sketch.ino
... ... @@ -13,17 +13,44 @@ LCD lcd;
13 13  
14 14 // ADC stuff
15 15  
16   -volatile uint8_t buffer[SIZE];
  16 +volatile uint8_t frame_1[SIZE];
  17 +volatile uint8_t frame_2[SIZE];
  18 +volatile uint8_t *buffer = frame_1;
  19 +volatile uint8_t *pc_buffer = frame_1;
17 20 volatile uint8_t index = 0;
  21 +volatile uint8_t pc_index = 0;
  22 +volatile boolean transfer_active = false;
  23 +volatile boolean transfer_ready = false;
18 24  
19 25 // ISR routines
20 26  
21 27 ISR(ADC_vect) {
22 28 buffer[index++] = ADCH;
  29 +
  30 + if (index == 0) {
  31 + buffer = (buffer == frame_1)? frame_2 : frame_1;
  32 + pc_buffer = (buffer == frame_1)? frame_2 : frame_1;
  33 +
  34 + // will this double buffer system be enough?...
  35 + // if transfer = true => not enough!...
  36 + // we could disable interrupts while send_data...?
  37 +
  38 + transfer_ready = true;
  39 + }
23 40 }
24 41  
25 42 // Procedures && functions
26 43  
  44 +void send_data() {
  45 + if (transfer_active && transfer_ready) {
  46 + for (int i = 0; i < SIZE; i++) {
  47 + Serial.write(pc_buffer[i]);
  48 + }
  49 +
  50 + transfer_ready = false;
  51 + }
  52 +}
  53 +
27 54 void print_time_lcd() {
28 55 bool alias_turn;
29 56 char buffer[4];
... ... @@ -62,7 +89,7 @@ void hardware_setup() {
62 89 ADCSRA |= (0<<ADPS2) | (0<<ADPS1) | (1<<ADPS0) | (1<<ADATE) | (1<<ADEN) | (1<<ADIE);
63 90 ADMUX |= (1<<REFS0) | (1<<ADLAR);
64 91 ADMUX &= ~(1<<REFS1);
65   - ADCSRB &= ~((1<<ADTS2) | (1<<ADTS1) | (1<<ADTS0));
  92 + ADCSRB &= ~((1<<ADTS2) | (1<<ADTS1) | (1<<ADTS0)); // wut? OCR0A
66 93 ADCSRA |= (1<<ADSC);
67 94 }
68 95  
... ... @@ -97,6 +124,8 @@ void setup() {
97 124 }
98 125  
99 126 void loop() {
  127 + send_data();
  128 +
100 129 uint8_t current;
101 130 if (current = second(), last_second != current) {
102 131 print_time_lcd();
... ... @@ -111,12 +140,8 @@ void loop() {
111 140 }
112 141 case HW_DTIME_GET:
113 142 {
114   - uint32_t timestamp = now();
115   -
116 143 Serial.write(HW_ACK);
117   - for (byte i = 0; i < 4; i++) {
118   - Serial.write((timestamp >> (8*i)) & 0xFF);
119   - }
  144 + Serial.write((byte *) now(), sizeof(uint32_t));
120 145  
121 146 break;
122 147 }
... ... @@ -142,6 +167,16 @@ void loop() {
142 167 {
143 168 while (Serial.available() < HW_GDATA_SIZE);
144 169  
  170 + // Activate flag and send chunks when ready?
  171 + transfer_active = true;
  172 +
  173 + break;
  174 + }
  175 + case HW_STOP_DATA:
  176 + {
  177 + // Stop sending chunks?
  178 + transfer_active = false;
  179 +
145 180 break;
146 181 }
147 182 default:
... ...