Synchronize constants between Arduino and GUI code
scottiealexander opened this issue · 4 comments
This is just a formal reminder to @lkfink and I that we need to implement a simple constant parsing routine in python so that the GUI uses the correct constants (some assumptions might be necessary, but see below).
Just a thought, but we could potentially save ourselves even more trouble by defining a magic number that we increment each time GEMConstants.h is changed, that way the GUI can query the master Ardunio for the version that its code was compiled with and check that against the file that it parses (throwing an error on mismatch). Of course we'd still have to remember to update the magic number...
Yes, this definitely needs to happen. In googling, I've seen a few different approaches thrown around: Boost.python, swig, JSON, Cython, h2py.. or just writing our own simple regexp parser keeping in mind "gotchyas" like comments.
What do you think would be the best approach?
Ok Lauren (@lkfink), I just pushed a function for parsing defines to the dev-stateful branch. The relevant function is parse_constants()
in GEMIO.py, which takes the path to a header file and returns a dict mapping define names to strings. Note, unsigned ints are transformed into python byte string so they should be ready to send to the master Arduino. Do you want to work it into the system? The tricky part will be making sure we get the correct path (system independent) to GEMConstants.h. Let me know.
Closed by commit 35d73b1 (and the 3 previous commits). Will formally close once merged with master.
Closing because dev-stateful has been merged into main (renamed from master). The new version runs Python3, so updates have been made regarding the byte-strings.