def __init__(self, **kwargs): self.pulseox = CmsPulseOx() self.pulseox.set_loadfile("dump.pkl") # self.pulseox.set_serial() super(PulseOxApp, self).__init__(**kwargs)
#!/usr/bin/env python # # Simply dump out the CMS-P protocol from the serial port # import serial from cmspulseox import CmsPulseOx RETRIES_MAX = 10 pulseox = CmsPulseOx() pulseox.set_savefile("dump.pkl") pulseox.set_serial() count = 0 retries = RETRIES_MAX for tstamp, packet in pulseox.read(): if pulseox.parse(packet): print "{0:10.02f}:{1}".format(tstamp, pulseox.dump()) else: print "bad packet" count += 1 if (count > 10000): break pulseox.stop_saving()
class PulseOxApp(App): def __init__(self, **kwargs): self.pulseox = CmsPulseOx() self.pulseox.set_loadfile("dump.pkl") # self.pulseox.set_serial() super(PulseOxApp, self).__init__(**kwargs) def clock_tick(self, dt): # This works because pulseox.read() is a generator, but # we only want to process one packet at a time otherwise # we risk harming app performance for tstamp, packet in self.pulseox.read(): if self.pulseox.parse(packet): # print self.pulseox.dump() # updates the various widgets around the outside self.pulse_rate.text = str(self.pulseox.pulserate) self.strength.text = str(self.pulseox.strength) self.search.text = "SEARCH" if self.pulseox.search else "" self.seek.text = "SEEK" if self.pulseox.seek else "" self.error.text = "ERROR" if self.pulseox.error else "" self.beep.text = "BEEP" if self.pulseox.beep else "" self.o2sat.text = str(self.pulseox.o2_sat) + " %" self.tstamp.text = time.strftime(" %H:%M:%S\n%a %d %b %Y",time.localtime(tstamp)) self.waveform.update_waveform(self.pulseox.waveform) self.waveform.update_o2sat(self.pulseox.o2_sat, self.pulseox.o2_low) return def build(self): self.top_layout = BoxLayout(orientation = 'vertical') self.l1_layout = BoxLayout(orientation = 'horizontal', size_hint = (1, .9)) self.bottom_bar_layout = BoxLayout(orientation = 'horizontal', size_hint = (1, .1)) self.right_bar_layout = BoxLayout(orientation = 'vertical', size_hint = (.2, 1)) self.top_layout.add_widget(self.l1_layout) self.top_layout.add_widget(self.bottom_bar_layout) self.waveform = PulseOxWaveform( pos_hint = {'top':0}, size_hint = (.8, .9)) self.strength = Button(text = 'strength') self.search = Button(text = 'search') self.seek = Button(text = 'seek') self.error = Button(text = 'error') self.beep = Button(text = 'beep') self.tstamp = Button(text = 'time') self.bottom_bar_layout.add_widget(self.strength) self.bottom_bar_layout.add_widget(self.search) self.bottom_bar_layout.add_widget(self.seek) self.bottom_bar_layout.add_widget(self.error) self.bottom_bar_layout.add_widget(self.beep) self.bottom_bar_layout.add_widget(self.tstamp) self.pulse_rate = Button(text = 'rate', size_hint = (1, .2), font_size = 18) self.o2sat = Button(text = 'O2 sat', size_hint = (1, .2), font_size = 18) self.bargraph = Button(text = 'bar', size_hint = (1, .6)) self.right_bar_layout.add_widget(self.pulse_rate) self.right_bar_layout.add_widget(self.o2sat) self.right_bar_layout.add_widget(self.bargraph) self.l1_layout.add_widget(self.waveform) self.l1_layout.add_widget(self.right_bar_layout) # fire the clock constantly Clock.schedule_interval(self.clock_tick, 0) return self.top_layout def update_waveform(self, height): print "PulseOxApp.update_waveform()" self.waveform.update_waveform(height)
#!/usr/bin/env python # # Simply dump out the CMS-P protocol from the serial port # from cmspulseox import CmsPulseOx pulseox = CmsPulseOx() pulseox.set_loadfile("dump.pkl") for tstamp, packet in pulseox.read(): if pulseox.parse(packet): print "{0:10.02f}:{1}".format(tstamp, pulseox.dump())