From d3d6cc97fb68ee2314a3d4a3e10f92542044c124 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Fri, 6 Sep 2024 13:25:44 +0100 Subject: [PATCH] Neopixel cmd --- DCCEXParser.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index fd13a41..3ec5710 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -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 @@ -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) { // + IODevice::write(vpin,setON); + return; + } + if (params==2) { // + for (auto pix=vpin;pix<=vpin+p[1];pix++) IODevice::write(pix,setON); + return; + } + if (params==4 || params==5) { // + 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) { // if (p[0]>0) IODevice::write(p[0],HIGH);