Skip to content

Commit

Permalink
Neopixel <o> cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Asbelos committed Sep 6, 2024
1 parent 03d8d5f commit d3d6cc9
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions DCCEXParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Once a new OPCODE is decided upon, update this list.
M, Write DCC packet
n, Reserved for SensorCam
N, Reserved for Sensorcam
o,
o, Neopixel driver (see also IO_NeoPixel.h)
O, Output broadcast
p, Broadcast power state
P, Write DCC packet
Expand Down Expand Up @@ -394,7 +394,34 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
return;
break;

case 'z': // direct pin manipulation
#ifndef IO_NO_HAL
case 'o': // Neopixel pin manipulation
if (p[0]==0) break;
{
VPIN vpin=p[0]>0 ? p[0]:-p[0];
bool setON=p[0]>0;
if (params==1) { // <o [-]vpin>
IODevice::write(vpin,setON);
return;
}
if (params==2) { // <o [-]vpin count>
for (auto pix=vpin;pix<=vpin+p[1];pix++) IODevice::write(pix,setON);
return;
}
if (params==4 || params==5) { // <z [-]vpin r g b [count]>
uint16_t colourcode=((p[1] & 0x1F)<<11) |
((p[2] & 0x1F)<<6) |
((p[3] & 0x1F)<<1);
if (setON) colourcode |= 0x0001;
// driver treats count 0 as 1
for (auto pix=vpin;pix<=vpin+p[4];pix++) IODevice::writeAnalogue(pix,colourcode,0,0);
return;
}
}
break;
#endif

case 'z': // direct pin manipulation
if (p[0]==0) break;
if (params==1) { // <z vpin | -vpin>
if (p[0]>0) IODevice::write(p[0],HIGH);
Expand Down

0 comments on commit d3d6cc9

Please sign in to comment.