def dsp_power(self, mode): print("dsp:_dsp_power - run") if mode == "server": from systems import SystemsData systems_data = SystemsData() self._oled.fill(0) self._oled.text('Web Server Mode', 0, 0) self._oled.text('SSID:' + systems_data.get_system_AP_SSID(), 0, 10) self._oled.text('PASS:'******'Please Access', 0, 30) self._oled.text('http://', 0, 40) self._oled.text(systems_data.get_system_AP_IP(), 0, 50) self._oled.show() elif mode == "client": self._oled.fill(0) self._oled.text('Booting...', 0, 0) self._oled.text('Client Mode', 0, 10) self._oled.show() elif mode == "done": print("dsp:dsp_pwr_done - run") self._oled.fill(0) self._oled.show() else: print("dsp:dsp_pwr - error:", mode) return
def __init__(self, snd_ques={}): ic() threading.Thread.__init__(self) self.stop_event = threading.Event() self.setDaemon(True) self._rcv_que = Queue() self._snd_ques = snd_ques self._sysdat = SystemsData() return
def __init__(self): ic() threading.Thread.__init__(self) self.stop_event = threading.Event() self.setDaemon(True) self._rcv_que = Queue() self._sysdat = SystemsData() # Setting some variables for our reset pin etc. RESET_PIN = digitalio.DigitalInOut(board.D4) TEXT = "" # Very important... This lets py-gaugette 'know' what pins to use in order to reset the display i2c = board.I2C() # oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3D, reset=RESET_PIN) self._oled = adafruit_ssd1306.SSD1306_I2C(DISP_WIDTH, DISP_HEIGHT, i2c, addr=DEVICE_ADDR, reset=RESET_PIN) # font self._font10 = ImageFont.truetype(PATH_FONT, 10) self._font12 = ImageFont.truetype(PATH_FONT, 12) self._font14 = ImageFont.truetype(PATH_FONT, 14) self._font16 = ImageFont.truetype(PATH_FONT, 16) self._font18 = ImageFont.truetype(PATH_FONT, 18) # Clear display. self._oled.fill(0) self._oled.show() return
def main(): # initial led_ctl = LedCtl() led_ctl.on_all() systems_data = SystemsData() mode = systems_data.get_system_mode() print(mode) oled_ctl = OledCtl() oled_ctl.dsp_power(mode) time.sleep(0.5) if "server" == mode: proc_server() else: asyncio.run(proc_client()) while True: time.sleep(10) return
class PreThread(threading.Thread): """ プレゼンター """ def __init__(self, snd_ques={}): ic() threading.Thread.__init__(self) self.stop_event = threading.Event() self.setDaemon(True) self._rcv_que = Queue() self._snd_ques = snd_ques self._sysdat = SystemsData() return def stop(self): ic() self.stop_event.set() return def run(self): ic() while True: # time.sleep(0.050) item = self.rcv_que.get() print("[pre_th]", "run : get : ", item) if "sw" in item["type"]: self._recvice_sw(item) elif "subsc" in item["type"]: self._recvice_subsc(item) else: print("[pre_th]", "Error : ", item) return def _recvice_sw(self, item): ic() def send_que_sw_red(): if "oled" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return val_time = "3000" val_disp = "ip" self._snd_ques["oled"].put({"type": "oled", "time": val_time, "disp": val_disp}) return def send_que_sw_blue(): if "oled" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return val_time = "3000" val_disp = self._sysdat.get_next_display() self._snd_ques["oled"].put({"type": "oled", "time": val_time, "disp": val_disp}) return name = item["name"] if "red" in name: send_que_sw_red() elif "blue" in name: send_que_sw_blue() else: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "command not found!", name) return def _recvice_subsc(self, item): ic() def send_que_led(action): ic() if "led" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return val_name = "red" if "red" in action else "blue" val_act = "on" if "on" in action else "off" self._snd_ques["led"].put({"type": "led", "name": val_name, "action": val_act}) return def send_que_buzzer(action): ic() if "buzzer" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return val_time = "500" if "short" in action else "3000" val_bfreq = "10000" self._snd_ques["buzzer"].put({"type": "buzzer", "name": "buzzer", "time": val_time, "bfreq": val_bfreq}) return def send_que_servo(action): ic() if "servo" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return val_name = "left" if "left" in action else "right" val_act = "raise" if "raise" in action else "down" self._snd_ques["servo"].put({"type": "servo", "name": val_name, "action": val_act}) return def send_que_dcm(action): ic() if "dcm" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return acts = ["forward", "back", "stop", "left", "right", "brake"] val_act = "" for act in acts: if act in action: val_act = act break val_speed = "fast" self._snd_ques["dcm"].put({"type": "dcm", "action": val_act, "speed": val_speed}) return def send_que_oled(action): ic() if "oled" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return val_time = "3000" val_disp = action.replace("oled_", "") self._snd_ques["oled"].put({"type": "oled", "time": val_time, "disp": val_disp}) return def store_twilite(msg): ic() veranda = ast.literal_eval(msg) self._sysdat.veranda_temp = veranda["temp"] self._sysdat.veranda_hum = veranda["hum"] self._sysdat.veranda_pressure = veranda["pressure"] return def store_pi0(msg): ic() room = ast.literal_eval(msg) self._sysdat.room_temp = room["temp"] self._sysdat.room_hum = room["hum"] self._sysdat.room_pressure = room["pressure"] return def store_co2m(msg): ic() room = ast.literal_eval(msg) self._sysdat.room_co2 = room["co2"] return def store_webmanga(msg): ic() # 内部に保存 webm = ast.literal_eval(msg) self._sysdat.set_webm(webm["title"], webm["episode"]) # 左腕を振って通知 val_name = "left" val_act = "swing" self._snd_ques["servo"].put({"type": "servo", "name": val_name, "action": val_act}) return action = item["action"] ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, item) if "buzzer" in action: send_que_buzzer(action) elif "servo" in action: send_que_servo(action) elif "motor" in action: send_que_dcm(action) elif "oled" in action: send_que_oled(action) elif "led" in action: send_que_led(action) elif "twilite" in action: store_twilite(item["msg"]) elif "pi0" in action: store_pi0(item["msg"]) elif "co2m" in action: store_co2m(item["msg"]) elif "webmanga" in action: store_webmanga(item["msg"]) else: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "command not found!") return @property def rcv_que(self): return self._rcv_que
class PreThread(threading.Thread): """ プレゼンター """ def __init__(self, snd_ques={}): ic() threading.Thread.__init__(self) self.stop_event = threading.Event() self.setDaemon(True) self._rcv_que = Queue() self._snd_ques = snd_ques self._sysdat = SystemsData() return def stop(self): ic() self.stop_event.set() return def run(self): ic() while True: # time.sleep(0.050) item = self.rcv_que.get() print("[pre_th]", "run : get : ", item) if "sw" in item["type"]: self._recvice_sw(item) elif "subsc" in item["type"]: self._recvice_subsc(item) else: print("[pre_th]", "Error : ", item) return def _recvice_sw(self, item): ic() def send_que_sw_no1(): if "oled" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return val_time = "3000" val_disp = "ip" self._snd_ques["oled"].put({ "type": "oled", "time": val_time, "disp": val_disp }) return def send_que_sw_no2(): if "oled" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return val_time = "3000" val_disp = self._sysdat.get_next_display() self._snd_ques["oled"].put({ "type": "oled", "time": val_time, "disp": val_disp }) return name = item["name"] if "no1" in name: send_que_sw_no1() elif "no2" in name: send_que_sw_no2() else: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "command not found!", name) return def _recvice_subsc(self, item): ic() def send_que_led(action): ic() if "led" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return val_name = "no1" if "no1" in action else "no2" val_act = "on" if "on" in action else "off" self._snd_ques["led"].put({ "type": "led", "name": val_name, "action": val_act }) return def send_que_buzzer(action): ic() if "buzzer" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return val_time = "500" if "short" in action else "3000" val_bfreq = "10000" self._snd_ques["buzzer"].put({ "type": "buzzer", "name": "buzzer", "time": val_time, "bfreq": val_bfreq }) return def send_que_servo(action): ic() if "servo" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return val_name = "left" if "left" in action else "right" val_act = "raise" if "raise" in action else "down" self._snd_ques["servo"].put({ "type": "servo", "name": val_name, "action": val_act }) return def send_que_dcm(action): ic() if "dcm" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return acts = ["forward", "back", "stop", "left", "right", "brake"] val_act = "" for act in acts: if act in action: val_act = act break val_speed = "fast" self._snd_ques["dcm"].put({ "type": "dcm", "action": val_act, "speed": val_speed }) return def send_que_oled(action): ic() if "oled" not in self._snd_ques: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "que not found!") return val_time = "3000" val_disp = action.replace("oled_", "") self._snd_ques["oled"].put({ "type": "oled", "time": val_time, "disp": val_disp }) return action = item["action"] ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, item) if "buzzer" in action: send_que_buzzer(action) elif "servo" in action: send_que_servo(action) elif "motor" in action: send_que_dcm(action) elif "oled" in action: send_que_oled(action) elif "led" in action: send_que_led(action) else: ic(sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, "command not found!") return @property def rcv_que(self): return self._rcv_que