Ejemplo n.º 1
0
/**
 * send data in chain to hardware (only use this if hardware doesn't show data right after
 * data is received to avoid blanking. If the data is shown immediately, you have
 * to transmit it in _show() 
 */
NftResult _send(void *privdata, LedChain * c, LedCount count, LedCount offset)
{
        NFT_LOG(L_DEBUG, "Sending LDP8806 data");

        struct priv *p = privdata;
        uint8_t *buf = led_chain_get_buffer(c);

        /* seek to offset */
        int bytes_per_component =
                led_chain_get_buffer_size(c) / led_chain_get_ledcount(c);
        buf += offset * bytes_per_component;

        /* send buffer */
        return spiTxData(p->fd, buf, bytes_per_component * count);
}
Ejemplo n.º 2
0
/**
 * send data in chain to hardware (only use this if hardware doesn't show data right away
 * to avoid blanking)
 */
NftResult _send(void *privdata, LedChain * c, LedCount count, LedCount offset)
{

        NFT_LOG(L_NOISY, "Sending %d LEDs (Offset: %d)", count, offset);


        Niftylino *n = privdata;

        if(!n || !n->usb_handle)
                NFT_LOG_NULL(NFT_FAILURE);


        char *buffer = led_chain_get_buffer(c);

        if(usb_bulk_write(n->usb_handle, 1, buffer,
                          led_chain_get_buffer_size(c), n->usb_timeout) < 0)
        {
                return NFT_FAILURE;
        }

        return NFT_SUCCESS;

}
Ejemplo n.º 3
0
/**
 * send data in chain to hardware (only use this if hardware doesn't show data right after
 * data is received to avoid blanking. If the data is shown immediately, you have
 * to transmit it in _show() 
 */
NftResult _send(void *privdata, LedChain * c, LedCount count, LedCount offset)
{
        NFT_LOG(L_DEBUG, "Sending arduino-max72xx data");

        struct priv *p = privdata;

        /* 8 bits-per-pixel buffer as given by niftyled */
        unsigned char *buffer = led_chain_get_buffer(c);
        /* 1 bit-per-pixel buffer as needed by arduino */
        unsigned char packed[64];

        /* clear buffer */
        memset(packed, 0, sizeof(packed));

        /* convert to 8bpp to 1bpp */
        LedCount i;
        for(i = 0; i < p->ledcount; i++)
        {
                packed[i / 8] = packed[i / 8] << 1;

                if(buffer[i] >= p->threshold)
                        packed[i / 8] |= 1;
        }


        NFT_LOG(L_NOISY, "Packed buffer: %x %x %x %x %x %x %x %x",
                packed[0], packed[1], packed[2], packed[3],
                packed[4], packed[5], packed[6], packed[7]);


        /* send buffer */
        ad_sendBuffer(p, packed,
                      (p->ledcount % 8 ==
                       0 ? p->ledcount / 8 : p->ledcount / 8 + 1));

        return NFT_SUCCESS;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
        nft_log_level_set(L_DEBUG);

        /* register new dummy hardware called "nlo01" */
        LedHardware *h;
        if(!(h = led_hardware_new("nlo01", "dummy")))
        {
                NFT_LOG(L_ERROR, "Hardware creation FAILED");
                return -1;
        }

        /* initialize any hardware that can be found (id="*"), define 12
         * connected LEDs (4 BGR pixels). Greyscale data should be provided in
         * unsigned 8-bit format */
        if(!led_hardware_init(h, "*", 12, "BGR u8"))
        {
                NFT_LOG(L_ERROR, "failed to initialize hardware");
                return -1;
        }


                /**********************************************************************
		 * niftyled basically provides 2 ways to send data to LED hardware:
		 * 
		 * 1.  set "raw" greyscale value of a LED in a chain connected to a
		 *     correctly initialized LED hardware
		 * 
		 * 1.1 use the API to set each greyscale value
		 * 
		 * 1.2 directly write to the RAW buffer
		 *
		 *
		 * 2. send a complete pixelframe and have niftyled translate that to 
		 *    mapped LEDs connected to one or more LED hardware devices 
		 *    according to the current setup configuration (where each LED
		 *    has been assigned a X/Y coordinate and a "Component" that refers 
		 *    to a component of a pixel at this position in the pixelframe)
		 */


                /****** METHOD 1.1 *******/
        /* get chain of this hardware */
        LedChain *c = led_hardware_get_chain(h);

        /* set all LEDs to half brightness */
        LedCount l;
        for(l = 0; l < led_chain_get_ledcount(c); l++)
        {
                led_chain_set_greyscale(c, l, 128);
        }

        /* send data to hardware */
        led_hardware_send(h);

        /* show previously sent hardware (latch to LEDs) */
        led_hardware_show(h);



                /****** METHOD 1.2 *******/
        /* ...or access raw pixelbuffer */
        uint8_t *pixels = led_chain_get_buffer(c);

        /* walk all pixels to turn on all LEDs */
        int i;
        for(i = 0; i < 16; i++)
                pixels[i] = 0xff;

        /* send data to hardware */
        led_hardware_send(h);

        /* show previously sent hardware (latch to LEDs) */
        led_hardware_show(h);


                /****** METHOD 2 - s. ledcat sources *******/


        /* deinitialize hardware */
        led_hardware_deinit(h);

        return 0;

}