]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
ADCuC: Go to Q&A based protocol
authorPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 13 Jul 2017 12:31:50 +0000 (14:31 +0200)
committerPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 13 Jul 2017 12:31:50 +0000 (14:31 +0200)
atmega32u4/adcuc/main.c

index 9f00fd5f1b2241960af0322b61475ef62eacc652..92d774b0a24da7c0a84b78bef479eec6bd7251b5 100644 (file)
@@ -65,6 +65,8 @@ uint8_t rxcnt = 0;
 uint8_t rxbuf[7];
 uint8_t txbuf[16];
 
+uint8_t conversion_active = 0;
+uint8_t channel = 0;
 
 
 uint8_t nib_to_hex(uint16_t in, uint8_t nib) {
@@ -102,13 +104,14 @@ ISR(TIMER0_OVF_vect) {
 
 void getdata(uint8_t buf) {
   if (rxcnt != 0 || (buf == 'S' || buf == 'A' || buf == 'L' || buf == 'C' || buf == 'I'
-                                || buf == 'D' || buf == 'O' || buf == 'P' || buf == 'R')) {
+                                || buf == 'D' || buf == 'O' || buf == 'P' || buf == 'R' || buf == 'V')) {
     rxbuf[rxcnt++] = buf;
     }
   if (buf == '\n' || buf == '\r') {
-    if(rxcnt == 5) { //4 letter commands
-      if (rxbuf[0] == 'A') {
-        // do something
+    if(rxcnt == 4) { //3 letter commands
+      if (rxbuf[0] == 'V' && rxbuf[2] == '?') {
+        channel = rxbuf[1]-49;
+        conversion_active = 1;
         }
       }
     }
@@ -117,7 +120,7 @@ void getdata(uint8_t buf) {
 
 void original_value(uint8_t channel, uint8_t get_value_1, uint8_t get_value_2) {
   uint16_t result = (get_value_1 << 8) | get_value_2;
-  send_answer_hex(channel,result);
+  send_answer_hex(channel+1,result);
   }
 
 void update_eeprom(void) {
@@ -217,10 +220,12 @@ __attribute__((naked)) int main(void) {
   uint16_t step = 0;
 
   while(1) {
-    int n = usb_serial_getchar();
-    while (n >= 0) {
-      getdata(n);
-      n = usb_serial_getchar();
+    if (conversion_active == 0) {
+      int n = usb_serial_getchar();
+      while (n >= 0) {
+        getdata(n);
+        n = usb_serial_getchar();
+        }
       }
 
     if(time != lasttime) {
@@ -231,26 +236,17 @@ __attribute__((naked)) int main(void) {
       _delay_us(500);
       */
 
-      switch(step++) {
-        case 10: do_channel(0); break;
-        case 20: read_channel(0); break;
-        case 30: do_channel(1); break;
-        case 40: read_channel(1); break;
-        case 50: do_channel(2); break;
-        case 60: read_channel(2); break;
-        case 70: do_channel(3); break;
-        case 80: read_channel(3); break;
-        case 90: do_channel(4); break;
-        case 100: read_channel(4); break;
-        case 110: do_channel(5); break;
-        case 120: read_channel(5); break;
-        case 130: do_channel(6); break;
-        case 140: read_channel(6); break;
-        case 150: do_channel(7); break;
-        case 160: read_channel(7); break;
+      if (conversion_active == 1) {
+        switch(step++) {
+          case 0: do_channel(channel); break;
+          case 10:
+            read_channel(channel);
+            conversion_active = 0;
+            step = 0;
+            break;
+          }
         }
-      if (step >= 487/2) {
-        //time = 0;
+      else {
         step = 0;
         }
       }