Update triangle waveform function to match pslab-android
bessman opened this issue · 4 comments
fossasia/pslab-hardware#111
fossasia/pslab-android#2364
The triangle waveform generated by pslab-android was messed up due to a difference in how the modulo operator is handled in Python and Java. pslab-python uses this function:
y = abs(x % 4 - 2) - 1, -1 <= x < 3
In Python, -1 % 4 == 3, so this results in:
But in Java, the modulo operator return the negative remainder if the dividend is negative; -1 % 4 == -1, so this function instead results in:
pslab-android now uses this function instead:
y = abs(x % 4 - 2), 0 <= x < 4
Which results in:
This function should also be used in pslab-python, for two reasons:
- We want to minimize differences between pslab-python and pslab-android
- As the bug in pslab-android demonstrates, it is unwise to rely on the behavior of the modulo operator with negative numbers
Since this change will change pslab-python's observerble behavior (i.e. the bytes it sends over serial), it will be necessary to re-record the serial traffic for the associated test case.
i want to work on this issue.
@bessman Is this issue still open ?
Yes.