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

Method parseCommand

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

Source from the content-addressed store, hash-verified

153}
154
155void JsonConsole::parseCommand(const fl::string& command) FL_NOEXCEPT {
156 FL_WARN("JsonConsole::parseCommand: Parsing command '" << command.c_str() << "'");
157
158 // Look for pattern: "name: value"
159 i16 colonPos = command.find(':');
160 FL_WARN("JsonConsole::parseCommand: Colon position: " << colonPos);
161
162 if (colonPos == -1) {
163 writeOutput("Error: Command format should be 'name: value'");
164 return;
165 }
166
167 // Work around fl::string::substring bug - it includes the end index when it shouldn't
168 fl::string name = command.substring(0, static_cast<fl::size>(colonPos - 1));
169 fl::string valueStr = command.substring(static_cast<fl::size>(colonPos + 1), command.size());
170
171 FL_WARN("JsonConsole::parseCommand: Raw name: '" << name.c_str() << "'");
172 FL_WARN("JsonConsole::parseCommand: Raw valueStr: '" << valueStr.c_str() << "'");
173
174 // Trim whitespace from name and value
175 while (!name.empty() && name[name.size()-1] == ' ') {
176 name = name.substring(0, name.size()-1);
177 }
178 while (!valueStr.empty() && valueStr[0] == ' ') {
179 valueStr = valueStr.substring(1, valueStr.size());
180 }
181
182 FL_WARN("JsonConsole::parseCommand: Trimmed name: '" << name.c_str() << "'");
183 FL_WARN("JsonConsole::parseCommand: Trimmed valueStr: '" << valueStr.c_str() << "'");
184
185 if (name.empty() || valueStr.empty()) {
186 writeOutput("Error: Both name and value are required");
187 return;
188 }
189
190 // Try to parse value as float
191 float value = 0.0f;
192 const char* cstr = valueStr.c_str();
193 char* endptr;
194 double parsed = strtod(cstr, &endptr);
195 if (endptr == cstr || *endptr != '\0') {
196 writeOutput("Error: Invalid numeric value");
197 return;
198 }
199 value = static_cast<float>(parsed);
200
201 // Try to set the slider value
202 if (setSliderValue(name, value)) {
203 fl::string response = "Set ";
204 response += name;
205 response += " to ";
206 response += valueStr;
207 writeOutput(response);
208 } else {
209 fl::string error = "Error: Component '";
210 error += name;
211 error += "' not found";
212 writeOutput(error);

Callers

nothing calls this directly

Calls 6

strtodFunction · 0.85
substringMethod · 0.80
c_strMethod · 0.45
findMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected