I am reading a byte data stream from a serial port. This data stream is from a Bluetooth LE (BLE) Scanner application, so when it’s detecting 10 more BLE devices, and their advertising data packets, we looking at a good amount of data streaming through, which then needs to be parsed.
I found that I had to use noloop() method and only update (loop) when required, to ensure that the app functioned smoothly. This works pretty well, but it’s a little messy if not careful when to loop / not loop etc. especially when I try to add in screen animation using a vector motion dynamics (that’s my end goal).
I then tried creating a separate
thread() to process and parse the serial data as received (it uses the polling method inside a while loop). This seems to work pretty well too and sharing of global data between my newly created thread and the main draw thread all seems to work seamlessly.
However, under certain app failures I need to restart and this is where it gets confusing.
So, how do I check the runtime state of my newly created thread.
I see in the JAVA documentation there is such a function, but I am not sure how to include this as the processing function
thread() does not return a thread id and so I have no reference.
I basically want to check if the thread has terminated or is still running.
Here’s an example where I simply assume the run state based on observation. I have within my application logic an event which requires the user to click on a button on the screen to continue processing. This seems to terminate my new thread (but I have no way of confirming) and so in this case I simply added in another
thread("same function name") upon button click event and my application then continues to process the serial data. I have no idea if this has created a duplicate thread or it simply overrides the old thread with the same name etc.
I am trying to get some visibility here.
Any guidance / tips will greatly appreciated.