GEX core repository.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gex-core/units/neopixel/unit_neopixel.c

75 lines
1.9 KiB

7 years ago
//
// Created by MightyPork on 2017/11/25.
//
#include "unit_base.h"
#include "unit_neopixel.h"
7 years ago
#define NPX_INTERNAL
7 years ago
#include "_npx_internal.h"
7 years ago
enum PinCmd_ {
CMD_CLEAR = 0,
CMD_LOAD = 1,
CMD_LOAD_U32_LE = 2,
CMD_LOAD_U32_BE = 3,
CMD_GET_LEN = 4,
7 years ago
};
/** Handle a request message */
static error_t Npx_handleRequest(Unit *unit, TF_ID frame_id, uint8_t command, PayloadParser *pp)
7 years ago
{
uint32_t len;
const uint8_t *bytes;
7 years ago
switch (command) {
/** Clear the entire strip */
7 years ago
case CMD_CLEAR:
return UU_Npx_Clear(unit);
7 years ago
/** Load packed RGB colors (length must match the strip size) */
case CMD_LOAD:;
bytes = pp_tail(pp, &len);
return UU_Npx_Load(unit, bytes, len);
7 years ago
/** Load sparse (uint32_t) colors, 0x00RRGGBB, little endian. */
7 years ago
case CMD_LOAD_U32_LE:
bytes = pp_tail(pp, &len);
return UU_Npx_LoadU32LE(unit, bytes, len);
7 years ago
/** Load sparse (uint32_t) colors, 0x00RRGGBB, big endian. */
7 years ago
case CMD_LOAD_U32_BE:
bytes = pp_tail(pp, &len);
return UU_Npx_LoadU32BE(unit, bytes, len);
7 years ago
/** Get the Neopixel strip length */
case CMD_GET_LEN:;
uint16_t count;
TRY(UU_Npx_GetCount(unit, &count));
com_respond_u16(frame_id, count);
return E_SUCCESS;
7 years ago
default:
return E_UNKNOWN_COMMAND;
7 years ago
}
}
// ------------------------------------------------------------------------
/** Unit template */
const UnitDriver UNIT_NEOPIXEL = {
.name = "NPX",
7 years ago
.description = "Neopixel RGB LED strip",
// Settings
.preInit = Npx_preInit,
.cfgLoadBinary = Npx_loadBinary,
.cfgWriteBinary = Npx_writeBinary,
.cfgLoadIni = Npx_loadIni,
.cfgWriteIni = Npx_writeIni,
// Init
.init = Npx_init,
.deInit = Npx_deInit,
// Function
.handleRequest = Npx_handleRequest,
};