impl main func
This commit is contained in:
+53
-42
@@ -1,6 +1,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <hardware_led.hpp>
|
||||
#include <hardware_rfid.hpp>
|
||||
#include <hardware_serial.hpp>
|
||||
#include "hardware.pb.h"
|
||||
|
||||
// Demo for HardwareLed
|
||||
@@ -9,14 +10,24 @@ HardwareLed<2> led; // Assuming NeoPixel on pin 2 (D2 on ESP8266)
|
||||
// Demo for HardwareRfid
|
||||
HardwareRfid rfid(4, 5); // SS=D2 (GPIO4), RST=D1 (GPIO5)
|
||||
|
||||
// Demo for HardwareSerial
|
||||
ProtoSerial serial;
|
||||
|
||||
hardware_LedConfig configs[4];
|
||||
unsigned long lastChange = 0;
|
||||
int currentConfig = 0;
|
||||
|
||||
void onRfidTag(const hardware_SensorToControlMessage& msg) {
|
||||
Serial.println("Callback onRfidTag triggered");
|
||||
Serial.print("RFID Tag detected: 0x");
|
||||
Serial.println(msg.payload.rfid_reading.card_id, HEX);
|
||||
serial.sendMessage(msg);
|
||||
// Serial.println("Callback onRfidTag triggered");
|
||||
// Serial.print("RFID Tag detected: 0x");
|
||||
// Serial.println(msg.payload.rfid_reading.card_id, HEX);
|
||||
}
|
||||
|
||||
void onSerialMessage(const IncomingMessage& msg) {
|
||||
if (msg.which_payload == hardware_ControlToSensorMessage_led_config_tag) {
|
||||
led.set(msg.payload.led_config);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
@@ -24,54 +35,54 @@ void setup() {
|
||||
led.begin();
|
||||
rfid.begin();
|
||||
rfid.setCallback(onRfidTag);
|
||||
serial.begin(Serial);
|
||||
serial.setCallback(onSerialMessage);
|
||||
|
||||
// Static config
|
||||
configs[0] = {0};
|
||||
configs[0].brightness = 128;
|
||||
configs[0].duration_ms = 0;
|
||||
configs[0].which_animation_params = 3;
|
||||
configs[0].animation_params.static_params.color = 0x00FF00; // Green
|
||||
// // Static config
|
||||
// configs[0] = {0};
|
||||
// configs[0].brightness = 128;
|
||||
// configs[0].duration_ms = 0;
|
||||
// configs[0].which_animation_params = 3;
|
||||
// configs[0].animation_params.static_params.color = 0x00FF00; // Green
|
||||
|
||||
// Pulse config
|
||||
configs[1] = {0};
|
||||
configs[1].brightness = 128;
|
||||
configs[1].duration_ms = 0;
|
||||
configs[1].which_animation_params = 4;
|
||||
configs[1].animation_params.pulse_params.color = 0xFF0000; // Red
|
||||
configs[1].animation_params.pulse_params.speed_ms = 500;
|
||||
// // Pulse config
|
||||
// configs[1] = {0};
|
||||
// configs[1].brightness = 128;
|
||||
// configs[1].duration_ms = 0;
|
||||
// configs[1].which_animation_params = 4;
|
||||
// configs[1].animation_params.pulse_params.color = 0xFF0000; // Red
|
||||
// configs[1].animation_params.pulse_params.speed_ms = 500;
|
||||
|
||||
// Fade config
|
||||
configs[2] = {0};
|
||||
configs[2].brightness = 128;
|
||||
configs[2].duration_ms = 0;
|
||||
configs[2].which_animation_params = 5;
|
||||
configs[2].animation_params.fade_params.colors_count = 3;
|
||||
configs[2].animation_params.fade_params.colors[0] = 0xFF0000; // Red
|
||||
configs[2].animation_params.fade_params.colors[1] = 0x00FF00; // Green
|
||||
configs[2].animation_params.fade_params.colors[2] = 0x0000FF; // Blue
|
||||
configs[2].animation_params.fade_params.speed_ms = 1000;
|
||||
// // Fade config
|
||||
// configs[2] = {0};
|
||||
// configs[2].brightness = 128;
|
||||
// configs[2].duration_ms = 0;
|
||||
// configs[2].which_animation_params = 5;
|
||||
// configs[2].animation_params.fade_params.colors_count = 3;
|
||||
// configs[2].animation_params.fade_params.colors[0] = 0xFF0000; // Red
|
||||
// configs[2].animation_params.fade_params.colors[1] = 0x00FF00; // Green
|
||||
// configs[2].animation_params.fade_params.colors[2] = 0x0000FF; // Blue
|
||||
// configs[2].animation_params.fade_params.speed_ms = 1000;
|
||||
|
||||
// Flicker config
|
||||
configs[3] = {0};
|
||||
configs[3].brightness = 128;
|
||||
configs[3].duration_ms = 0;
|
||||
configs[3].which_animation_params = 6;
|
||||
configs[3].animation_params.flicker_params.color = 0xFFFFFF; // White
|
||||
configs[3].animation_params.flicker_params.intensity = 50;
|
||||
// // Flicker config
|
||||
// configs[3] = {0};
|
||||
// configs[3].brightness = 128;
|
||||
// configs[3].duration_ms = 0;
|
||||
// configs[3].which_animation_params = 6;
|
||||
// configs[3].animation_params.flicker_params.color = 0xFFFFFF; // White
|
||||
// configs[3].animation_params.flicker_params.intensity = 50;
|
||||
|
||||
led.set(configs[0]);
|
||||
Serial.println("Starting with static green");
|
||||
// led.set(configs[0]);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
led.update();
|
||||
rfid.update();
|
||||
serial.update();
|
||||
|
||||
if (millis() - lastChange >= 10000) {
|
||||
lastChange = millis();
|
||||
currentConfig = (currentConfig + 1) % 4;
|
||||
led.set(configs[currentConfig]);
|
||||
Serial.print("Switched to config ");
|
||||
Serial.println(currentConfig);
|
||||
}
|
||||
// if (millis() - lastChange >= 10000) {
|
||||
// lastChange = millis();
|
||||
// currentConfig = (currentConfig + 1) % 4;
|
||||
// led.set(configs[currentConfig]);
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user