Added code to allow DirectOutput to connect to the ESP8266.
This commit is contained in:
parent
030a37daf6
commit
772376e214
@ -20,6 +20,7 @@ void loop();
|
|||||||
|
|
||||||
void set_blink(uint8_t mode);
|
void set_blink(uint8_t mode);
|
||||||
void blink();
|
void blink();
|
||||||
|
void fill(CRGB color);
|
||||||
|
|
||||||
uint8_t receive_byte();
|
uint8_t receive_byte();
|
||||||
uint16_t receive_word();
|
uint16_t receive_word();
|
||||||
|
67
src/main.cpp
67
src/main.cpp
@ -14,41 +14,65 @@ uint16_t led_count;
|
|||||||
uint8_t blink_mode = 0;
|
uint8_t blink_mode = 0;
|
||||||
unsigned long blink_timer_ts;
|
unsigned long blink_timer_ts;
|
||||||
unsigned long blink_mode_timeout_timer_ts;
|
unsigned long blink_mode_timeout_timer_ts;
|
||||||
|
unsigned long last_data_at = 0;
|
||||||
|
bool connected = false;
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
//Serial.setRxBufferSize(1);
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.setTimeout(1);
|
|
||||||
|
|
||||||
|
//send_ack();
|
||||||
//Serial.println("Online!");
|
//Serial.println("Online!");
|
||||||
led_count = 256;
|
led_count = 256;
|
||||||
leds = new CRGB[256];
|
leds = new CRGB[256];
|
||||||
//FastLED.addLeds<WS2812B, WS2812B_PIN, GRB>(leds, 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);
|
FastLED[0].setLeds(leds, 256);
|
||||||
pinMode(STATUS_LED_PIN, OUTPUT);
|
pinMode(STATUS_LED_PIN, OUTPUT);
|
||||||
set_blink(0);
|
set_blink(0);
|
||||||
blink_timer_ts = blink_mode_timeout_timer_ts = millis();
|
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() {
|
void loop() {
|
||||||
Serial.setTimeout(1);
|
if (connected && last_data_at + 1000 < millis()) connected=false;
|
||||||
byte buffer=0;
|
byte cmd;
|
||||||
size_t received = Serial.readBytes(&buffer, 1);
|
if (Serial.available()) {
|
||||||
if (received==1) {
|
cmd = Serial.read();
|
||||||
switch(buffer) {
|
|
||||||
case 'L': cmd_length(); break;
|
switch(cmd) {
|
||||||
case 'F': cmd_fill(); break;
|
case 'L': cmd_length(); break;
|
||||||
case 'R': cmd_receive(); break;
|
case 'F': cmd_fill(); break;
|
||||||
case 'O': cmd_output(); break;
|
case 'R': cmd_receive(); break;
|
||||||
case 'C': cmd_clear(); break;
|
case 'O': cmd_output(); break;
|
||||||
case 'V': cmd_version(); break;
|
case 'C': cmd_clear(); break;
|
||||||
case 'M': cmd_get_max(); break;
|
case 'V': cmd_version(); break;
|
||||||
|
case 'M': cmd_get_max(); break;
|
||||||
case 'r': cmd_random_color(); break;
|
case 'r': cmd_random_color(); break;
|
||||||
case 't': cmd_test(); break;
|
case 't': cmd_test(); break;
|
||||||
case '?': cmd_help(); break;
|
case '?': cmd_help(); break;
|
||||||
default: send_nack(); break;
|
case 0: if (!connected) {
|
||||||
|
connected = true;
|
||||||
|
send_ack();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: send_nack(); break;
|
||||||
}
|
}
|
||||||
set_blink(1);
|
set_blink(1);
|
||||||
|
last_data_at = millis();
|
||||||
}
|
}
|
||||||
blink();
|
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() {
|
void cmd_output() {
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
send_ack();
|
send_ack();
|
||||||
@ -120,7 +151,7 @@ void cmd_fill() {
|
|||||||
uint16_t cmd_leds = receive_word();
|
uint16_t cmd_leds = receive_word();
|
||||||
CRGB color = receive_color();
|
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;
|
uint16_t end_led = first_led + cmd_leds;
|
||||||
for(uint16_t i=first_led; i<end_led; i++) {
|
for(uint16_t i=first_led; i<end_led; i++) {
|
||||||
leds[i] = color;
|
leds[i] = color;
|
||||||
|
Loading…
Reference in New Issue
Block a user