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 blink();
|
||||
void fill(CRGB color);
|
||||
|
||||
uint8_t receive_byte();
|
||||
uint16_t receive_word();
|
||||
|
47
src/main.cpp
47
src/main.cpp
@ -14,28 +14,46 @@ 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) {
|
||||
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;
|
||||
@ -46,9 +64,15 @@ void loop() {
|
||||
case 'r': cmd_random_color(); 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;
|
||||
|
Loading…
Reference in New Issue
Block a user