MCPcopy Create free account
hub / github.com/FastLED/FastLED / setSliderValue

Method setSliderValue

src/platforms/shared/ui/json/json_console.cpp.hpp:216–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214}
215
216bool JsonConsole::setSliderValue(const fl::string& name, float value) FL_NOEXCEPT {
217 FL_WARN("JsonConsole::setSliderValue: Looking for component '" << name.c_str() << "' with value " << value);
218 FL_WARN("JsonConsole: Component mapping size: " << mComponentNameToId.size());
219 for (const auto& pair : mComponentNameToId) {
220 FL_WARN("JsonConsole: Available component: '" << pair.first.c_str() << "' -> ID " << pair.second);
221 }
222
223 int componentId = -1;
224
225 // First, try to convert the name to an integer (numeric ID)
226 const char* cstr = name.c_str();
227 char* endptr;
228 long parsed = strtol(cstr, &endptr, 10);
229
230 if (endptr != cstr && *endptr == '\0' && parsed >= 0 && parsed <= 2147483647L) {
231 // Successfully parsed as a valid integer ID
232 componentId = static_cast<int>(parsed);
233 FL_WARN("JsonConsole: Using numeric ID: " << componentId);
234 } else {
235 // Not a valid integer, try to find component ID by name
236 auto it = mComponentNameToId.find(name);
237 int* componentIdPtr = (it != mComponentNameToId.end()) ? &it->second : nullptr;
238
239 // WORKAROUND: Handle subtle string comparison issue in some environments
240 // Try with a fresh string if the parsed name doesn't work
241 if (!componentIdPtr && name == "slider") {
242 fl::string freshKey = "slider";
243 auto it2 = mComponentNameToId.find(freshKey);
244 componentIdPtr = (it2 != mComponentNameToId.end()) ? &it2->second : nullptr;
245 }
246
247 if (!componentIdPtr) {
248 FL_WARN("JsonConsole: Component '" << name.c_str() << "' not found in mapping");
249 return false; // Component not found
250 }
251
252 componentId = *componentIdPtr;
253 FL_WARN("JsonConsole: Found component ID: " << componentId);
254 }
255
256 // Create JSON to update the component using new json
257 fl::json doc = fl::json::object();
258
259 fl::string idStr;
260 idStr += componentId;
261
262 // Send the value directly, not wrapped in a "value" object
263 doc.set(idStr, value);
264
265 // Convert to string and send to driver
266 fl::string jsonStr = doc.to_string();
267
268 FL_WARN("JsonConsole: Sending JSON to driver: " << jsonStr.c_str());
269 mUpdateEngineState(jsonStr.c_str());
270
271 // Force immediate processing of pending updates (for testing environments)
272 // In normal operation, this happens during the driver loop
273 FL_WARN("JsonConsole: Calling processJsonUiPendingUpdates()");

Callers

nothing calls this directly

Calls 8

strtolFunction · 0.85
c_strMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
setMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected