1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-22 23:56:13 +01:00

Its working!!

This commit is contained in:
Asbelos 2024-09-06 08:08:18 +01:00
parent 235f3c82b5
commit 03d8d5f93d

View File

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