|
1 | 1 |
|
2 | 2 | import npyfile
|
3 | 3 |
|
4 |
| -# mpremote mip install "github:peterhinch/micropython-async/v3/primitives" |
5 |
| -from primitives import Pushbutton |
6 |
| - |
7 | 4 | import asyncio
|
8 | 5 | import os
|
9 | 6 | import time
|
|
13 | 10 |
|
14 | 11 |
|
15 | 12 | def format_time(secs):
|
16 |
| - year, month, day, hour, minute, second, _, _ = time.gmtime(secs) |
| 13 | + tt = time.gmtime(secs) |
| 14 | + year, month, day, hour, minute, second, _, _ = tt[0:8] |
17 | 15 | formatted = f'{year:04d}-{month:02d}-{day:02d}T{hour:02d}:{minute:02d}:{second:02d}'
|
18 | 16 | return formatted
|
19 | 17 |
|
@@ -68,13 +66,15 @@ def process(self, data):
|
68 | 66 | out_path = f'{self._directory}/{time_str}_{self._classname}{self._suffix}'
|
69 | 67 | out_typecode = 'h'
|
70 | 68 | out_shape = (3, self._recording_samples)
|
71 |
| - self._recording_file = npyfile.Writer(open(out_path, 'w'), out_shape, out_typecode) |
| 69 | + self._recording_file_path = out_path |
| 70 | + self._recording_file = npyfile.Writer(open(out_path, 'wb'), out_shape, out_typecode) |
| 71 | + self._recording_file._write_header() |
72 | 72 | print(f'record-file-open t={t:.3f} file={out_path}')
|
73 | 73 |
|
74 | 74 | # TODO: avoid writing too much at end of file
|
75 | 75 | self._recording_file.write_values(data)
|
76 | 76 | print(f'recorder-write-chunk t={t:.3f}')
|
77 |
| - if self._recording_file.written_bytes > 3*2*self._recording_samples: |
| 77 | + if self._recording_file.written_bytes >= 3*2*self._recording_samples: |
78 | 78 | # rotate file
|
79 | 79 | self.close()
|
80 | 80 | print(f'record-file-rotate t={t:.3f}')
|
|
0 commit comments