Ejemplo n.º 1
0
int main(int argc, char* argv[]){
  if(argc < 2){
    printf("Not enough input arguments!\n");
    printf("Usage: %s filename\n", argv[0]);
    return -1;
  }

  loadImage(&image, argv[1]);

  cropToSquare(&image);

  uint16_t numSlices = (REFRESH_RATE * 60) / ROTATION_RATE;

  ws2811_init(&ledstring);
  setup_handlers();

  unsigned int updatesCompleted = 0;
  double th;

  #ifdef PERFCOUNT
  struct timespec start, end;
  printf("Update rate:\n");
  if(clock_gettime(CLOCK_REALTIME, &start)) {
    EPRINT("Error: Couldnt get clock time!");
  }
  #endif

  while(running) {
    th = (updatesCompleted % numSlices) * 2 * M_PI / numSlices;
    generateSlice(ledstring.channel[0].leds, th, image.height);

    if (ws2811_render(&ledstring)) {
      EPRINT("Error: Rendering string didnt return 0!\n");
      break;
    }
    updatesCompleted += 1;

    #ifdef PERFCOUNT
    if(!(updatesCompleted % 300)) {
      if(clock_gettime(CLOCK_REALTIME, &end)) {
        EPRINT("Error: Couldnt get clock time!");
      }
      double freq = 300000.0/((end.tv_sec - start.tv_sec)*1000 + (end.tv_nsec - start.tv_nsec)/1000000);
      printf("\t%.2f Hz\r", freq);
      fflush(stdout);
      start = end;
    }
    #endif
  }

  // Clear the led strip before exiting
  for(int i = 0; i < LED_COUNT; i++) {
    ledstring.channel[0].leds[i] = 0;
  }
  ws2811_render(&ledstring);
  ws2811_fini(&ledstring);
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
    int ret = 0;

    setup_handlers();

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

    while (1)
    {
        matrix_raise();
        matrix_bottom();
        matrix_render();

        if (ws2811_render(&ledstring))
        {
            ret = -1;
            break;
        }

        // 15 frames /sec
        usleep(1000000 / 15);
    }

    ws2811_fini(&ledstring);

    return ret;
}
Ejemplo n.º 3
0
Archivo: hat.c Proyecto: snobu/silicorn
/* Clear the display and exit gracefully */
void unicorn_exit(int status){
        puts("\nCleaning up HAT...");
        clear_led_buffer();
        ws2811_render(&ledstring);
        ws2811_fini(&ledstring);
        exit(status);
}
Ejemplo n.º 4
0
// Send new values down the LED chain
int LedDeviceWS281x::write(const std::vector<ColorRgb> &ledValues)
{
	int idx = 0;
	for (const ColorRgb& color : ledValues)
	{
		if (idx >= _led_string.channel[_channel].count)
		{
			break;
		}

		_temp_rgbw.red = color.red;
		_temp_rgbw.green = color.green;
		_temp_rgbw.blue = color.blue;
		_temp_rgbw.white = 0;

		if (_led_string.channel[_channel].strip_type == SK6812_STRIP_GRBW)
		{
			Rgb_to_Rgbw(color, &_temp_rgbw, _whiteAlgorithm);
		}

		_led_string.channel[_channel].leds[idx++] = 
			((uint32_t)_temp_rgbw.white << 24) + ((uint32_t)_temp_rgbw.red << 16) + ((uint32_t)_temp_rgbw.green << 8) + _temp_rgbw.blue;

	}
	while (idx < _led_string.channel[_channel].count)
	{
		_led_string.channel[_channel].leds[idx++] = 0;
	}
	
	return ws2811_render(&_led_string) ? -1 : 0;
}
Ejemplo n.º 5
0
static void ctrl_c_handler(int signum)
{
    ledstring.channel[0].brightness = 0;
    ws2811_render(&ledstring);
    ws2811_fini(&ledstring);
    exit(0);
}
Ejemplo n.º 6
0
/*
  Clear the display and exit gracefully
*/
void unicorn_exit(int status){
    int i;
    for (i = 0; i < 64; i++){
        setPixelColorRGB(i,0,0,0);
    }
    ws2811_render(&ledstring);
    ws2811_fini(&ledstring);

    exit(status);
}
Ejemplo n.º 7
0
Archivo: leds.c Proyecto: TwP/pixel_pi
/* call-seq:
 *    show
 *
 * Update the display with the data from the LED buffer.
 *
 * Returns this PixelPi::Leds instance.
 */
static VALUE
pp_leds_show( VALUE self )
{
  ws2811_t *ledstring = pp_leds_struct( self );
  int resp = ws2811_render( ledstring );
  if (resp < 0) {
    rb_raise( ePixelPiError, "PixelPi::Leds failed to render: %d", resp );
  }
  return self;
}
Ejemplo n.º 8
0
//sends the buffer to the leds
//render <channel>,0,AABBCCDDEEFF...
//optional the colors for leds:
//AABBCC are RGB colors for first led
//DDEEFF is RGB for second led,...
void render(char * args){
	int channel=0;
	int r,g,b;
	int led_index;
	int size;
    int start;
    char value[MAX_VAL_LEN];
    char color_string[6];
    
	if (debug) printf("Render %s\n", args);
	
    if (ledstring.device==NULL){
        printf("Error you must call setup first!\n");
        return;
    }
    
    if (args!=NULL){
		args = read_val(args, value, MAX_VAL_LEN);
		channel = atoi(value)-1;
        if (channel<0 || channel > 1) channel=0;
		if (*args!=0){
			args++;
			args = read_val(args, value, MAX_VAL_LEN); //read start position
			start = atoi(value);
			while (*args!=0 && (*args==' ' || *args==',')) args++; //skip white space
            
			if (debug) printf("Render channel %d selected start at %d leds %d\n", channel, start, ledstring.channel[channel].count);
			
            size = strlen(args);
            led_index = start % ledstring.channel[channel].count;

            while (*args!=0){
                //if (debug) printf("r %d %d\n", hextable[args[0]], hextable[args[1]]);
                int i=0;
                while (*args!=0 && i<6){
                    if (*args!=' ' && *args!='\t'){
                        color_string[i]=*args;
                        i++;
                    }
                    args++;
                }
                if (i==6){
                    r = (hextable[color_string[0]]<<4) + hextable[color_string[1]];
                    g = (hextable[color_string[2]]<<4) + hextable[color_string[3]];
                    b = (hextable[color_string[4]]<<4) + hextable[color_string[5]];
                    if (debug) printf(" set pixel %d to %d,%d,%d\n", led_index, r,g,b);
                    ledstring.channel[channel].leds[led_index] = color(r,g,b);
                    led_index += (led_index %ledstring.channel[channel].count);
                }
            }
		}
	}
	if (ledstring.device!=NULL) ws2811_render(&ledstring);
}
Ejemplo n.º 9
0
// Turn off the LEDs by sending 000000's
// TODO Allow optional power switch out another gpio, if this code handles it can
// make it more likely we don't accidentally drive data into an off strip
int LedDeviceWS281x::switchOff()
{
	if (!initialized)
		return -1;

	int idx = 0;
	while (idx < led_string.channel[chan].count)
		led_string.channel[chan].leds[idx++] = 0;

	if (ws2811_render(&led_string))
		return -1;

	return 0;
}
Ejemplo n.º 10
0
int RPIWS281xOutput::RawSendData(unsigned char *channelData)
{
	LogDebug(VB_CHANNELOUT, "RPIWS281xOutput::RawSendData(%p)\n", channelData);

	unsigned char *c = channelData;
	unsigned int r = 0;
	unsigned int g = 0;
	unsigned int b = 0;

	// Handle String #1
	if (m_string1GPIO)
	{
		for (int i = 0; i < m_string1Pixels; i++)
		{
			r = *(c++);
			g = *(c++);
			b = *(c++);
			ledstring.channel[0].leds[i] =
				(r << 16) | (g <<  8) | (b);
		}
	}

	// Handle String #2
	if (m_string2GPIO)
	{
		for (int i = 0; i < m_string2Pixels; i++)
		{
			r = *(c++);
			g = *(c++);
			b = *(c++);
			ledstring.channel[1].leds[i] =
				(r << 16) | (g <<  8) | (b);
		}
	}

	if (ws2811_render(&ledstring))
	{
		LogErr(VB_CHANNELOUT, "ws2811_render() failed\n");
	}

	return m_channelCount;
}
Ejemplo n.º 11
0
// Send new values down the LED chain
int LedDeviceWS281x::write(const std::vector<ColorRgb> &ledValues)
{
	if (!initialized)
		return -1;

	int idx = 0;
	for (const ColorRgb& color : ledValues)
	{
		if (idx >= led_string.channel[chan].count)
			break;
		led_string.channel[chan].leds[idx++] = ((uint32_t)color.red << 16) + ((uint32_t)color.green << 8) + color.blue;
	}
	while (idx < led_string.channel[chan].count)
		led_string.channel[chan].leds[idx++] = 0;

	if (ws2811_render(&led_string))
		return -1;

	return 0;
}
Ejemplo n.º 12
0
void show(){
    ws2811_render(&ledstring);
}
Ejemplo n.º 13
0
int matrix_render() {
  return ws2811_render(&leds);
}