// Byte quads in the string are interpreted as (brightness, B, G, R) values.
// Only the first 5 bits of the brightness value is actually used (0-31).
// This function does not corrupt your buffer.
//
// apa102.write(1, 3, string.char(31, 0, 255, 0)) uses GPIO5 for DATA and GPIO0 for CLOCK and sets the first LED green, with the brightness 31 (out of 0-32)
// apa102.write(5, 6, string.char(255, 0, 0, 255):rep(10)) uses GPIO14 for DATA and GPIO12 for CLOCK and sets ten LED to red, with the brightness 31 (out of 0-32).
// Brightness values are clamped to 0-31.
staticintapa102_write(lua_State*L){
uint8_tdata_pin=luaL_checkinteger(L,1);
MOD_CHECK_ID(gpio,data_pin);
uint32_talt_data_pin=pin_num[data_pin];
uint8_tclock_pin=luaL_checkinteger(L,2);
MOD_CHECK_ID(gpio,clock_pin);
uint32_talt_clock_pin=pin_num[clock_pin];
size_tbuf_len;
constchar*buf=luaL_checklstring(L,3,&buf_len);
uint32_tnbr_frames=buf_len/4;
if(nbr_frames>100000){
returnluaL_error(L,"The supplied buffer is too long, and might cause the callback watchdog to bark.");