def __init__(self): self.temperature = 0 if not boxsettings.FAKE_DATA: logging.debug("Not FAKE data") self.thermometer = Thermometer() else: logging.debug("Not using sensors: fake data.")
def __init__(self): super(Sensors, self).__init__() #create the sensore self.anemometer=Anemometer() self.hygrometer=Hygrometer() self.rain_gauge=RainGauge() self.thermometer=Thermometer()
def __init__(self): cntr = counter(2) meter = FluxMeter(70, 75) thermos = {} for i in range(2): thermo = Thermometer(cntr, meter) thermos[thermo.id] = thermo self.thermos = thermos
def encoding(input, num_bits = 8): inputs = [] th = Thermometer(input.data.min(), input.data.max(), num_bits) for i in range(len(input.data)): bit_array = bitarray(0) row = input.data[i] for elem in row: bit_array.extend(th.code(elem)) inputs.append({"class" : input.target[i], "bitarray": bit_array}) return inputs
def build_page(layout, page): layout.clear_widgets() links.clear() # TODO: will prevent iframe functionality to work for id, item in page.iteritems(): if item['type'] == 'button': wgt = Button() elif item['type'] == 'label': wgt = Label() elif item['type'] == 'var-label': wgt = VariableLabel() wgt.set_var(item['variable']) elif item['type'] == 'led': wgt = Led() wgt.set_var(item['variable']) elif item['type'] == 'thermometer': wgt = Thermometer() wgt.set_var(item['variable']) elif item['type'] == 'manometer': wgt = Manometer() wgt.set_var(item['variable']) elif item['type'] == 'edit-grid': wgt = EditGrid() wgt.set_dimenstion(item['rows'], item['cols']) wgt.id = id if 'text' in item: wgt.text = item['text'] if 'font-size' in item: wgt.font_size = item['font-size'] if 'pos' in item: wgt.pos = eval(item['pos']) if 'size' in item: wgt.size = eval(item['size']) if 'pos_hint' in item: wgt.pos_hint = item['pos_hint'] if 'size_hint' in item: wgt.size_hint = eval(item['size_hint']) if 'link' in item: links[wgt.id] = item['link'] wgt.bind(on_press=navigate) if 'click' in item: wgt.bind(on_press=eval(item['click'])) layout.add_widget(wgt)
from datetime import datetime from thermometer import Thermometer from program import app from flask import render_template thermo = Thermometer() timenow = str(datetime.today()) @app.route('/') @app.route('/index') def index(): tp = f"{thermo.get_temp():.2f}" tm = datetime.today().strftime("%H:%M:%S %m/%d/%Y") return render_template('index.html',time=tm,temp=tp) @app.route('/temp') def get_temp(): return f"{thermo.get_temp():.2f}°F"
def createWidget(self, parent): return Thermometer(parent)
def __init__(self, parent, cx, htrs): self.cx = cx self.htrs = htrs title = "Connection %d" % (cx + 1) wx.Frame.__init__(self, parent, wx.ID_ANY, title, (-1, -1), (-1, -1), wx.DEFAULT_FRAME_STYLE & ~(wx.CLOSE_BOX)) self.Bind(wx.EVT_CLOSE, self.onClose) sizer = wx.BoxSizer(wx.VERTICAL) sizerLeft = wx.BoxSizer(wx.VERTICAL) sizerRight = wx.BoxSizer(wx.VERTICAL) grid = wx.GridBagSizer() bfont = wx.Font(12, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD) font = wx.Font(12, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL) row = 1 t = wx.StaticText(self, wx.ID_ANY, "Printer:", size=(160, -1)) t.SetFont(bfont) grid.Add(t, (row, 0)) self.tPrtr = wx.StaticText(self, wx.ID_ANY, "", size=(200, -1)) self.tPrtr.SetFont(font) grid.Add(self.tPrtr, (row, 1)) t = wx.StaticText(self, wx.ID_ANY, "Port:") t.SetFont(bfont) grid.Add(t, (row + 1, 0)) self.tPort = wx.StaticText(self, wx.ID_ANY, "") self.tPort.SetFont(font) grid.Add(self.tPort, (row + 1, 1)) t = wx.StaticText(self, wx.ID_ANY, "Status:") t.SetFont(bfont) grid.Add(t, (row + 2, 0)) self.tStat = wx.StaticText(self, wx.ID_ANY, "") self.tStat.SetFont(font) grid.Add(self.tStat, (row + 2, 1)) sizerLeft.Add(grid) sizerLeft.AddSpacer((20, 20)) self.lFile = wx.StaticText(self, wx.ID_ANY, "") self.lFile.SetFont(bfont) sizerLeft.Add(self.lFile) self.tFile = wx.StaticText(self, wx.ID_ANY, "") self.tFile.SetFont(font) sizerLeft.Add(self.tFile) sizerLeft.AddSpacer((20, 20)) grid = wx.GridBagSizer() row = 0 self.lStartTime = wx.StaticText(self, wx.ID_ANY, "", size=(160, -1)) self.lStartTime.SetFont(bfont) grid.Add(self.lStartTime, (row, 0)) self.tStartTime = wx.StaticText(self, wx.ID_ANY, "", size=(200, -1)) self.tStartTime.SetFont(font) grid.Add(self.tStartTime, (row, 1)) self.lExpDur = wx.StaticText(self, wx.ID_ANY, "") self.lExpDur.SetFont(bfont) grid.Add(self.lExpDur, (row + 1, 0)) self.tExpDur = wx.StaticText(self, wx.ID_ANY, "") self.tExpDur.SetFont(font) grid.Add(self.tExpDur, (row + 1, 1)) self.lOrigETA = wx.StaticText(self, wx.ID_ANY, "") self.lOrigETA.SetFont(bfont) grid.Add(self.lOrigETA, (row + 2, 0)) self.tOrigETA = wx.StaticText(self, wx.ID_ANY, "") self.tOrigETA.SetFont(font) grid.Add(self.tOrigETA, (row + 2, 1)) grid.AddSpacer((10, 10), (row + 3, 0)) row += 4 self.lElapsed = wx.StaticText(self, wx.ID_ANY, "") self.lElapsed.SetFont(bfont) grid.Add(self.lElapsed, (row, 0)) self.tElapsed = wx.StaticText(self, wx.ID_ANY, "") self.tElapsed.SetFont(font) grid.Add(self.tElapsed, (row, 1)) self.lRemaining = wx.StaticText(self, wx.ID_ANY, "") self.lRemaining.SetFont(bfont) grid.Add(self.lRemaining, (row + 1, 0)) self.tRemaining = wx.StaticText(self, wx.ID_ANY, "") self.tRemaining.SetFont(font) grid.Add(self.tRemaining, (row + 1, 1)) self.lNewETA = wx.StaticText(self, wx.ID_ANY, "") self.lNewETA.SetFont(bfont) grid.Add(self.lNewETA, (row + 2, 0)) self.tNewETA = wx.StaticText(self, wx.ID_ANY, "") self.tNewETA.SetFont(font) grid.Add(self.tNewETA, (row + 2, 1)) grid.AddSpacer((20, 20), (row + 3, 0)) row += 4 self.lHeight = wx.StaticText(self, wx.ID_ANY, "") self.lHeight.SetFont(bfont) grid.Add(self.lHeight, (row, 0)) self.tHeight = wx.StaticText(self, wx.ID_ANY, "") self.tHeight.SetFont(font) grid.Add(self.tHeight, (row, 1)) self.lLayer = wx.StaticText(self, wx.ID_ANY, "") self.lLayer.SetFont(bfont) grid.Add(self.lLayer, (row + 1, 0)) self.tLayer = wx.StaticText(self, wx.ID_ANY, "") self.tLayer.SetFont(font) grid.Add(self.tLayer, (row + 1, 1)) self.lGCode = wx.StaticText(self, wx.ID_ANY, "G Code") self.lGCode.SetFont(bfont) grid.Add(self.lGCode, (row + 2, 0)) self.tGCode = wx.StaticText(self, wx.ID_ANY, "") self.tGCode.SetFont(font) grid.Add(self.tGCode, (row + 2, 1)) sizerLeft.Add(grid) sizerH = wx.BoxSizer(wx.HORIZONTAL) sizerH.AddSpacer((20, 20)) sizerH.Add(sizerLeft) sizerRight.AddSpacer((20, 20)) self.therm = {} self.therm['Bed'] = Thermometer(self, "Print Bed") sizerRight.Add(self.therm['Bed']) sizerRight.AddSpacer((10, 10)) k = "temps::connection.%d::temps::temps::HE0" % (self.cx + 1) if k in self.htrs: self.therm['HE0'] = Thermometer(self, "Hot End 0") sizerRight.Add(self.therm['HE0']) sizerRight.AddSpacer((10, 10)) k = "temps::connection.%d::temps::temps::HE1" % (self.cx + 1) if k in self.htrs: self.therm['HE1'] = Thermometer(self, "Hot End 1") sizerRight.Add(self.therm['HE1']) sizerRight.AddSpacer((10, 10)) sizerRight.AddSpacer((10, 10)) sizerH.Add(sizerRight, 1, wx.EXPAND) sizerH.AddSpacer((20, 20)) sizer.Add(sizerH) self.SetSizer(sizer) self.Layout() self.Fit()
# encoding: utf-8 from thermometer import Thermometer from resmeasure import ResMeasure import socket ip_port = ("192.168.0.150", 50052) client = socket.socket() client.connect(ip_port) while True: cont = client.recv(1024).decode() ##python 3.5 转型 # w= 0.01 c = float(cont) / 100 r = ResMeasure().get_res(c) t = Thermometer().read(r) # print('当前电阻是:','%.2f' % r,'Ω') print('当前温度是:', '%.2f' % t, '℃') client.close()
def __init__(self): self.thermometer = Thermometer() self.min = None self.max = None
from thermometer import Thermometer thermometer = Thermometer() for i in range(5): temp, when = thermometer.get_measurement() print("{} temperature = {} degrees".format(when.isoformat(), temp)) thermometer.close()
# Celsius to Fahrenheit button self.addButton(text = ">>>>", row = 2, column = 0, command = self.computeFahr) # Fahrenheit to Celsius button self.addButton(text = "<<<<", row = 2, column = 1, command = self.computeCelsius) # The controller methods def computeFahr(self): """Inputs the Celsius degrees and outputs the Fahrenheit degrees.""" degrees = self.celsiusField.getNumber() self.model.setCelsius(degrees) self.fahrField.setNumber(self.model.getFahrenheit()) def computeCelsius(self): """Inputs the Fahrenheit degrees and outputs the Celsius degrees.""" degrees = self.fahrField.getNumber() self.model.setFahrenheit(degrees) self.celsiusField.setNumber(self.model.getCelsius()) # Instantiate the model, pass it to the view, and pop up the window. if __name__ == "__main__": model = Thermometer() view = ThermometerView(model) view.mainloop()
log("File imports sucessful!") VERBOSE = True HOST = "0.0.0.0" DEVICE_PORT = 24601 ADC_PIN = 0 generate_auth_key_if_not_exists() """ Unfortunately micropython on the ESP8266 does not support threading at this point and so only 1 request can be processed at once, however this should be fine as request collisions should not occur very often. """ thermometer = Thermometer(ADC_PIN) """ log() logs the string to a text file ("log.txt") which we can have a look at incase anything goes wrong or we need to see what requests have been occuring on the device. """ log("Thermometer object instantiated!") # Connection Manager sk = socket.socket() sk.bind((HOST, DEVICE_PORT)) sk.listen(1) while True:
def build_page(layout, page): layout.clear_widgets() links.clear() # TODO: will prevent iframe functionality to work for id, item in page.iteritems(): # create instances (ids) if item['type'] == 'button': wgt = Button() if Preferences.theme != 'default': wgt.background_normal = os.path.join(util.dir_theme, Preferences.theme, 'btn_normal.png') wgt.background_down = os.path.join(util.dir_theme, Preferences.theme, 'btn_down.png') wgt.color = Preferences.foreground wgt.border = [0, 0, 0, 0] elif item['type'] == 'label': wgt = Label() if Preferences.theme != 'default': wgt.color = Preferences.foreground elif item['type'] == 'image': img_path = os.path.join(util.dir_img, item['source']) wgt = Image(source=img_path) elif item['type'] == 'textinput': wgt = TextInput() elif item['type'] == 'var-label': wgt = VariableLabel() elif item['type'] == 'led': wgt = Led() elif item['type'] == 'thermometer': wgt = Thermometer() elif item['type'] == 'manometer': wgt = Manometer() elif item['type'] == 'edit-grid': wgt = EditGrid() wgt.set_dimenstion(item['rows'], item['cols']) elif item['type'] == 'simul-grid': wgt = SimulGrid() wgt.set_dimenstion(item['rows'], item['cols']) wgt.build_network() Simulator.set_grid(wgt) elif item['type'] == 'graph': wgt = Graph() elif item['type'] == 'DatePicker': wgt = DatePicker() elif item['type'] == 'GraphLabel': wgt = GraphLabel() else: print 'Unknown component ' + item['type'] return wgt.id = id layout.add_widget(wgt) for id, item in page.iteritems(): # now can use references (id) wgt = get_widget(id) if 'text' in item: wgt.text = item['text'] if 'font_size' in item: wgt.font_size = item['font_size'] if 'pos' in item: wgt.pos = eval(item['pos']) if 'size' in item: wgt.size = eval(item['size']) if 'pos_hint' in item: wgt.pos_hint = item['pos_hint'] if 'size_hint' in item: wgt.size_hint = eval(item['size_hint']) if 'link' in item: links[wgt.id] = item['link'] wgt.bind(on_press=navigate) if 'click' in item: wgt.bind(on_press=eval(item['click'])) if 'halign' in item: wgt.halign = item['halign'] if 'multiline' in item: wgt.multiline = item['multiline'] if 'validate' in item: wgt.bind(on_text_validate=eval(item['validate'])) if 'variable' in item: wgt.set_var(item['variable']) if 'listener' in item: listeners = item['listener'].split(',') for listener in listeners: wgt.append_listener(get_widget(listener.strip())) if 'markup' in item: wgt.markup = item['markup']