def onQuit(self): """request clock thread to stop. thread will quit program via calling exit.""" try: if bl.get_power(): self.myThread.quit() except: self.myThread.quit()
def PIRChange(channel): global SwitchDisplay, DisplayOffCount if GPIO.input(PIRPin) == GPIO.LOW: SwitchDisplay = 0 DisplayOffCount = COUNT #print 'Tick 1-0 um ' + datetime.datetime.now().strftime("%H:%M:%S") else: SwitchDisplay = 1 print 'Tick 0-1 um ' + datetime.datetime.now().strftime("%H:%M:%S") if (screen.get_power() != True): screen.set_power(True) screen.set_brightness(255, smooth=True, duration=3) DisplayOffCount = COUNT
def __init__(self, dummy=False, *args, **kwargs): Logger.name = 'BrightnessHandler' Logger.info('BrightnessHandler: Loading brightness-module') # Dummy mode? self.dummy = dummy # Set initial values self.current = bl.get_actual_brightness() if not self.dummy else 0 self.max = bl.get_max_brightness() if not self.dummy else 100 self.status = bl.get_power() if not self.dummy else True # Register events self.register_event_type('on_brightness_change') self.register_event_type('on_power_change') super(BrightnessHandler, self).__init__(*args, **kwargs)
def query_display_state(cls): cls._display_lock.acquire() state = cls._state_unknown if DisplayController.is_raspberry_pi(): if DisplayController.is_hdmi_display(): # subprocess.run(["vcgencmd", "display_power", "1"]) state = cls._state_unknown else: # rpi 7" touchscreen if backlight.get_power(): state = cls._state_display_on else: state = cls._state_display_off else: pass cls._display_lock.release() logger.debug("Current display state %s", cls._display_states[state]) return state
def handleCommand(self, cmd): if cmd == 'playpause': self.kbd.emit_click(uinput.KEY_B) elif cmd == 'next': self.kbd.emit_click(uinput.KEY_N) elif cmd == 'previous': self.kbd.emit_click(uinput.KEY_V) elif cmd == 'phoneUp': self.kbd.emit_click(uinput.KEY_P) elif cmd == 'phoneDown': self.kbd.emit_click(uinput.KEY_O) elif cmd == 'search': self.kbd.emit_click(uinput.KEY_M) elif cmd == 'home': self.kbd.emit_click(uinput.KEY_H) elif cmd == 'brightnessUp': self.increaseBrightness() elif cmd == 'brightnessDown': self.decreaseBrightness() elif cmd == 'volumeUp': self.volumeUp() elif cmd == 'volumeDown': self.volumeDown() elif cmd == 'screenOff': bl.set_power(False) elif cmd == 'screenOn': bl.set_power(True) elif cmd == 'toggleScreen': if bl.get_power(): bl.set_power(False) else: bl.set_power(True) elif cmd == 'toggleCamera': print("Camera is " + ("running" if self.is_cam_running else "not running")) if self.is_cam_running: print("Stop camera") self.stopCamera() else: print("Start camera") self.startCamera()
def __init__(self): QtGui.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.showFullScreen() # show window in full screen self.setWindowTitle("Clock") self.setupUi(self) try: print(bl.get_power()) except: print("could not get power") # settings for widgets # buttons settings self.btnScreenOff.clicked.connect(self.onScreenOff) self.btnQuit.clicked.connect(self.onQuit) self.wifi_enabled = True self.btnWifi.clicked.connect(self.on_wifi_btn) # intialize slider self.brightnessSlider.setMinimum(12) self.brightnessSlider.setMaximum(255) try: self.brightnessSlider.setValue(bl.get_actual_brightness()) except: print("could not get brightness") self.brightnessSlider.valueChanged.connect(self.on_update_brightness) # clock #self.labelTime.clicked.connect(self.onScreenOff()) #self.labelDate.clic # buttons stop watch self.btnStartStopWatch.clicked.connect(self.startStopWatch) self.stopWatchrunning = False self.btnResetStopWatch.clicked.connect(self.resetStopWatch) # variables timer self.timerH = 0 self.timerM = 0 self.timerS = 0 # buttons timer self.btnHourPlus.clicked.connect(self.hour_plus) self.btnHourMin.clicked.connect(self.hour_min) self.btnMinPlus.clicked.connect(self.min_plus) self.btnMinMin.clicked.connect(self.min_min) self.btnSecPlus.clicked.connect(self.sec_plus) self.btnSecMin.clicked.connect(self.sec_min) # set timer buttons checkable self.btnHourPlus.setCheckable(True) self.btnTimer.clicked.connect(self.start_timer) self.btnTimerReset.clicked.connect(self.reset_timer) # buttons alarm self.btnNewAlarm.clicked.connect(self.new_alarm) self.alarms = [] ### threads #### # clock thread self.myThread = MyThread(self) self.myThread.timeElapsed.connect(self.on_myThread_updateTime) self.myThread.quitThread.connect(self.exit) self.myThread.start() # stopwatch thread self.stopWatchThread = StopWatchThread() self.stopWatchThread.secondElapsed.connect(self.onSecondElapsed) # timer thread self.timerThread = TimerThread() self.timerThread.secondElapsed.connect(self.onTimerSecondElapsed) self.timerThread.onFinished.connect(self.timer_finished) # sound self.sound_thread = None # http server self.my_server = server.CallbackServer() self.my_server.start() commandThread = CommandsThread(self) commandThread.onChangeScreen.connect(self.onScreenOff) commandThread.start()
def onScreenOff(self): try: bl.set_power(not bl.get_power()) except: print("could not change screen")
SwitchDisplay = 1 print 'Tick 0-1 um ' + datetime.datetime.now().strftime("%H:%M:%S") if (screen.get_power() != True): screen.set_power(True) screen.set_brightness(255, smooth=True, duration=3) DisplayOffCount = COUNT GPIO.setup(PIRPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(PIRPin, GPIO.BOTH, callback=PIRChange, bouncetime=50) screen.set_power(True) screen.set_brightness(255) #print 'Dim nach %d Sekunden, Aus nach %d Sekunden' % (COUNT/3, COUNT) while 1: sleep(1) if (DisplayOffCount > 0): DisplayOffCount = DisplayOffCount - 1 if (SwitchDisplay == 0): if (DisplayOffCount == 0): screen.set_power(False) elif (DisplayOffCount == COUNT / 3): screen.set_brightness(32, smooth=True, duration=3) else: if (screen.get_power() == False): screen.set_power(True) if (screen.get_actual_brightness() < 255): screen.set_brightness(255, smooth=True, duration=2)