(self)
| 60 | |
| 61 | @threaded |
| 62 | def run(self): |
| 63 | first_time = True |
| 64 | latest_time = GameTime.get_time() |
| 65 | while self._run_ps: |
| 66 | if self._callback is not None: |
| 67 | current_time = GameTime.get_time() |
| 68 | |
| 69 | # Second part forces the sensors to send data at the first tick, regardless of frequency |
| 70 | if current_time - latest_time > (1 / self._reading_frequency) \ |
| 71 | or (first_time and GameTime.get_frame() != 0): |
| 72 | self._callback(GenericMeasurement(self.__call__(), GameTime.get_frame())) |
| 73 | latest_time = GameTime.get_time() |
| 74 | first_time = False |
| 75 | |
| 76 | else: |
| 77 | time.sleep(0.001) |
| 78 | |
| 79 | def listen(self, callback): |
| 80 | # Tell that this function receives what the producer does. |
no test coverage detected