Here's what I switched to a few days ago
I created bunch of mapping predicates like:
neopixel_cmd_dict( start(), _{f:'start'}).
neopixel_cmd_dict( setMode(Mode), _{f:'setMode', args:_{m:Mode}}).
neopixel_cmd_dict( setPixelColor(N, R, G, B), _{f:'setPixelColor', args:_{n:N,r:R,g:G,b:B}}).
And then:
neopixel_cmd([], []).
neopixel_cmd([CmdHead|CmdTail], [MapHead|MapTail]):-
neopixel_cmd_dict(CmdHead, MapHead),
neopixel_cmd(CmdTail, MapTail).
neopixel_cmd_json(Json, CmdList):-
neopixel_cmd(CmdList, Dict),
atom_json_dict(Json, Dict,[]).
send_neopixel_cmd(NeoPixelId, CmdList):-
neopixel_cmd_json(Json, CmdList),
publish(['Smarthome','neopixel',NeoPixelId], Json).
So now I can do things in a much more readable format like:
neopixel_init('60:01:94:1a:d0:65'):-
send_neopixel_cmd('60:01:94:1a:d0:65', [
setSpeed(3000),
setBrightness(50),
setMode(46),
start()
]).
BTW, the order for the commands should be preserved. In related code where I do almost the same thing for LCD and OLED display code I’ll set text font/color before printing a line, then changing it for another line, such as:
color(black,Black),
color(yellow,Yellow),
color(green,Green),
color(red,Red),
lcd_cmd_json(Json, [
fillScreen(Black),
setCursor(0,0),
setTextColor(Red),
setTextSize(WelcomeTextSize),
print(FormattedWelcome),
setTextColor(Green),
setTextSize(NameTextSize),
print(FormattedName),
setTextColor(Yellow),
setTextSize(WelcomeTextSize),
print(FormattedTimestamp),
setBlankTime(7200)
]).