Hi Shawn, thanks for checking in.
I am collecting the microphone data in the default way that the produced code from EI does. What I did is simply cut all of the EI code from the loop() function and slap it into a routine that is called when “nothing else is happening” i.e. when no buttons have been pressed and no lights are flashing etc.
I don’t have any interrupts, however the simple state machine I’ve made is completely non-blocking, so I suspect that if all of my debugging print statements are turned off, the code will spend the vast majority of time recording/listening/inferencing from the microphone.
But, when a button is pushed, that routine will no longer be called because the state machine is now handling the behaviors, driving motors, flashing lights etc. When those behaviors timeout (using millis() functions throughout) then the state machine will start calling the EI function again.
As in the reply above, I am now calling “run_classifier_init();” when the state machine exits so that in the next cycle through, the EI routine might be ready to start recording/listening again. I don’t know however, if I am properly terminating the EI routine. I simply stop calling it when a button is pressed. It’s possible that I should be clearing a buffer or something else so that, together with the init, it’s fully ready to start fresh again. If you have a suggestion for what to call when exiting the tasks in your default loop() or when re-entering your loop() I would really like to know.
One thing that concerns me is that in the EI generated function called “microphone_inference_record()” there is the dreaded delay, it’s actually “delay(1)”, which seems to be waiting for the buffer to fill up. Despite that it is only delaying for 1 millisecond, that’s like 99.99999% of the cycles available on this 32MHz NRF processor You suggested I make the other parts of the process short - they are all basically nothing, i.e. 1 or 2 clock cycles, but the EI generated function just mentioned is likely dominating in a bad way, causing button presses to be missed. If you have a suggestion for how to gracefully remove the “delay(1)” from your code I would like to know, and humbly suggest that you replace it in your standard code generation routine so that it becomes non blocking.
Your suggestion about running the classifier on a separate thread probably would work but I don’t have the skill to implement that yet.