64 remote.bind(
"setLed", [](
int index,
int r,
int g,
int b) {
65 if (index >= 0 && index <
NUM_LEDS) {
67 FL_DBG(
"Set LED " << index <<
" to RGB(" << r <<
", " << g <<
", " << b <<
")");
71 remote.bind(
"fill", [](
int r,
int g,
int b) {
73 FL_DBG(
"Filled all LEDs with RGB(" << r <<
", " << g <<
", " << b <<
")");
83 remote.bind(
"millis", []() -> int64_t {
84 return static_cast<int64_t
>(millis());
87 remote.bind(
"micros", []() -> int64_t {
88 return static_cast<int64_t
>(micros());
94 result.set(
"brightness",
FastLED.getBrightness());
95 result.set(
"millis",
static_cast<int64_t
>(millis()));
101 if (index >= 0 && index <
NUM_LEDS) {
102 result.set(
"r",
leds[index].r);
103 result.set(
"g",
leds[index].g);
104 result.set(
"b",
leds[index].b);
106 result.set(
"error",
"Index out of range");
111 Serial.println(
"Remote RPC example ready");
115 Serial.println(
"=== RPC Schema ===");
119 Serial.print(
"Schema size: ");
121 Serial.println(
" bytes (flat tuple format)");
124 Serial.println(
"Send JSON over serial, e.g.:");
125 Serial.println(
" Commands (no return):");
126 Serial.println(R
"( {"function":"fill","args":[255,0,0]})");
127 Serial.println(R"( {"timestamp":5000,"function":"setBrightness","args":[64]})");
128 Serial.println(" Queries (with return):");
129 Serial.println(R
"( {"function":"millis","args":[]})");
130 Serial.println(R"( {"function":"getStatus","args":[]})");
131 Serial.println(R"( {"function":"getLed","args":[0]})");
132 Serial.println(" Schema:");
133 Serial.println(R
"raw( {"method":"rpc.discover","id":1})raw" " // Get RPC schema");
152 Serial.println(response.to_string().c_str());
162 while (
Serial.available()) {
164 if (c ==
'\n' || c ==
'\r')
break;
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
fl::string readSerialJson()
fl::vector< fl::json > requestQueue
fl::Remote remote([]() -> fl::optional< fl::json > { if(requestQueue.empty()) { return fl::nullopt;} auto req=fl::move(requestQueue[0]);requestQueue.erase(requestQueue.begin());return req;}, [](const fl::json &response) { responseQueue.push_back(response);})
fl::vector< fl::json > responseQueue
fl::unique_ptr< fl::Remote > remote
JSON-RPC server with scheduling support.
fl::size size() const FL_NOEXCEPT
fl::string to_string() const FL_NOEXCEPT
static json parse(const fl::string &txt) FL_NOEXCEPT
static json object() FL_NOEXCEPT
void fill_solid(CRGB *targetArray, int numToFill, const CRGB &color) FL_NOEXCEPT
Fill a range of LEDs with a solid color.
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
constexpr nullopt_t nullopt