Beispiel #1
0
Driver :: ~Driver()
{
	//clear();
	/* Free the pixel buffer */
	lpd8806_free(&buf);

	/* Close the SPI device */
	close(fd);
}
Beispiel #2
0
int main(int argc, char *argv[]) {
  int fd;              /* SPI device file descriptor */
  const int leds = 500; /* 50 LEDs in the strand */
  lpd8806_buffer buf;      /* Memory buffer for pixel values */
  int count;           /* Count of iterations (up to 3) */
  int i;               /* Counting Integer */
  set_gamma(2.5,2.5,2.5);
  /* Open SPI device */
  fd = open("/dev/spidev0.0",O_WRONLY);
  if(fd<0) {
      /* Open failed */
      fprintf(stderr, "Error: SPI device open failed.\n");
      exit(1);
  }

  /* Initialize SPI bus for lpd8806 pixels */
  if(spi_init(fd)<0) {
      /* Initialization failed */
      fprintf(stderr, "Unable to initialize SPI bus.\n");
      exit(1);
  }

  /* Allocate memory for the pixel buffer and initialize it */
  if(lpd8806_init(&buf,leds)<0) {
      /* Memory allocation failed */
      fprintf(stderr, "Insufficient memory for pixel buffer.\n");
      exit(1);
  }

  /* Loop Forever */
  while(1) {
    /* Do three iterations */
    for(count=0;count<3;count++) {
      /* Write color for every pixel */
      for(i=0;i<leds;i++) {
        if((i+count)%3==0) {
          /* Red pixel */
          write_gamma_color(&buf.pixels[i],255,0,0);
        }
        else if((i+count)%3==1) {
          /* Green pixel */
          write_gamma_color(&buf.pixels[i],0,255,0);
        }
        else {
          /* Blue pixel */
          write_gamma_color(&buf.pixels[i],0,0,255);
        }
      }

      /* Send the data to the lpd8806 lighting strand */
      if(send_buffer(fd,&buf)<0) {
        fprintf(stderr, "Error sending data.\n");
        exit(1);
      }

      /* Sleep for 1 second */
      usleep(1000000/60.0f);
    }
  }
for(i=0;i<leds;i++) {
    
      write_gamma_color(&buf.pixels[i],0x00,0x00,0x00);
      
  }
    send_buffer(fd,&buf);
  /* Although the program never gets to this point, below is how to clean up */

  /* Free the pixel buffer */
  lpd8806_free(&buf);

  /* Close the SPI device */
  close(fd);

  return 0;
}
Beispiel #3
0
void * spi_handler(void)
{
  lpd8806_buffer buf;
  int fd;
  int return_value;
  lpd8806_color *p;
  int i;
  double h, r, g, b;

  /* Open the device file using Low-Level IO */
  fd = open(device,O_WRONLY);
  if(fd<0) {
    fprintf(stderr,"Error %d: %s\n",errno,strerror(errno));
    pthread_exit(NULL);
  }

  /* Initialize the SPI bus for Total Control Lighting */
  return_value = spi_init(fd);
  if(return_value==-1) {
    fprintf(stderr,"SPI initialization error %d: %s\n",errno, strerror(errno));
    pthread_exit(NULL);
  }

  /* Initialize pixel buffer */
  if(lpd8806_init(&buf,leds)<0) {
    fprintf(stderr,"Pixel buffer initialization error: Not enough memory.\n");
    pthread_exit(NULL);
  }

  /* Set the gamma correction factors for each color */
  set_gamma(2.2,2.2,2.2);

  /* Blank the pixels */

  for(i=0;i<leds;i++) {
    write_gamma_color(&buf.pixels[i],0x00,0x00,0x00);
  }

  send_buffer(fd,&buf);

  h = 0.0;
  printf("Entering spi loop\n");
  /* Loop while continue_looping is true */
  for(;;){
    pthread_mutex_lock(&playback_status_lock);
    if(is_playing){
      h+=2.0;
      if(h>=360.0) h=0.0;
      memmove(buf.pixels+1,buf.pixels,sizeof(lpd8806_color)*(leds-2));
      HSVtoRGB(h,1.0,1.0,&r,&g,&b);
      p = &buf.pixels[0];
      write_gamma_color(p,(int)(r*255.0),(int)(g*255.0),(int)floor(b*255.0));
      send_buffer(fd,&buf);
    } else {
      for(i=0;i<leds;i++) {
         p = &buf.pixels[i];
         write_gamma_color(p,0x00,0x00,0x00);
      }
    send_buffer(fd,&buf);
   }
   pthread_mutex_unlock(&playback_status_lock);
   usleep(10000);
  }
for(i=0;i<leds;i++) {
    p = &buf.pixels[i];
      write_gamma_color(p,0x00,0x00,0x00);
      
  }
    send_buffer(fd,&buf);
  lpd8806_free(&buf);
  close(fd);
  printf("lpd thread terminated.\n");

  pthread_exit(NULL);
}