I have successfully interfaced my digital LED stripes, and at the phase where i need to control them through UART.
I am trying to figure out a way where i can send strings with functions followed by parameters or simply just color values to begin with, in following fashion:
"ledbreath 254,235,232" or "ledblink 0,235,0"
Unfortunately this kind of parsing usually ends up in nasty spaghetti code, so i was hoping perhaps anybody had any experience on how to handle this particular technique?
Unfortunately this kind of parsing usually ends up in nasty spaghetti code
That never happens to me. Sometimes I get ravioli or porkchops, but I've never gotten spaghetti.
What have you tried? Parsing the strings you show is very straightforward, IF they are strings.
Nice to hear from a pasta lover
What i have done so far is sending following sequence:
"ledblink\n"
"234\n"
"220\n"
"234\n\r"
Which i have implemented in a statemachine, not so elegant, but quite quick and dirty. I would rather send "ledblink 234,0,23\n" in one sequence and parse this.
I would rather send "ledblink 234,0,23\n" in one sequence and parse this.
So, do it. Collect the data in a string (a NULL terminated char array), and then use strtok() to parse it, and atoi() to convert (some of) the tokens to numbers.
I would rather send "ledblink 234,0,23\n" in one sequence and parse this.
So, do it. Collect the data in a string (a NULL terminated char array), and then use strtok() to parse it, and atoi() to convert (some of) the tokens to numbers.