예제 #1
0
파일: main.c 프로젝트: swoodford/rpi_ws281x
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;
}
예제 #2
0
파일: hat.c 프로젝트: 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);
}
예제 #3
0
파일: main.c 프로젝트: mludvig/rpi_ws281x
static void ctrl_c_handler(int signum)
{
    ledstring.channel[0].brightness = 0;
    ws2811_render(&ledstring);
    ws2811_fini(&ledstring);
    exit(0);
}
예제 #4
0
LedDeviceWS281x::~LedDeviceWS281x()
{
	if (_deviceReady)
	{
		ws2811_fini(&_led_string);
	}
}
예제 #5
0
파일: leds.c 프로젝트: TwP/pixel_pi
/* call-seq:
 *    close
 *
 * Shutdown the NeoPixels connected to the DMA / PWM channel. After this method
 * the current PixelPi::Leds instance will no longer be usable; a new instance
 * will need to be created. This method is automatically invoked when the
 * instance is deallcoated by the Ruby garbage collector. It does not need to be
 * explicitly invoked.
 *
 * Returns `nil`.
 */
static VALUE
pp_leds_close( VALUE self )
{
  ws2811_t *ledstring = pp_leds_struct( self );
  if (ledstring->device) ws2811_fini( ledstring );
  return Qnil;
}
예제 #6
0
int RPIWS281xOutput::Close(void)
{
	LogDebug(VB_CHANNELOUT, "RPIWS281xOutput::Close()\n");

	ws2811_fini(&ledstring);

	return ChannelOutputBase::Close();
}
예제 #7
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);
}
예제 #8
0
// Destructor
LedDeviceWS281x::~LedDeviceWS281x()
{
	if (initialized)
	{
		std::cout << "Shutdown WS281x PWM and DMA channel" << std::endl;
		ws2811_fini(&led_string);
	}
	initialized = false;
}
예제 #9
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);
}
예제 #10
0
파일: leds.c 프로젝트: TwP/pixel_pi
static void
pp_leds_free( void *ptr )
{
  ws2811_t *ledstring;
  if (NULL == ptr) return;

  ledstring= (ws2811_t*) ptr;
  if (ledstring->device) ws2811_fini( ledstring );
  xfree( ledstring );
}
예제 #11
0
파일: main.c 프로젝트: swoodford/rpi_ws281x
static void ctrl_c_handler(int signum)
{
    ws2811_fini(&ledstring);
}
예제 #12
0
파일: matrix.c 프로젝트: vixus0/monohorn
void matrix_end() {
  ws2811_fini(&leds);
}
예제 #13
0
//main routine
int main(int argc, char *argv[]){
    int ret = 0;
	int i;
	int index=0;

	ledstring.device=NULL;
	command_line = NULL;
    named_pipe_file=NULL;
	malloc_command_line(DEFAULT_COMMAND_LINE_SIZE);

    setup_handlers();

    input_file = stdin; //by default we read from console, stdin
    mode = MODE_STDIN;
    
	if (argc>1){
        if (strcmp(argv[1], "-p")==0){ //use a named pipe, creates a file (by default in /dev/ws281x) which you can write commands to: echo "command..." > /dev/ws281x
            if (argc>2){
                named_pipe_file = malloc(strlen(argv[2]+1));
                strcpy(named_pipe_file,argv[2]);
            }else{
                named_pipe_file = malloc(strlen(DEFAULT_DEVICE_FILE)+1);
                strcpy(named_pipe_file, DEFAULT_DEVICE_FILE);
            }
            printf ("Opening %s as named pipe.", named_pipe_file);
            remove(named_pipe_file);
            mkfifo(named_pipe_file,0777);
            chmod(named_pipe_file,0777);
            input_file = fopen(named_pipe_file, "r");
            mode  = MODE_NAMED_PIPE;
        }else if (strcmp(argv[1], "-f")==0){ //read commands / data from text file
            if (argc>2){
                input_file = fopen(argv[2], "r");
                printf("Opening %s.", argv[2]);
            }else{
                printf("Error you must enter a file name after -f option\n");
                exit(1);
            }
            mode = MODE_FILE;
        }else if (strcmp(argv[1], "-tcp")==0){ //open up tcp ip port and read commands from there
            if (argc>2){
                int port = atoi(argv[2]);
                if (port==0) port=9999;
                printf("Listening on %d.\n", port);
                start_tcpip(port);
            }else{
                printf("You must enter a port after -tcp option\n");
                exit(1);
            }
            mode = MODE_TCP;
        }
	}
	
	if ((mode == MODE_FILE || mode == MODE_NAMED_PIPE) && input_file==NULL){
		perror("Error opening file!");
		exit(1);
	}
	
    int c;
	
	while (exit_program==0) {
        if (mode==MODE_TCP){
            c = 0;
            if (read(active_socket, (void *) & c, 1)<=0) c = EOF; //returns 0 if connection is closed, -1 if no more data available and >0 if data read
        }else{
            c = fgetc (input_file); //doesn't work with tcp
        }
        
	  if (c!=EOF){
        process_character(c);
	  }else{
        //end of file or read error
		switch (mode){
            case MODE_TCP:
                if (!exit_program){
                    tcp_wait_connection(); //go back to wait for connection
                }
                break;
            case MODE_NAMED_PIPE:
            case MODE_STDIN:
                usleep(10000);
                break;
            case MODE_FILE:
                exit_program=1;
                break;
        }
	  }
    }
	
    if (mode==MODE_TCP){
        shutdown(active_socket,SHUT_RDWR);
        shutdown(sockfd,SHUT_RDWR);
        close(active_socket);
        close(sockfd);
    }else{
        fclose(input_file);
    }
        
    if (named_pipe_file!=NULL){
        remove(named_pipe_file);
        free(named_pipe_file);
    }
	free(command_line);
    if (thread_data!=NULL) free(thread_data);
    if (ledstring.device!=NULL) ws2811_fini(&ledstring);

    return ret;
}
예제 #14
0
//initializes the ws2811 driver code
//setup freq=400,dma=5,channels=1,channel_1_gpio=18,channel_1_invert=0,channel_1_count=250,channel_1_brightness=255,channel_2_...
void setup_ledstring(char * args){
	char key[MAX_KEY_LEN], value[MAX_VAL_LEN];
	int key_index, value_index;

	if (ledstring.device!=NULL)	ws2811_fini(&ledstring);
	
	ledstring.device = NULL;
	ledstring.freq = WS2811_TARGET_FREQ;
	ledstring.dmanum = 5;
	ledstring.channel[0].gpionum = 18;
	ledstring.channel[0].invert = 0;
	ledstring.channel[0].count = 1;
	ledstring.channel[0].brightness = 255;
	
	ledstring.channel[1].gpionum = 0;
	ledstring.channel[1].invert = 0;
	ledstring.channel[1].count = 0;
	ledstring.channel[1].brightness = 0;
	
	//char * key = strtok(args, " =");
	//char c = args;
	if (debug) printf("Setup\n");
	
	if (args!=NULL){
		while (*args){
			//first we get the key
			args = read_key(args, key,MAX_KEY_LEN);
			if (*args!=0) *args++;
			//now read the value part
			args = read_val(args, value,MAX_VAL_LEN);
			if (*args!=0) *args++;
			
			if (debug) printf("Setting %s=%s\n", key, value);
			
			if (strlen(key)>0 && strlen(value) > 0){
				if (strcmp(key,"freq")==0){
					ledstring.freq = atoi(value);
				}else if (strcmp(key, "dma")==0){
					ledstring.dmanum = atoi(value);
				}else if (strcmp(key, "channels")==0){
					if (value[0]=='1'){
						ledstring.channel[1].gpionum=0;
						ledstring.channel[1].invert = 0;
						ledstring.channel[1].count = 0;
						ledstring.channel[1].brightness = 0;
					}else{
						ledstring.channel[1].gpionum=0;
						ledstring.channel[1].invert = 0;
						ledstring.channel[1].count = 1;
						ledstring.channel[1].brightness = 255;				
					}
				}else if (strcmp(key, "channel_1_gpio")==0){
					ledstring.channel[0].gpionum=atoi(value);
				}else if (strcmp(key, "channel_1_invert")==0){
					ledstring.channel[0].invert=atoi(value);
				}else if (strcmp(key, "channel_1_count")==0){
					ledstring.channel[0].count=atoi(value);
				}else if (strcmp(key, "channel_1_brightness")==0){
					ledstring.channel[0].brightness=atoi(value);
				}else if (strcmp(key, "channel_2_gpio")==0){
					ledstring.channel[1].gpionum=atoi(value);
				}else if (strcmp(key, "channel_2_invert")==0){
					ledstring.channel[1].invert=atoi(value);
				}else if (strcmp(key, "channel_2_count")==0){
					ledstring.channel[1].count=atoi(value);
				}else if (strcmp(key, "channel_2_brightness")==0){
					ledstring.channel[1].brightness=atoi(value);
				}
			}
			//args++;
		}
	}
	
	int size = ledstring.channel[0].count;
	if (ledstring.channel[1].count> size) size= ledstring.channel[1].count;
	malloc_command_line(DEFAULT_COMMAND_LINE_SIZE + size * 6); //allocate memory for full render data

	if (ws2811_init(&ledstring)){
		perror("Initialization failed.\n");
        return;
    }
	
}