1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-26 17:46:14 +01:00

Compare commits

..

No commits in common. "d3d6cc97fb68ee2314a3d4a3e10f92542044c124" and "235f3c82b5c8e94106bc63dfd5f2957b423f1601" have entirely different histories.

2 changed files with 23 additions and 53 deletions

View File

@ -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, Neopixel driver (see also IO_NeoPixel.h)
o,
O, Output broadcast
p, Broadcast power state
P, Write DCC packet
@ -394,34 +394,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
return;
break;
#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
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);

View File

@ -153,15 +153,12 @@ private:
_nPins=nPins;
_I2CAddress = i2cAddress;
_brightness=2; // TODO 0,1,2,3
_redOffset=4+(mode >> 4 & 0x03);
_greenOffset=4+(mode >> 2 & 0x03);
_blueOffset=4+(mode & 0x03);
if (4+(mode >>6 & 0x03) == _redOffset) _bytesPerPixel=3;
_redOffset=mode >> 4 & 0x03;
_greenOffset=mode >> 2 & 0x03;
_blueOffset=mode & 0x03;
if ((mode >>6 & 0x03) == _redOffset) _bytesPerPixel=3;
else _bytesPerPixel=4; // string has a white byte.
_kHz800=(mode & NEO_KHZ400)==0;
_showPendimg=false;
// In dccex there are only 2 bytes per pixel
pixelBuffer=(uint16_t *) calloc(_nPins,sizeof(uint16_t)); // all pixels off
addDevice(this);
}
@ -186,18 +183,12 @@ private:
const byte pinbuffer[] = {SEESAW_NEOPIXEL_BASE, SEESAW_NEOPIXEL_PIN,SEESAW_PIN15};
I2CManager.write(_I2CAddress, pinbuffer, sizeof(pinbuffer));
for (auto pin=0;pin<_nPins;pin++) transmit(pin);
// but in dccex there are only 2 bytes per pixel
pixelBuffer=(uint16_t *) calloc(_nPins,sizeof(uint16_t)); // all pixels off
_display();
}
// loop called by HAL supervisor
void _loop(unsigned long currentMicros) override {
if (!_showPendimg) return;
byte showBuffer[]={SEESAW_NEOPIXEL_BASE,SEESAW_NEOPIXEL_SHOW};
I2CManager.write(_I2CAddress,showBuffer,sizeof(showBuffer));
_showPendimg=false;
}
// read back pixel colour (rarely needed I suspect)
int _readAnalogue(VPIN vpin) override {
if (_deviceState == DEVSTATE_FAILED) return 0;
@ -231,12 +222,12 @@ private:
void _writeAnalogue(VPIN vpin, int colour, uint8_t ignore1, uint16_t ignore2) override {
(void) ignore1;
(void) ignore2;
if (_deviceState == DEVSTATE_FAILED) return;
auto newColour=(uint16_t)colour;
if (_deviceState == DEVSTATE_FAILED) return;
auto pin=vpin-_firstVpin;
if (pixelBuffer[pin]==newColour) return;
pixelBuffer[pin]=newColour;
transmit(pin);
pixelBuffer[pin]=newColour;
transmit(pin);
}
// Display device information and status.
@ -257,10 +248,10 @@ private:
void transmit(uint16_t pin, bool show=true) {
byte buffer[]={SEESAW_NEOPIXEL_BASE,SEESAW_NEOPIXEL_BUF,0x00,0x00,0x00,0x00,0x00};
byte buffer[8]={SEESAW_NEOPIXEL_BASE,SEESAW_NEOPIXEL_BUF,0x00,0x00,0x00,0x00,0x00};
uint16_t offset= pin * _bytesPerPixel;
buffer[2]=(byte)(offset>>8);
buffer[3]=(byte)(offset & 0xFF);
buffer[3]=(byte)(offset &0xFF);
auto colour=pixelBuffer[pin];
if (colour & NEOPIXEL_ON_FLAG) {
buffer[_redOffset]=(colour>>11 & 0x1F) <<_brightness;
@ -270,8 +261,14 @@ private:
// Transmit pixel to driver
I2CManager.write(_I2CAddress,buffer,4 +_bytesPerPixel);
_showPendimg=true;
if (show) {
// Show, but only if after previous 300uS
while((micros() - lastShowTime) < 300L);
byte showBuffer[]={SEESAW_NEOPIXEL_BASE,SEESAW_NEOPIXEL_SHOW};
I2CManager.write(_I2CAddress,showBuffer,sizeof(showBuffer));
lastShowTime=micros();
}
}
uint16_t* pixelBuffer = nullptr;
byte _brightness;
@ -279,7 +276,7 @@ private:
byte _redOffset;
byte _greenOffset;
byte _blueOffset;
bool _showPendimg;
unsigned long lastShowTime=0;
bool _kHz800;
};