 
 // Serial I/O
 const int ioSize = 64;
-char command[32];
+char command[32];
 int8_t in_index = 0;
 
 void start_serial(void)

{
  uint16_t i, val;

  if( collect_serial() )
  {
      // we have valid buffer of serial input
      char cmd = command[0] & CASE_MASK;
      switch (cmd) {
          case '*':
            Serial.println("Magnus Core Node");
            break;
          case 'E':
          case 'R':
              owner = cmd == 'E' ? enlightened : resistance;
              percent = getPercent(&command[1]);
              uint8_t red, green, blue, white;
              Color c;
              c = ToColor(0x00, 
                  owner == enlightened ? 0xff : 0x00,
                  owner == resistance ? 0xff : 0x00,
                  0x00);
              animations.pulse.init(states[0], strip, c);
//              pCurrAnimation = &animations.pulse;
              animationQueue.setTo(&animations.pulse);
              break;

          case 'N':
              owner = neutral;
              animations.redFlash.init(states[0], strip, RGBW_SUPPORT);
              animationQueue.setTo(&animations.redFlash);
              animationQueue.add(&animations.solid);
              percent = 20;
              break;

          default:
              Serial.print("Unkwown command "); Serial.println(cmd);
              break;
      }
      Serial.print((char *)command); Serial.print(" - ");Serial.print(command[0],DEC);Serial.print(": "); 
      Serial.print("owner "); Serial.print(owner,DEC); Serial.print(", percent "); Serial.println(percent,DEC); 
  }

  if(strings[dir].timing < millis() )
  {
      strings[dir].timing += 10; // every 100 milliseconds we will check this direction

      strip.setPin(dir+BASE_PIN);  // pick the string

      uint8_t red, green, blue, white;
      red = 0x20; green = 0; blue = 0x20; white = 0x20;
      bool useAnimations = false;
      if( owner == neutral ) 
      {
          red = 0x40; green = 0x40; blue = 0x40; white = 0x40;
          //      red = 0; green = 0; blue = 0; white = 0x40;
          useAnimations = true;
      }
      else if( owner == resistance )
      {
          red = 0; green = 0x1f; blue = 0xff;; white = 0;
          useAnimations = true;
      }
      else if( owner == enlightened )
      {
          red = 0x1f; green = 0xff; blue = 0; white = 0;
          useAnimations = true;
      }

      if (useAnimations) {
          unsigned int queueSize = animationQueue.size();
          if (queueSize > 1) {
              if (animationQueue.peek()->done(states[0])) {
                  animationQueue.remove();
                  queueSize--;
                  animationQueue.peek()->start(states[0]);
              }
          }
          if (queueSize > 0) {
              //strip.setBrightness(255);
              strip.setBrightness((uint8_t)((uint16_t)(255*(percent/100.0))));
              //pCurrAnimation->doFrame(states[0], strip);
              animationQueue.peek()->doFrame(states[0], strip);
          }
      } else {
          for(i=0; i < strip.numPixels(); i++)
          {
              //strip.setPixelColor(i, green,blue,red); // for RGB order is funny?
              //        strip.setPixelColor(i, green, red, blue,white);
              strip.setPixelColor(i, red, green, blue);
              //        float scale = ((millis()/100)%100)/200.0 + 0.5;
              float scale = 1.0f;
              float pct = percent * scale;
              //        Serial.print("Percent: "); Serial.println(pct, 4);
              strip.setBrightness((uint8_t)((uint16_t)(255*(pct/100.0))));
          }
          strip.show();
      }

      dir++;
      if( dir >= NUM_STRINGS )
          dir = 0;
  }


}



#include <Adafruit_NeoPixel.h>
#include <stdlib.h>
#include <string.h>
#include "animation.hpp"
#include "circbuff.hpp"

// first communication pin for neo pixel string
#define BASE_PIN 2
