Hi Mostafa,
Before getting into the details of your code, it's worth briefly going over the Analog_input classes functionallity, to make sure were on the same page about how an adaptation for your sensor would work.
The analog input can do two things:
1) Streams continous analog data to the GUI, which is plotted and saved in a file. This process does not generate any framework events.
2) Generates framework events on rising and/or falling threshold crossings. This only happens if rising_event or falling_event arguments are specified when it is initialised and these events are used by the current task.
As event generation triggered by threshold crossings is completely optional, I don't see why it would prevent you from subclassing the analog input. Subclassing the analog input would also make it much easier to understand your code as it would make it clear what functionallity has been modified. I would suggest not having seperate
PMW3360DM and MotionDetector classes (because you are never going to use the
PMW3360DM class indepenent of the MotionDetector) but rather having a single class that subclasses Analog_input.
Regarding the memory allocation errors when you try and acquire at high sample rates, I think the issue is caused by the fact your input is generating framework events every time it aquires a sample (unlike the analog input class which only does so on threshold crossings). Specifically, your timer_ISR function (called regularly using a hardware timer to read each new sample) puts the input's ID in the interrupt_queue, causing the framework to call it's _process_interrupt method, which generates a framework event (by putting an event in fw.event_queue). This is almost certainly not what you want because these events would be completely uniformative to the task (as they are just periodic at the sampling frequency), and will put a lot of load on the framework as it processes the high frequency stream of events. You don't need to be generating framework events in order to stream the analog input to the computer - analog data is sent to the computer by the _send_buffer method, which is called by the framework when the input puts its ID in the
stream_data_queue.
Regarding the overflow_error, I think this is happening because although it analog input class says that data type 'L' (unsigned 4 byte integer) is allowed, it looks like when the data is saved to disk by the
data_logger class, it is converted to a 4 byte signed integer. I have created an issue
here to record this bug. A workaround for you should be to just specify a datatype of 'l' (signed 4 byte integer) as you are anyway using the 4 bytes to store two 2 byte integers, rather than an unsigned 4 byte integer.
Regarding the IndexError, i'm not exactly sure what is causing this but it will be easier to debug once the other issues are fixed.
best,
Thomas