]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
fixes & more LED for DAQi
authorJan Michel <j.michel@gsi.de>
Mon, 23 Jan 2017 11:05:57 +0000 (12:05 +0100)
committerJan Michel <j.michel@gsi.de>
Mon, 23 Jan 2017 11:05:57 +0000 (12:05 +0100)
atmega32u4/daqi/daqi.c
atmega32u4/daqi/usb_serial.c

index 0d99a4262e625989e58e65fa627cd003576f58c8..9c1bd679d5b52b5298ac884784710de761ea6f44 100644 (file)
 uint8_t buffer[BUFFERSIZE];
 uint8_t pointer = 0;
 
-uint8_t red[NUM_LEDS]   = {0xff};
-uint8_t green[NUM_LEDS] = {0xff};
-uint8_t blue[NUM_LEDS]  = {0xff};
+uint8_t red[NUM_LEDS]   = {0x06,0x06,0x06,0x06,0x06};
+uint8_t green[NUM_LEDS] = {0x09,0x09,0x09,0x09,0x09};
+uint8_t blue[NUM_LEDS]  = {0x10,0x10,0x10,0x10,0x10};
 
 
 void init(void) {
  LED_RGB_OUT();
  LED_RGB_LOW();
+ DDRD |= (1<<PD5);
 }
 
 void led_update(void) {
   uint8_t col[3];
   uint8_t cc;
-  DDRD |= (1<<PD5);
+  PORTD &= ~(1<<PD5);
+  
   cli();
   for(uint8_t k = 0; k<NUM_LEDS;k++) {
     col[0] = green[k];
@@ -45,6 +47,7 @@ void led_update(void) {
           }
         else {
           LED_RGB_HIGH();
+          _delay_us(0.1);
           LED_RGB_LOW();
           _delay_us(0.5);
           }
@@ -53,17 +56,17 @@ void led_update(void) {
       }  
     }  
   sei();
-  DDRD &= ~(1<<PD5);
+  PORTD |=  (1<<PD5);
   }
 
-uint8_t hex2int(char c) {
+uint8_t hex2int(uint8_t c) {
   if(c >= '0' && c<='9') return c-'0';
   if(c >= 'a' && c<='f') return c-'a'+10;
   if(c >= 'A' && c<='F') return c-'A'+10;
   return -1;
   } 
   
-uint8_t configuration_led(char* h) {
+uint8_t configuration_led(uint8_t* h) {
   uint8_t l = hex2int(*h);
   red[l]   = hex2int(*(h+1))*16+hex2int(*(h+2));
   green[l] = hex2int(*(h+3))*16+hex2int(*(h+4));
@@ -76,21 +79,24 @@ uint8_t configuration_led(char* h) {
 __attribute__((naked)) int main(void) {
   init();  
   usb_init();
+  led_update();
 
   while (1) {
     int n = usb_serial_getchar();
     if (n >= 0) {
       buffer[pointer++] = n;
+      usb_serial_putchar_nowait(n);
       if(pointer>BUFFERSIZE) {
         pointer = 0;
         }
-      if(n == 10) {
-        if(pointer >= 9 && buffer[0] == '#') {
-          configuration_led(buffer+1);
-          }
+      if(pointer >= 8 && buffer[0] == '#') {
+        configuration_led(buffer+1);
         pointer = 0;
         }
       }
+    if (n == 0x0a || n == 0x0d || buffer[0] != '#') {
+      pointer = 0;
+      }
     }
   }
 
index 2c12a9ce50ed9b65bc43b06cad9f00cd17288234..7b79e005b422e975e8086ee69a22b3cba2423a3a 100644 (file)
@@ -60,7 +60,7 @@
 // Udev rules (in /etc/udev/rules.d) can define persistent device
 // names linked to this serial number, as well as permissions, owner
 // and group settings.
-#define STR_SERIAL_NUMBER        L"00001"
+#define STR_SERIAL_NUMBER        L"00002"
 
 // Mac OS-X and Linux automatically load the correct drivers.  On
 // Windows, even though the driver is supplied by Microsoft, an