From 4d51c6a6121831040d717ec47edd11ea5cd48b43 Mon Sep 17 00:00:00 2001
From: ghmartin77
Date: Tue, 26 Dec 2017 00:20:38 +0100
Subject: [PATCH] FastLED

---
 LEDMatrix.cpp | 53 ++++++++++++++++++++++-------------------------------
 LEDMatrix.h   |  9 ++++-----
 2 files changed, 26 insertions(+), 36 deletions(-)

diff --git a/LEDMatrix.cpp b/LEDMatrix.cpp
index fe4d37f..16b3c76 100644
--- a/LEDMatrix.cpp
+++ b/LEDMatrix.cpp
@@ -2,9 +2,7 @@
 
 LEDMatrix::LEDMatrix(uint8_t dpin, uint8_t cpin, uint8_t aWidth,
 		uint8_t aHeight) :
-		width(aWidth), height(aHeight), noPixels(aWidth * aHeight), matrix(
-				Adafruit_WS2801(aHeight, aWidth, dpin, cpin,
-				MATRIX_RGB_FORMAT)), pixels(
+		width(aWidth), height(aHeight), noPixels(aWidth * aHeight), pixels(
 				(uint8_t*) malloc(3 * aWidth * aHeight)) {
 
 }
@@ -15,7 +13,8 @@ LEDMatrix::~LEDMatrix() {
 }
 
 void LEDMatrix::init() {
-	matrix.begin();
+	FastLED.addLeds<LPD8806, PIN_DATA, PIN_CLOCK, RGB>(leds,
+			sizeof(leds) / sizeof(leds[0]));
 }
 
 void LEDMatrix::clear() {
@@ -64,36 +63,28 @@ void LEDMatrix::update() {
 	float calibrationGreenEffectively = calibrationGreen * brightness;
 	float calibrationBlueEffectively = calibrationBlue * brightness;
 
-	if (rotation == ROTATION_180) {
-		for (uint16_t idx = 0; idx < noPixels * 3; idx = idx + 3) {
-			matrix.setPixelColor(y, x, pixels[idx] * calibrationRedEffectively,
-					pixels[idx + 1] * calibrationGreenEffectively,
-					pixels[idx + 2] * calibrationBlueEffectively);
-			if (++x >= width) {
-				++y;
-				x = 0;
-			}
+	for (uint16_t idx = 0; idx < noPixels * 3; idx = idx + 3) {
+
+		int16_t currentY = height - 1 - y - yOffset;
+
+		if (currentY >= 0) {
+			CRGB& led = leds[currentY * 4 + x];
+
+			led.r = pixels[idx] * calibrationRedEffectively;
+			led.g = pixels[idx + 1] * calibrationGreenEffectively;
+			led.b = pixels[idx + 2] * calibrationBlueEffectively;
+		} else {
+			CRGB& led = leds[(currentY + height) * 4 + x];
+
+			led.r = led.g = led.b = 0;
 		}
-	} else { // ROTATION_0
-		for (uint16_t idx = 0; idx < noPixels * 3; idx = idx + 3) {
-
-			int16_t currentY = height - 1 - y - yOffset;
-
-			if (currentY >= 0) {
-				matrix.setPixelColor(currentY, x,
-						pixels[idx] * calibrationRedEffectively,
-						pixels[idx + 1] * calibrationGreenEffectively,
-						pixels[idx + 2] * calibrationBlueEffectively);
-			} else {
-				matrix.setPixelColor(currentY + height, x, 0, 0, 0);
-			}
-			if (++x >= width) {
-				++y;
-				x = 0;
-			}
+		if (++x >= width) {
+			++y;
+			x = 0;
 		}
 	}
-	matrix.show();
+
+	FastLED.show();
 }
 
 void LEDMatrix::flip() {
diff --git a/LEDMatrix.h b/LEDMatrix.h
index faf6870..06b8724 100644
--- a/LEDMatrix.h
+++ b/LEDMatrix.h
@@ -1,11 +1,10 @@
 #ifndef LEDMATRIX_H_
 #define LEDMATRIX_H_
 
-#include "Adafruit_WS2801.h"
+#include "defines.h"
 
-#define MATRIX_RGB_FORMAT WS2801_RBG
-
-#include <Adafruit_WS2801.h>
+#define FASTLED_INTERNAL
+#include <FastLED.h>
 
 class LEDMatrix {
 public:
@@ -49,7 +48,7 @@ public:
 	}
 
 private:
-	Adafruit_WS2801 matrix;
+	CRGB leds[160];
 
 	uint8_t *pixels;
 	uint8_t width;
-- 
2.10.1.windows.1

