Crow as II-follower #250
Crow as II-follower #250
Conversation
Possibly stupid question but the And is there a reason we can't use something like |
|
super rad, nice work! opinions:
i'd like to give this a prelim test phase before doing the TT side, to make sure we like the syntax. |
|
@simonvanderveldt We could collapse them into a single An extended version of @tehn -- most programmer-y
ii.self.query = function(...)
local args = {...}
local nargs = #args
-- user can switch on nargs, or just handle them all the same?
return _
end
-- basic helper for count-of-args so it's obvious how to switch based on 'query0' vs 'query2'
ii.self.query = function(count,...)
local args = {...}
-- switch on count
return _
end
-- args are explicit to avoid varargs (which are weird in that you have to explicitly table-ify them
ii.self.query = function(count,a,b,c)
-- switch on count
-- a,b, and/or c may be nil
return _
end
-- provide args wrapped in a table with a count
ii.self.query = function(count,arg-table)
-- switch on count
-- use args[n] where n=1:3 (args[n] can be nil)
return _
end |
|
@simonvanderveldt @tehn updated to |
|
The main thing I'm not sure about is what it would look like when used in practice/which cases are relevant, so I think some examples are a good idea. |
crow now successfully receives i2c commands and queries from other i2c leader devices. Has been tested only with two crows talking to each other, either by switching leader/follower roles dynamically, or by one device leading another & querying values.
Current usage (to be added to docs):
When implementing crow's i2c follower behaviour:
First question is whether there is a better name for 'this crow' than '_c' (which is a shortcut to the
crowtable i was using elsewhere, but has largely been deprecated). Suggestions welcome. We could change the follower commands toii.crowand leaders to something differentii.remotecrow. or useii.thisorii.selffor the OO crew.Second question is whether the
queryNcallbacks should share a single callback like theii.<device>.get()commands as they are conceptually similar. Key differences are that queryN returnsNargs rather than just one, so we'd need to use varargs (...). Secondly queryN functions must return the i2c response from that function call. If no return value is provided they will return zero.I note there is a danger here that
querymessages could crash crow if the lua environment is currently active when the i2c interrupt occurs. To avoid this, we'd need to overhaul the event system to have a priority stack which feels like overkill until we start seeing crashes (i haven't seen any). As crow is a leader/follower you can send acallNmessage to a crow which knows to respond with a matchingcallNwhich is fine for crow<->crow, but not Teletype (as it can't currently act as a follower). This issue does not apply to 'input' and 'output' queries as they fetch responses in the C layer.Adding Teletype support (#55) should now be straightforward for anyone who wants to jump on that, though decisions about naming here should be reflected there.
I2C chaining (#5) should now be relatively simple to support by adding some crowlib commands to set reception i2c address. Note that sending arbitrary Lua is not yet possible as the i2c lib only buffers messages up to 9bytes (1 cmd byte, and 8 arg bytes).
Fixes #17
Fixes #220
Improves (but doesn't necessarily close) #221 (up to 16 queued commands won't be dropped)
Here's an example script where 2 crows work together to count as fast as possible. It will make
druideat a lot of CPU cycles as it processes & displays the data.