def update_labels(self): ''' Function takes the RAM database and push it out to file.''' ''' All label widgets are updated on the screen. ''' # Get the process time it takes to update the tags. self.start_time = time.clock() # Send all current tags to database to be saved. DataBase.refresh_tag_database() DataBase.set_value('h_datetime', time.strftime("%H:%M")) for each_widget in self.builder.get_objects(): try: if type(each_widget) == Gtk.Label: if (each_widget.get_name() in DataBase.tags): tagname = str(each_widget.get_name()) value = DataBase.get_value(tagname) each_widget.set_label(str(value)) # print(tagname + str(value)) except: print(each_widget.get_name() + str(" not found durring window refresh.")) # Update all Widget Labels on the HMI. # for each_tag in DataBase.tags: # try: # widget = self.builder.get_object(each_tag) # tag = DataBase.get_value(str(each_tag)) # widget.set_label(str(tag)) # except: # pass # print(self.window_name + " Tags updated: {:.3f} ms.".format((time.clock() - self.start_time)*1000)) return True
def __init__(self, scale_number, address): if (address == 8): self.address = 0x08 elif (address == 9): self.address = 0x09 elif (address == 10): self.address = 0x10 self.scale_number = str(scale_number) self.h_scale_address = 'h_scale_' + self.scale_number + '_address' DataBase.set_value(self.h_scale_address, address) self.h_scale_name = 'h_scale_' + self.scale_number + '_name' self.h_scale_style = 'h_scale_' + self.scale_number + '_style' self.h_scale_brewdate = 'h_scale_' + self.scale_number + '_brewdate' self.h_scale_brewstyle = 'h_scale_' + self.scale_number + '_brewstyle' self.h_scale_actual = 'h_scale_' + self.scale_number + '_actual' self.h_scale_raw_actual = 'h_scale_' + self.scale_number + '_raw_actual' self.h_scale_tare = 'h_scale_' + self.scale_number + '_tare' self.h_scale_raw_tare = 'h_scale_' + self.scale_number + '_raw_tare' self.h_scale_zero = 'h_scale_' + self.scale_number + '_zero' self.h_scale_raw_zero = 'h_scale_' + self.scale_number + '_raw_zero' self.h_scale_span = 'h_scale_' + self.scale_number + '_span' self.h_scale_raw_span = 'h_scale_' + self.scale_number + '_raw_span' self.h_scale_decimal = 'h_scale_' + self.scale_number + '_decimal' self.busy = False self.update_seconds = 1 self.start_timers() print("Scale " + str(self.scale_number) + " created.")
def _update_weight(self): x = self._get_command(10) if (x == False): pass else: DataBase.set_value(self.h_scale_raw_actual, str(x)) ymin = float(DataBase.get_value(self.h_scale_zero)) ymax = float(DataBase.get_value(self.h_scale_span)) xmin = float(DataBase.get_value(self.h_scale_raw_zero)) xmax = float(DataBase.get_value(self.h_scale_raw_span)) try: m = (ymax - ymin) / (xmax - xmin) except: m = 0.0 b = ymin - (m * xmin) y = (m * x) + b decimal = DataBase.get_value(self.h_scale_decimal) result = str(y / pow(10, int(decimal))) truncated_result = result[0:(result.find('.') + 1 + int(decimal))] DataBase.set_value(self.h_scale_actual, truncated_result) if (self.read_scale_timer.get_status() == False): print('Scale ' + self.scale_number + ' has timed out, manually reconnect.')
def read_switch(self): self.busy = True try: self.pin_state = GPIO.input(self.pin_number) #print(GPIO.input(self.pin_number)) except: self.pin_state = 1 if (self.pin_state == 0): DataBase.set_value(self.door_switch_temp, 'open') else: DataBase.set_value(self.door_switch_temp, 'closed') self.busy = False
def read_sensor(self): self.busy = True try: sensor = W1ThermSensor() self.new_input = sensor.get_temperature() #print(self.new_input) self.filtered = ( (1.0 - self.filter_k) * self.filtered_previous) + (self.filter_k * self.new_input) self.filtered_previous = self.filtered temp = '{0:.1f}'.format(self.filtered) DataBase.set_value(self.h_temperature, temp) except Exception as e: self.read_sensor_timer.error() print("Temperature Sensor reading failed. " + str(e) + '.') DataBase.set_value(self.h_temperature, 'Error') self.busy = False
def run_compressor(self): if self.error_state == False: self.busy = True temp = DataBase.get_value('h_temperature') if (temp == 'Error'): DataBase.set_value('h_door_switch', 'STOPPED') GPIO.output(self.pin_number, 0) else: temp = float(temp) #try: if (temp > 4.0): DataBase.set_value('h_door_switch', 'RUNNING') GPIO.output(self.pin_number, 1) elif (temp < 2.0): DataBase.set_value('h_door_switch', 'STOPPED') GPIO.output(self.pin_number, 0) else: pass else: print("Compressor is in error state.") self.busy = False
def push_enter(self, *args): DataBase.set_value(DataBase.get_local_value('keyboard_variable'), DataBase.get_local_value('keyboard_buffer'))