some more cleanup
Next up: Move loadData into isrHandler, if possible. To Do: redo single-color methods
This commit is contained in:
parent
1a99df4214
commit
40c05bd53f
|
|
@ -10,7 +10,9 @@ Pixel::Pixel(int pin, uint32_t nPixels){
|
|||
|
||||
rmt_isr_register(isrHandler,(void *)this,0,NULL); // end-transmission interrupt automatically enabled by rmt_tx_start
|
||||
rmt_set_tx_thr_intr_en(rf->getChannel(),true,8); // need to also enable threshold interrupt
|
||||
|
||||
channelNum=rf->getChannel();
|
||||
txEndMask=TxEndMask(channelNum);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +53,6 @@ void Pixel::setColors(const uint32_t *data, uint32_t nPixels){
|
|||
status.iMem=0;
|
||||
status.iBit=24;
|
||||
status.started=true;
|
||||
status.txEndMask=TxEndMask(channelNum);
|
||||
|
||||
loadData(); // load first 2 bytes
|
||||
loadData();
|
||||
|
|
@ -92,7 +93,7 @@ void Pixel::setHSV(float h, float s, float v, int nPixels){
|
|||
|
||||
///////////////////
|
||||
|
||||
void Pixel::loadColor(color_t c, uint32_t *p){
|
||||
void Pixel::loadColor(uint32_t c, uint32_t *p){
|
||||
|
||||
uint32_t count=24;
|
||||
p+=23;
|
||||
|
|
@ -105,13 +106,13 @@ void Pixel::loadColor(color_t c, uint32_t *p){
|
|||
|
||||
///////////////////
|
||||
|
||||
color_t Pixel::getColorRGB(uint8_t r, uint8_t g, uint8_t b){
|
||||
uint32_t Pixel::getColorRGB(uint8_t r, uint8_t g, uint8_t b){
|
||||
return(g<<16 | r<<8 | b);
|
||||
}
|
||||
|
||||
///////////////////
|
||||
|
||||
color_t Pixel::getColorHSV(float h, float s, float v){
|
||||
uint32_t Pixel::getColorHSV(float h, float s, float v){
|
||||
float r,g,b;
|
||||
LedPin::HSVtoRGB(h,s/100.0,v/100.0,&r,&g,&b);
|
||||
return(getColorRGB(r*255,g*255,b*255));
|
||||
|
|
@ -143,7 +144,7 @@ void Pixel::isrHandler(void *arg){
|
|||
|
||||
Pixel *pix=(Pixel *)arg;
|
||||
|
||||
if(RMT.int_st.val & status.txEndMask){
|
||||
if(RMT.int_st.val & pix->txEndMask){
|
||||
RMT.int_clr.val=~0;
|
||||
status.started=false;
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -8,15 +8,12 @@
|
|||
#include "RFControl.h"
|
||||
#include "PwmPin.h"
|
||||
|
||||
typedef uint32_t color_t;
|
||||
|
||||
struct pixel_status_t {
|
||||
int nPixels;
|
||||
const uint32_t *data;
|
||||
int iBit;
|
||||
int iMem;
|
||||
boolean started;
|
||||
uint32_t txEndMask; // mask for end-of-transmission interrupt
|
||||
};
|
||||
|
||||
class Pixel {
|
||||
|
|
@ -24,6 +21,7 @@ class Pixel {
|
|||
uint32_t pattern[2]; // storage for zero-bit and one-bit pulses
|
||||
uint32_t resetTime; // minimum time (in usec) between pulse trains
|
||||
int channelNum; // channel number
|
||||
uint32_t txEndMask; // mask for end-of-transmission interrupt
|
||||
|
||||
uint32_t nTrain; // number of Pixels to transmit per pulse train batch
|
||||
|
||||
|
|
@ -45,7 +43,7 @@ class Pixel {
|
|||
volatile static pixel_status_t status;
|
||||
|
||||
static void isrHandler(void *arg); // interrupt handler
|
||||
void loadColor(color_t c, uint32_t *p); // creates pulse pattern for pixel color (encoded as RGB in low 24-bits of *p)
|
||||
void loadColor(uint32_t c, uint32_t *p); // creates pulse pattern for pixel color (encoded as RGB in low 24-bits of *p)
|
||||
|
||||
public:
|
||||
Pixel(int pin, uint32_t nPixels=1); // creates addressable single-wire RGB LED on pin (such as the SK68 or WS28), with OPTIONAL reserve of memory for nPixels
|
||||
|
|
@ -57,8 +55,8 @@ class Pixel {
|
|||
void setColors(const uint32_t *data, uint32_t nPixels); // sets colors of nPixels from array of Colors
|
||||
int getPin(){return(rf->getPin());} // returns pixel pin if valid, else returns -1
|
||||
|
||||
static color_t getColorRGB(uint8_t r, uint8_t g, uint8_t b); // return pixel Color from RGB values
|
||||
static color_t getColorHSV(float h, float s, float v); // return pixel Color from HSV values
|
||||
static uint32_t getColorRGB(uint8_t r, uint8_t g, uint8_t b); // return pixel Color from RGB values
|
||||
static uint32_t getColorHSV(float h, float s, float v); // return pixel Color from HSV values
|
||||
|
||||
void loadData();
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ struct Effect1 {
|
|||
|
||||
Pixel *px;
|
||||
int H=0;
|
||||
color_t x[8];
|
||||
uint32_t x[8];
|
||||
uint32_t alarmTime=0;
|
||||
uint32_t speed;
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ struct Effect2 {
|
|||
int phase=0;
|
||||
int dir=1;
|
||||
int H=0;
|
||||
color_t x[8];
|
||||
uint32_t x[8];
|
||||
uint32_t alarmTime=0;
|
||||
uint32_t speed;
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ void setup() {
|
|||
colors[4]=px.getColorRGB(40,0,0);
|
||||
colors[5]=px.getColorRGB(40,0,0);
|
||||
colors[6]=px.getColorRGB(40,0,0);
|
||||
colors[7]=px.getColorRGB(0,0,40);
|
||||
colors[7]=px.getColorRGB(0,40,0);
|
||||
|
||||
px.setColors(colors,8);
|
||||
Serial.println("\n\nDone\n\n");
|
||||
|
|
|
|||
Loading…
Reference in New Issue