Re: asynycio as_GPS
Posted: Wed Jan 15, 2020 7:17 am
Yes. The main part of the code should read
I can see no reason why this wouldn't work, but having no Pycom hardware I can't test it.
Using a keyboard interrupt to break does ensure that str_end is written but runs the risk that the last record will be incomplete. My version polls a switch to avoid this risk, with the switch only being checked after the record has been written.
Code: Select all
with open(fn, 'w') as f:
f.write(str_start)
while True:
try:
f.write(gps.longitude_string(as_GPS.KML))
f.write(',')
f.write(gps.latitude_string(as_GPS.KML))
f.write(',')
f.write(str(gps.altitude))
f.write('\r\n')
led(off)
# for _ in range(interval * 10):
await asyncio.sleep_ms(100)
except KeyboardInterrupt:
break
f.write(str_end)
Using a keyboard interrupt to break does ensure that str_end is written but runs the risk that the last record will be incomplete. My version polls a switch to avoid this risk, with the switch only being checked after the record has been written.