diff --git a/led-matrix.cc b/led-matrix.cc index d8e223a..c962909 100644 --- a/led-matrix.cc +++ b/led-matrix.cc @@ -74,7 +74,7 @@ void RGBMatrix::ClearScreen() { void RGBMatrix::SetPixel(uint8_t x, uint8_t y, uint8_t red, uint8_t green, uint8_t blue) { - if (x > 31 || y > 31) return; + if (x >= kColumns || y > 31) return; // TODO: re-map values to be luminance corrected (sometimes called 'gamma'). // Ideally, we had like 10PWM bits for this, but we're too slow for that :/ diff --git a/led-matrix.h b/led-matrix.h index a2b41e4..12d4781 100644 --- a/led-matrix.h +++ b/led-matrix.h @@ -1,3 +1,4 @@ +// -*- c++ -*- // Controlling a 32x32 RGB matrix via GPIO. #ifndef RPI_RGBMATRIX_H @@ -18,13 +19,16 @@ class RGBMatrix { // thread. void UpdateScreen(); + int columns() { return kColumns; } + private: GPIO *const io_; enum { + kChainedBoards = 1, // Number of boards that are daisy-chained. kRows = 16, - kColumns = 32, - kPWMBits = 7 // maximum PWM resolution. + kColumns = kChainedBoards * 32, + kPWMBits = 7 // maximum PWM resolution. }; union IoBits { diff --git a/main.cc b/main.cc index e7438b4..6ba9116 100644 --- a/main.cc +++ b/main.cc @@ -153,16 +153,18 @@ public: } void Run() { + const int columns = matrix_->columns(); while (running_) { if (image_ == NULL) { usleep(100 * 1000); continue; } usleep(30 * 1000); - for (int x = 0; x < 32; ++x) { + for (int x = 0; x < columns; ++x) { for (int y = 0; y < 32; ++y) { const Pixel &p = getPixel((horizontal_position_ + x) % width_, y); - int disp_x = 31 - x; // Display upside down on my desk. Lets flip :) + // Display upside down on my desk. Lets flip :) + int disp_x = columns - x; int disp_y = 31 - y; matrix_->SetPixel(disp_x, disp_y, p.red, p.green, p.blue); }