Exemple #1
0
int main(int argc, char *argv[])
{

#ifdef IMX
	int retuid;
	retuid = setuid(0);     // root me!
    if (retuid == -1) {
        exit(-10);
    }
#endif

	// Open the pipe, write the data, close the pipe.
	pipe_fd = open("/run/pipelights.3.fifo", O_WRONLY);
	if (pipe_fd == -1) {
		printf("Failed to open pipe!\n");
		exit(-120);
	}

	since_start();	// initialize the count of when we started execution

	// Ok, we're ready to start, so call the setup
	setup();
	synchronize(1);	// And setup the sync function

	while (1) {
		loop(since_start());
		synchronize(20000000);					// 50 fps or 20 msec/frame
		send_frame(pipe_fd, 0L);				// Try to transmit the frame
	}
	close(pipe_fd);		// And close the fifo

	return 0;
}
Exemple #2
0
int main(int argc, char *argv[])
{
	int ret = 0;
	int ss, sp, j;
	int doing = 1;

#ifdef IMX
	int retuid;
	retuid = setuid(0);     // root me!
    if (retuid == -1) {
    	perror("Could not setuid.\n");
        exit(-10);
    }
#endif
	
	since_start();			// initialize the count of when we started execution
	spi_open();

	// Read the size of our LED string
	// Use the correct map for the string size
	ss = NUM_GLOBES;
	sp = ss * 3;			// Number of color units in string

	// Allocate space for the frame transmit buffer
	txbuf = malloc(sp + 3);
	txbuf[sp+1] = txbuf[sp+2] = txbuf[sp] = 0x00;		// Last byte always null for end of sequence signalling

	// Ok, we're ready to start, so call the setup
	setup(argc, argv);
	synchronize(1);	// And setup the sync function

	while (doing) {
		//memset((void*) txbuf, (int) 0x80, (size_t) sp);  // Clear the string quickly
		doing = loop(since_start());
		synchronize(20000000);					// 50 fps or 20 msec/frame
		spi_send(txbuf, (sp + 1));		// Try to transmit the frame
	}
	free(txbuf);		// Always clean up after yourself!
	spi_close();

	return 0;
}
Exemple #3
0
int main(int argc, char *argv[])
{
    int ret = 0;
    int fileDescriptor, ss, sp, j;
    int retuid;
    int doing;
    layoutloader("layout.conf.json");
    int face, row, col;


    retuid = setuid(0);     // root me!
    if (retuid == -1) {
        exit(-10);
    }

    since_start();          // initialize the count of when we started execution

    // Read the size of our LED string
    // Use the correct map for the string size
    string_size = ss = NUM_BULBS;

    sp = ss * 3;            // Number of color units in string

    // Allocate space for the frame transmit buffer
    txbuf = malloc(sp + 1);
    txbuf[sp] = 0x00;       // Last byte always null for end of sequence signalling

#ifdef OLIMEX
    gpio_map();
    gpio_output(2,1); //bank 2 bit 1 = GPIO65 the LED on board
    gpio_output(0,20); //bank 0 bit 20 = GPIO20 = SSP2_MOSI
    gpio_output(0,24); //bank 0 bit 24 = GPIO24 = SSP2_SCLK
#else
    fileDescriptor = open(device, O_RDWR);
    if (fileDescriptor < 0)
        pabort("can't open device");

    /*
     * spi mode
     */
    ret = ioctl(fileDescriptor, SPI_IOC_WR_MODE, &mode);
    if (ret == -1)
        pabort("can't set spi mode");

    ret = ioctl(fileDescriptor, SPI_IOC_RD_MODE, &mode);
    if (ret == -1)
        pabort("can't get spi mode");

    /*
     * bits per word
     */
    ret = ioctl(fileDescriptor, SPI_IOC_WR_BITS_PER_WORD, &bits);
    if (ret == -1)
        pabort("can't set bits per word");

    ret = ioctl(fileDescriptor, SPI_IOC_RD_BITS_PER_WORD, &bits);
    if (ret == -1)
        pabort("can't get bits per word");

    /*
     * max speed hz
     */
    ret = ioctl(fileDescriptor, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
    if (ret == -1)
        pabort("can't set max speed hz");

    ret = ioctl(fileDescriptor, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
    if (ret == -1)
        pabort("can't get max speed hz");

    ////("spi mode: %d\n", mode);
    ////("bits per word: %d\n", bits);
    ////("max speed: %d Hz (%d KHz)\n", speed, speed/1000);
#endif

    // Ok, we're ready to start, so call the setup
    //setup(argc,argv);
    synchronize(1);                                         // And setup the sync function
    while (doing) {

		// Clear the whole string
		// Set a bulb
		// And move on
		for (face = 0; face < 4; face++) {
			for (row = 0; row < ROWS_PER_FACE; row++) {
				for (col = 0; col < COLS_PER_FACE; col++) {
					memset((void*) txbuf, (int) 0x80, (size_t) sp);  // Clear the string quickly
					set_pixel(face, col, row, 0xFF, 0xFF, 0xFF);
					send_frame(fileDescriptor, txbuf, (sp + 3));		// Try to transmit the frame
					usleep(100000);
				}
			}
	
		}
	
		// Chase the inner LEDs
		for (face = 0; face < 4; face++) {
			for (row = 0; row < BULBS_INSIDE; row++) {
				memset((void*) txbuf, (int) 0x80, (size_t) sp);  // Clear the string quickly
				set_inner_pixel(face, row, 0xFF, 0xFF, 0xFF);
				send_frame(fileDescriptor, txbuf, (sp + 3));		// Try to transmit the frame
				usleep(100000);
			}
		}	



        /*if (loop(since_start())) {
            //doing = 0;
        }*/
        //synchronize(20000000);                              // 50 fps or 20 msec/frame
        //send_frame(fileDescriptor, txbuf, (sp + 1));        // Try to transmit the frame
    }
    free(txbuf);                                            // Always clean up after yourself!
#ifdef OLIMEX
#else
    close(fileDescriptor);
#endif
    return 0;
}