CTHN.de - LEDCube - commandline client
Functions
demo.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <usb.h>
#include "../firmware/globals.h"
Include dependency graph for demo.c:

Functions

void lc_setFrame (unsigned long)
 The setFrame function.
void lc_setMode (int)
 The setMode function.
void lc_saveFrame (unsigned long, int)
void lc_init (void)
 The init function.
void lc_close (void)
 The close function.
void eeprom1 ()
void sinus1 (int max)
void demo ()
int main (int argc, char **argv)

Function Documentation

void demo ( )
{
    // stop animation
    lc_setMode(MODE_ANIMATION_STOP);

    //clear cube
    lc_setFrame(0);

    sleep(1);

    // transfer one frame
    lc_setFrame(0x06127348);

    sleep(1);

    // another frame
    lc_setFrame(0x07007007);

    sleep(1);

    // switch all led on
    lc_setFrame(0x07ffffff);

    sleep(1);

    // save animation to eeprom and animate for 60 seconds
    //eeprom1();

    //sleep(10);

    // animate with a sinus wave
    sinus1(25);

    // start animation one time
    lc_setMode(MODE_ANIMATION_SINGLE);
}

Here is the call graph for this function:

void eeprom1 ( )
{

    // lc_set animation stop
    lc_setMode(MODE_ANIMATION_STOP);

    unsigned long buf = 0;
    int tmp = 0;
    int tmp2 = 26;
    for (tmp = 0; tmp < 32; tmp++)
    {
        if (tmp < 27)
            buf = (1 << tmp);
        else
        {
            tmp2--;
            buf = (1 << tmp2);
        }

        // save to position tmp
        lc_saveFrame(buf, tmp);

    }
    //
    // lc_set mode to animate endless loop
    lc_setMode(MODE_ANIMATION_LOOP);

}

Here is the call graph for this function:

void lc_close ( )

The close function.

Returns:
NOT_CONNECTED_ERROR or return state of the usb_close function.
{
    if (_lc_handle == NULL)
        return NOT_CONNECTED_ERROR;

    return usb_close(_lc_handle);

}
void lc_init ( )

The init function.

Returns:
SUCCESSFULLY_CONNECTED or DEVICE_NOT_FOUND_ERROR.
{

    usb_init();

    /* compute lc_vid/lc_pid from usbconfig.h so that there is a central source of information */
    _lc_vid = _lc_rawVid[1] * 256 + _lc_rawVid[0];
    _lc_pid = _lc_rawPid[1] * 256 + _lc_rawPid[0];

    /* The following function is in opendevice.c: */
    if( usbOpenDevice( &_lc_handle, _lc_vid, _lc_vendor, _lc_pid, _lc_product, NULL, NULL, NULL) != 0)
    {
        fprintf(stderr, "Could not find USB device \"%s\" with lc_vid=0x%x lc_pid=0x%x\n", _lc_product, _lc_vid, _lc_pid);
        return DEVICE_NOT_FOUND_ERROR;
    }
    return SUCCESSFULLY_CONNECTED;
}
void lc_saveFrame ( unsigned  long,
int   
)
void lc_setFrame ( unsigned long  frame)

The setFrame function.

Parameters:
frameThe 32bit frame data. Bit 0-8 equals layer one; bit 9 - 17 euqals layer two; bit 18 - 26 equals layer three. the 5 MSB is the lifetime of the current frame in ISR calls (300Hz).
Returns:
NOT_CONNECTED_ERROR or the return value of the usb_control_msg function.
{

    if (_lc_handle == NULL)
        return NOT_CONNECTED_ERROR;

    int low  =  frame & 0xffff;
    int high = (frame & 0xffff0000) >> 16;

    int ret = usb_control_msg(_lc_handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME,  low, 0, _lc_buffer, 0, 300);
    ret += usb_control_msg(_lc_handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, high, 1, _lc_buffer, 0, 300);

    return ret;
}
void lc_setMode ( int  mode)

The setMode function.

Parameters:
modeThe firmware mode. MODE_ANIMATION_STOP; MODE_ANIMATION_SINGLE; MODE_ANIMATION_LOOP
Returns:
NOT_CONNECTED_ERROR or the return value of the usb_control_msg function.
{
    if (_lc_handle == NULL)
        return NOT_CONNECTED_ERROR;

    return usb_control_msg(_lc_handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_MODE, mode, 0, _lc_buffer, 0, 300);
}
int main ( int  argc,
char **  argv 
)
{

    lc_init();

    demo();

    lc_setMode(MODE_ANIMATION_LOOP);

    lc_close();

    return 0;
}

Here is the call graph for this function:

void sinus1 ( int  max)
{

    // lc_set animation stop
    lc_setMode(MODE_ANIMATION_STOP);

    int j = max;
    while (--j)
    {

        int i = 0;
        int k = 0;
        //for (i = 0; i < 360; i+=11)
        for (i = 0; i < 360; i++)
        {
            // 2 = 27
            // 1 = 27 / 2
            // n = 27 * n / 2
            double d = cos((double)((6.28*i)/360)) + 1; // 6.28 = PI * 2
            unsigned long tmp = (1 << (int)((27 * d) / 2));

            // show frame
            lc_setFrame(tmp);
            // or save the frame to eeprom
            //tmp = tmp + (k << 27);
            //if (k < 32)
                //lc_saveFrame(tmp, k, k);

            usleep(2500);
            k++;
        }

    }

}

Here is the call graph for this function:

 All Files Functions Variables Defines