Skip to content

Commit

Permalink
o Make APA102 work (RGB is actualy BGR; also byte-pos was not updated).
Browse files Browse the repository at this point in the history
  • Loading branch information
hzeller committed May 30, 2016
1 parent b7faf14 commit 7bb1d19
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/led-strip.cc
Expand Up @@ -82,9 +82,9 @@ class LPD6803LedStrip : public LEDStrip {
if (pos < 0 || pos >= count_) return;
uint16_t data = 0;
data |= (1<<15); // start bit
data |= luminance_cie1931(5, c.r) << 10;
data |= luminance_cie1931(5, c.r) << 10;
data |= luminance_cie1931(5, c.g) << 5;
data |= luminance_cie1931(5, c.b) << 0;
data |= luminance_cie1931(5, c.b) << 0;

spi_->SetBufferedByte(gpio_, 2 * pos + 4 + 0, data >> 8);
spi_->SetBufferedByte(gpio_, 2 * pos + 4 + 1, data & 0xFF);
Expand All @@ -100,7 +100,7 @@ class APA102LedStrip : public LEDStrip {
APA102LedStrip(MultiSPI *spi, int gpio, int count)
: LEDStrip(count), spi_(spi), gpio_(gpio) {
const size_t startframe_size = 4;
const size_t endframe_size = 8 + 8*(count / 16);
const size_t endframe_size = (count+15) / 16;
const size_t bytes_needed = startframe_size + 4*count + endframe_size;

spi_->RegisterDataGPIO(gpio, bytes_needed);
Expand All @@ -125,9 +125,9 @@ class APA102LedStrip : public LEDStrip {
const uint8_t global_brigthness = 0x1F; // full brightness for now
const int base = 4 + 4 * pos;
spi_->SetBufferedByte(gpio_, base + 0, 0xE0 | global_brigthness);
spi_->SetBufferedByte(gpio_, base + 1, luminance_cie1931(8, c.r));
spi_->SetBufferedByte(gpio_, base + 1, luminance_cie1931(8, c.g));
spi_->SetBufferedByte(gpio_, base + 1, luminance_cie1931(8, c.b));
spi_->SetBufferedByte(gpio_, base + 2, luminance_cie1931(8, c.g));
spi_->SetBufferedByte(gpio_, base + 3, luminance_cie1931(8, c.r));
}

private:
Expand Down

0 comments on commit 7bb1d19

Please sign in to comment.