示例#1
0
// helper to init all leds
void init_leds(){
  // init leds
  //int fd;              /* SPI device file descriptor */
  //const int leds = 12; /* 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);
  }

  // SET LEDS HERE, update to do on interaction
  flash_leds(12);
}
示例#2
0
 Driver::Driver()
{
	
	setup_pcf();
	set_gamma(2.5,2.5,2.5);
	leds= 64;
		
	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 */
	
	for(int i=0;i<leds;i++) {
		
		write_gamma_color(&buf.pixels[i],0x00,0x00,0x00);
			
	}
	
	
		send_buffer(fd,&buf);

}
示例#3
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;
}
示例#4
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);
}
示例#5
0
int main(int argc, char **argv) {

	int spi_fd;
	int effect=EFFECT_RANDOM;

	if (argc>1) {
		if ((!strncmp(argv[1],"-h",2)) || (!strncmp(argv[1],"help",4))) {
			help(argv[0]);
			return 0;
		}

		if (!strncmp(argv[1],"bargraph_mannual",15)) {
			effect=EFFECT_BARGRAPH_MANUAL;
		}

		if (!strncmp(argv[1],"bargraph",8)) {
			effect=EFFECT_BARGRAPH;
		}

		if (!strncmp(argv[1],"disable",7)) {
			effect=EFFECT_DISABLE;
		}

		if (!strncmp(argv[1],"falling",7)) {
			effect=EFFECT_FALLING;
		}


		if (!strncmp(argv[1],"fish",4)) {
			effect=EFFECT_FISH;
		}

		if (!strncmp(argv[1],"gradient",8)) {
			effect=EFFECT_GRADIENT;
		}

		if (!strncmp(argv[1],"noise",5)) {
			effect=EFFECT_NOISE;
		}

		if (!strncmp(argv[1],"pulsar",6)) {
			effect=EFFECT_PULSAR;
		}

		if (!strncmp(argv[1],"rainbow",7)) {
			effect=EFFECT_RAINBOW;
		}

		if (!strncmp(argv[1],"stars",5)) {
			effect=EFFECT_STARS;
		}

		if (!strncmp(argv[1],"red_green",9)) {
			effect=EFFECT_RED_GREEN;
		}

		if (!strncmp(argv[1],"blue_yellow",11)) {
			effect=EFFECT_BLUE_YELLOW;
		}

		if (!strncmp(argv[1],"two_color_scroll",15)) {
			effect=EFFECT_TWO_COLOR_SCROLL;
		}

		if (!strncmp(argv[1],"scanner_blinky",14)) {
			effect=EFFECT_SCANNER_BLINKY;
		} else

		if (!strncmp(argv[1],"scanner_dual",12)) {
			effect=EFFECT_SCANNER_DUAL;
		} else

		if (!strncmp(argv[1],"scanner_random",14)) {
			effect=EFFECT_SCANNER_RANDOM;
		} else

		if (!strncmp(argv[1],"scanner",7)) {
			effect=EFFECT_SCANNER;
		}


	}

	spi_fd=lpd8806_init();
	if (spi_fd<0) {
		exit(-1);
	}

	switch(effect) {
		case EFFECT_BARGRAPH:
			bargraph(spi_fd,argc>2?argv[2]:NULL,
					argc>3?argv[3]:NULL);
			break;

		case EFFECT_BARGRAPH_MANUAL:
			bargraph_manual(spi_fd,argc>2?argv[2]:NULL,
					argc>3?argv[3]:NULL);
			break;

		case EFFECT_DISABLE:
			disable(spi_fd);
			break;

		case EFFECT_FALLING:
			falling(spi_fd,
				argc>2?argv[2]:NULL,
				argc>2?argv[3]:NULL);
			break;

		case EFFECT_FISH:
			fish(spi_fd,argc>2?argv[2]:NULL);
			break;

		case EFFECT_GRADIENT:
			gradient(spi_fd,argc>2?argv[2]:NULL);
			break;

		case EFFECT_NOISE:
			noise(spi_fd);
			break;

		case EFFECT_PULSAR:
			pulsar(spi_fd,argc>2?argv[2]:NULL);
			break;

		case EFFECT_RAINBOW:
			rainbow(spi_fd);
			break;

		case EFFECT_STARS:
			stars(spi_fd,argc>2?argv[2]:NULL,
					argc>3?argv[3]:NULL);
			break;
		case EFFECT_TWO_COLOR_SCROLL:
			two_color_scroll(spi_fd,
					argc>2?argv[2]:NULL,
					argc>3?argv[3]:NULL,
					argc>4?argv[4]:NULL);
			break;

		case EFFECT_RED_GREEN:
			two_color_scroll(spi_fd,
					"red",
					"green",
					"1");
			break;
		case EFFECT_BLUE_YELLOW:
			two_color_scroll(spi_fd,
					"blue",
					"yellow",
					"0");
			break;

		case EFFECT_SCANNER:
			scanner(spi_fd,argc>2?argv[2]:NULL);
			break;

		case EFFECT_SCANNER_BLINKY:
			scanner_blinky(spi_fd);
			break;

		case EFFECT_SCANNER_DUAL:
			scanner_dual(spi_fd,
				argc>2?argv[2]:NULL,
				argc>3?argv[3]:NULL);
			break;

		case EFFECT_SCANNER_RANDOM:
			scanner_random(spi_fd);
			break;


	}

	lpd8806_close(spi_fd);

	return 0;
}
示例#6
0
int main(int argc, char **argv) {

	int spi_fd;
	int effect=EFFECT_RANDOM;

	if (argc>1) {
		if (!strncmp(argv[1],"-h",2)) {
			help(argv[0]);
			return 0;
		}

		if (!strncmp(argv[1],"bargraph",8)) {
			effect=EFFECT_BARGRAPH;
		}

		if (!strncmp(argv[1],"rainbow",7)) {
			effect=EFFECT_RAINBOW;
		}

		if (!strncmp(argv[1],"stars",5)) {
			effect=EFFECT_STARS;
		}

		if (!strncmp(argv[1],"red_green",9)) {
			effect=EFFECT_RED_GREEN;
		}

		if (!strncmp(argv[1],"blue_yellow",11)) {
			effect=EFFECT_BLUE_YELLOW;
		}

		if (!strncmp(argv[1],"two_color_scroll",15)) {
			effect=EFFECT_TWO_COLOR_SCROLL;
		}

	}

	spi_fd=lpd8806_init();
	if (spi_fd<0) {
		exit(-1);
	}

	switch(effect) {
		case EFFECT_BARGRAPH:
			bargraph(spi_fd,argc>2?argv[2]:NULL,
					argc>3?argv[3]:NULL);
			break;
		case EFFECT_RAINBOW:
			rainbow(spi_fd);
			break;
		case EFFECT_STARS:
			stars(spi_fd,argc>2?argv[2]:NULL,
					argc>3?argv[3]:NULL);
			break;
		case EFFECT_TWO_COLOR_SCROLL:
			two_color_scroll(spi_fd,
					argc>2?argv[2]:NULL,
					argc>3?argv[3]:NULL,
					argc>4?argv[4]:NULL);
			break;

		case EFFECT_RED_GREEN:
			two_color_scroll(spi_fd,
					"red",
					"green",
					"1");
			break;
		case EFFECT_BLUE_YELLOW:
			two_color_scroll(spi_fd,
					"blue",
					"yellow",
					"0");
			break;



	}

	lpd8806_close(spi_fd);

	return 0;
}