Example #1
0
int main(int argc, char **argv) {
    int shader = 0;

    if (argc >= 3){
        if(sscanf (argv[2], "%i", &anim_delay)!=1){
            printf ("Error, delay must be an integer \n");
            return 0;
        }
    }

    int newbrightness = 0;
    if (argc >= 4){
        if(sscanf (argv[3], "%i", &newbrightness)!=1){
            printf ("Error, brightness must be an integer \n");
            return 0;

        }else{
            setBrightness(newbrightness);
        }
    }
    if (argc == 2){
        if(sscanf (argv[1], "%i", &newbrightness)==1){
            setBrightness(newbrightness);
            shader = 1;
        }
    }

    int i;
    for (i = 0; i < 64; i++) {
        struct sigaction sa;
        memset(&sa, 0, sizeof(sa));
        sa.sa_handler = unicorn_exit;
        sigaction(i, &sa, NULL);
    }

    setvbuf(stdout, NULL, _IONBF, 0);

    if(ws2811_init(&ledstring))
    {
        return -1;
    }

    clearLEDBuffer();

    if(argc < 2){
        shader = 1;
    }

    if(shader){
        run_shader();
    }else{

        read_png_file(argv[1]);
        while(1){
            process_file();
            if (height/8 == 1){
                break;
            }
        }

    }

    unicorn_exit(0);

    return 0;
}
Example #2
0
int main(int argc, char **argv) {

  // Catch all signals possible - it's vital we kill the DMA engine on process exit!
  uint8_t i;
  for (i = 0; i < 64; i++) {
    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = unicorn_exit;
    sigaction(i, &sa, NULL);
  }

  // Get the input args if any
  int newbrightness = DEFAULT_BRIGHTNESS*100;
  if (argc == 2) {
    if(sscanf (argv[1], "%i", &newbrightness)!=1){
      printf ("Error, brightness must be an integer \n");
      return 0;
    }
  } else if (argc == 3) {
    if(sscanf (argv[1], "%i", &newbrightness)!=1){
      printf ("Error, brightness must be an integer \n");
      return 0;
    }
    if(sscanf (argv[2], "%i", &pulse_second) > 1){
      printf ("Error, second pulsing must be an bool \n");
      return 0;
    }
  } else if (argc == 4) {
    if(sscanf (argv[1], "%i", &newbrightness)!=1){
      printf ("Error, brightness must be an integer \n");
      return 0;
    }
    if(sscanf (argv[2], "%i", &pulse_second) > 1){
      printf ("Error, second pulsing must be an bool \n");
      return 0;
    }
    if(sscanf (argv[3], "%i", &rotate) > 1){
      printf ("Error, rotate must be an bool \n");
      return 0;
    }
  }


  // Don't buffer console output
  setvbuf(stdout, NULL, _IONBF, 0);

  // Set the number of pixels
  numLEDs = PIXEL_COLUMN*PIXEL_ROW;

  // Set the brightness
  setBrightness(newbrightness/100.0);

  // init WS2812
  initHardware();
  clearLEDBuffer();

  // Create the matrix lookup map
  initMatrixMap(pixelMap,rotate);

  // Wipe through rgb for LED debug at start up
  colorWipe(Color(255,0,0),WIPE_DELAY);
  colorWipe(Color(0,255,0),WIPE_DELAY);
  colorWipe(Color(0,0,255),WIPE_DELAY);
  colorWipe(Color(0,0,0),WIPE_DELAY);

  while(1) {
      // The get time and set matrix loop (Arduino lagacy)
      loop();
      // Wait a second before checking the time again
      usleep(1000*1000);
    }

  // Shouldn't get here but if we do, exit gracefully
  unicorn_exit(0);

  return 0;
}