def main(): hardware = Hardware() with open(TIMESTAMPS_FILE, 'a', buffering=1) as f: try: # Use external trigger only hardware.send_message(messages.TriggerConditionMessage(0b1000000)) while True: msg = hardware.read_message() if type(msg) == messages.MeasuredDataMessage: logging.info("%s %s ns", msg.timestamp, msg.count_ticks_PPS) f.write("%s %s ns\n" % (msg.timestamp, msg.count_ticks_PPS)) except KeyboardInterrupt: print "Interrupted by user." finally: hardware.close()
p1, p2 = self.race.best_time self.p1_best_time.SetLabel("%0.2f sec" % p1) self.p2_best_time.SetLabel("%0.2f sec" % p2) for num, (old, new) in enumerate( zip(self.last_num_laps, self.race.num_laps)): if old != new: lap_list = [self.p1_lap_list, self.p2_lap_list][num] pos = lap_list.InsertStringItem(0, "%d" % new) lap_list.SetStringItem( pos, 1, "%0.2f" % (sum(self.race.laps[num]))) lap_list.SetStringItem(pos, 2, "%0.2f" % (self.race.laps[num][-1])) self.last_num_laps = self.race.num_laps if __name__ == "__main__": hardware = Hardware("/dev/ttyUSB0") race = RaceThread(hardware, [1, 1]) try: app = wx.PySimpleApp(0) wx.InitAllImageHandlers() rt = RaceTimer(app, race, None, -1, "") app.SetTopWindow(rt) rt.Show() app.MainLoop() finally: race.stop() hardware.close()