Added code to allow DirectOutput to connect to the ESP8266.

This commit is contained in:
Fabian Schlenz 2020-07-28 06:54:14 +02:00
parent 030a37daf6
commit 772376e214
2 changed files with 50 additions and 18 deletions

View File

@ -20,6 +20,7 @@ void loop();
void set_blink(uint8_t mode);
void blink();
void fill(CRGB color);
uint8_t receive_byte();
uint16_t receive_word();

View File

@ -14,41 +14,65 @@ uint16_t led_count;
uint8_t blink_mode = 0;
unsigned long blink_timer_ts;
unsigned long blink_mode_timeout_timer_ts;
unsigned long last_data_at = 0;
bool connected = false;
void setup() {
//Serial.setRxBufferSize(1);
Serial.begin(9600);
Serial.setTimeout(1);
//send_ack();
//Serial.println("Online!");
led_count = 256;
leds = new CRGB[256];
//FastLED.addLeds<WS2812B, WS2812B_PIN, GRB>(leds, 256);
FastLED.addLeds<APA102, LED_DATA_PIN, LED_CLOCK_PIN, GRB, DATA_RATE_MHZ(1)>(leds, 256);
FastLED.addLeds<APA102, LED_DATA_PIN, LED_CLOCK_PIN, RGB, DATA_RATE_MHZ(1)>(leds, 256);
FastLED[0].setLeds(leds, 256);
pinMode(STATUS_LED_PIN, OUTPUT);
set_blink(0);
blink_timer_ts = blink_mode_timeout_timer_ts = millis();
/* fill(CRGB::DarkRed);
delay(250);
fill(CRGB::DarkGreen);
delay(250);
fill(CRGB::DarkBlue);
delay(250); */
fill(CRGB::Black);
// CLear the receive buffer
while (Serial.available()) { Serial.read(); }
}
void loop() {
Serial.setTimeout(1);
byte buffer=0;
size_t received = Serial.readBytes(&buffer, 1);
if (received==1) {
switch(buffer) {
case 'L': cmd_length(); break;
case 'F': cmd_fill(); break;
case 'R': cmd_receive(); break;
case 'O': cmd_output(); break;
case 'C': cmd_clear(); break;
case 'V': cmd_version(); break;
case 'M': cmd_get_max(); break;
if (connected && last_data_at + 1000 < millis()) connected=false;
byte cmd;
if (Serial.available()) {
cmd = Serial.read();
switch(cmd) {
case 'L': cmd_length(); break;
case 'F': cmd_fill(); break;
case 'R': cmd_receive(); break;
case 'O': cmd_output(); break;
case 'C': cmd_clear(); break;
case 'V': cmd_version(); break;
case 'M': cmd_get_max(); break;
case 'r': cmd_random_color(); break;
case 't': cmd_test(); break;
case '?': cmd_help(); break;
default: send_nack(); break;
case 't': cmd_test(); break;
case '?': cmd_help(); break;
case 0: if (!connected) {
connected = true;
send_ack();
}
break;
default: send_nack(); break;
}
set_blink(1);
last_data_at = millis();
}
blink();
}
@ -110,6 +134,13 @@ void blink() {
}
}
void fill(CRGB color) {
for (int i=0; i<led_count; i++) {
leds[i] = color;
}
FastLED.show();
}
void cmd_output() {
FastLED.show();
send_ack();
@ -120,7 +151,7 @@ void cmd_fill() {
uint16_t cmd_leds = receive_word();
CRGB color = receive_color();
if (first_led <= led_count && cmd_leds>0 && first_led + cmd_leds + 1 <= led_count) {
if (first_led <= led_count && cmd_leds>0 && first_led + cmd_leds <= led_count) {
uint16_t end_led = first_led + cmd_leds;
for(uint16_t i=first_led; i<end_led; i++) {
leds[i] = color;