From ec3412d8cd470e8cbfcfc53390f44329866eebb5 Mon Sep 17 00:00:00 2001 From: Bay Date: Tue, 18 Mar 2025 19:41:06 +0100 Subject: [PATCH] Update DisplayRPI.ts Add support for all RGB color orders --- ledder/server/drivers/DisplayRPI.ts | 100 ++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 19 deletions(-) diff --git a/ledder/server/drivers/DisplayRPI.ts b/ledder/server/drivers/DisplayRPI.ts index 0ba52f76..83c35c4e 100644 --- a/ledder/server/drivers/DisplayRPI.ts +++ b/ledder/server/drivers/DisplayRPI.ts @@ -54,25 +54,87 @@ export class DisplayRPI extends Display { const offset = this.mapper[floor_x][floor_y] - if (this.rgbOrder==0) - leds.setPixel( - ~~(offset / this.pixelsPerChannel), // channel - offset % this.pixelsPerChannel, //led nr - this.gammaMapper[Math.round(color.r)], - this.gammaMapper[Math.round(color.g)], - this.gammaMapper[Math.round(color.b)], - color.a - ) - else - leds.setPixel( - ~~(offset / this.pixelsPerChannel), // channel - offset % this.pixelsPerChannel, //led nr - this.gammaMapper[Math.round(color.g)], - this.gammaMapper[Math.round(color.r)], - this.gammaMapper[Math.round(color.b)], - color.a - ) - + /** + * For compatibility reasons 0 = RGB 1 = GRB + * 0 = RGB + * 1 = GRB + * 2 = RBG + * 3 = GBR + * 4 = BRG + * 5 = BGR + */ + + switch (this.rgbOrder) { + case 0: + leds.setPixel( + ~~(offset / this.pixelsPerChannel), // channel + offset % this.pixelsPerChannel, //led nr + this.gammaMapper[Math.round(color.r)], + this.gammaMapper[Math.round(color.g)], + this.gammaMapper[Math.round(color.b)], + color.a + ) + break; + case 1: + leds.setPixel( + ~~(offset / this.pixelsPerChannel), // channel + offset % this.pixelsPerChannel, //led nr + this.gammaMapper[Math.round(color.g)], + this.gammaMapper[Math.round(color.r)], + this.gammaMapper[Math.round(color.b)], + color.a + ) + break; + case 2: + leds.setPixel( + ~~(offset / this.pixelsPerChannel), // channel + offset % this.pixelsPerChannel, //led nr + this.gammaMapper[Math.round(color.r)], + this.gammaMapper[Math.round(color.b)], + this.gammaMapper[Math.round(color.g)], + color.a + ) + break; + case 3: + leds.setPixel( + ~~(offset / this.pixelsPerChannel), // channel + offset % this.pixelsPerChannel, //led nr + this.gammaMapper[Math.round(color.b)], + this.gammaMapper[Math.round(color.r)], + this.gammaMapper[Math.round(color.g)], + color.a + ) + break; + case 4: + leds.setPixel( + ~~(offset / this.pixelsPerChannel), // channel + offset % this.pixelsPerChannel, //led nr + this.gammaMapper[Math.round(color.g)], + this.gammaMapper[Math.round(color.r)], + this.gammaMapper[Math.round(color.b)], + color.a + ) + break; + case 5: + leds.setPixel( + ~~(offset / this.pixelsPerChannel), // channel + offset % this.pixelsPerChannel, //led nr + this.gammaMapper[Math.round(color.b)], + this.gammaMapper[Math.round(color.g)], + this.gammaMapper[Math.round(color.r)], + color.a + ) + break; + default: + leds.setPixel( + ~~(offset / this.pixelsPerChannel), // channel + offset % this.pixelsPerChannel, //led nr + this.gammaMapper[Math.round(color.r)], + this.gammaMapper[Math.round(color.g)], + this.gammaMapper[Math.round(color.b)], + color.a + ) + } }