コード例 #1
0
def runSubMenu3():
    print "************************"
    print " 1: Reboot"
    print " 2: Shutdown"
    print " 3: Exit"
    print "************************"
    ssd1327.clearCanvas()
    ssd1327.putCursorandTextwithoutRefresh(0, "1: Reboot")
    ssd1327.putTextwithoutRefresh(1, "2: Shutdown")
    ssd1327.putTextwithoutRefresh(2, "3: Exit")
    ssd1327.displayCanvas()

    count = 0
    itemNum = 0
    while True:
        if button.checkButton0State(Move_Button_Pin):
            count += 1
            itemNum = count % 3
            if itemNum == 0:
                ssd1327.putTextwithRefresh(2, "3: Exit")
                ssd1327.putCursorandTextwithRefresh(0, "1: Reboot")
            elif itemNum == 1:
                ssd1327.putTextwithRefresh(0, "1: Reboot")
                ssd1327.putCursorandTextwithRefresh(1, "2: Shutdown")
            else:
                ssd1327.putTextwithRefresh(1, "2: Shutdown")
                ssd1327.putCursorandTextwithRefresh(2, "3: Exit")
        if button.checkButton0State(Enter_Exit_Button_Pin):
            if itemNum == 0:
                reboot()
            elif itemNum == 1:
                exit()
            else:
                break
        time.sleep(0.1)
コード例 #2
0
def displayNotice1():
	if DISPLAY_TYPE == 0:
		ssd1327.clearCanvas()
		ssd1327.putTextwithoutRefresh(0, "Start bluetooth")
		ssd1327.putTextwithoutRefresh(1, "pairing process")
		ssd1327.putTextwithoutRefresh(2, "on BT client device")
		ssd1327.displayCanvas()
	elif DISPLAY_TYPE == 1: 
		lcd2004.setBlinkOff()
		lcd2004.putTextwithRefresh("Start BT pairing process on BT client")
コード例 #3
0
def displayNotice3():
	if DISPLAY_TYPE == 0:
		ssd1327.clearCanvas()
		ssd1327.putTextwithoutRefresh(0, "Select a device")
		ssd1327.putTextwithoutRefresh(1, "to connect on BlueTerm")
		ssd1327.putTextwithoutRefresh(2, "and")
		ssd1327.putTextwithoutRefresh(3, "input SSID and PWD")
		ssd1327.displayCanvas()
	elif DISPLAY_TYPE == 1:
		lcd2004.setBlinkOff()
		lcd2004.putTextwithRefresh("Select a device to\nconnect on BlueTerm\nand input SSID and PWD")
コード例 #4
0
def displayNotice2():
	if DISPLAY_TYPE == 0:
		ssd1327.clearCanvas()
		ssd1327.putTextwithoutRefresh(0, "BlueTerm is ready?")
		ssd1327.putTextwithoutRefresh(2, "If yes,")
		ssd1327.putTextwithoutRefresh(3, "press 'move button'")
		ssd1327.putTextwithoutRefresh(4, "If no,")
		ssd1327.putTextwithoutRefresh(5, "press 'exit button'")
		ssd1327.displayCanvas()
	elif DISPLAY_TYPE == 1: 
		lcd2004.setBlinkOff()
		lcd2004.putTextwithRefresh("BlueTerm is ready?")
		lcd2004.putTextwithoutRefresh("\nIf yes, press ~")
		lcd2004.putTextwithoutRefresh("\n\nIf no, press $")
コード例 #5
0
def displayNotice0():
	if DISPLAY_TYPE == 0:
		ssd1327.clearCanvas()
		ssd1327.putTextwithoutRefresh(0, "Bluetooth client device")
		ssd1327.putTextwithoutRefresh(1, "is paired to RPi?")
		ssd1327.putTextwithoutRefresh(3, "If yes,")
		ssd1327.putTextwithoutRefresh(4, "press 'move button'")
		ssd1327.putTextwithoutRefresh(5, "If no,")
		ssd1327.putTextwithoutRefresh(6, "press 'exit button'")
		ssd1327.displayCanvas()
	elif DISPLAY_TYPE == 1: 
		lcd2004.setBlinkOff()
		lcd2004.putTextwithRefresh("BT client is paired?")
		lcd2004.putTextwithoutRefresh("\nIf yes, press ~")
		lcd2004.putTextwithoutRefresh("\n\nIf no, press $")
コード例 #6
0
def displaySensingResult():
	if DISPLAY_TYPE == 0: 
		ssd1327.clearCanvas()
		ssd1327.putTextwithoutRefresh(0, "EC: " + str(sensingData['ec']) + "uS")
		ssd1327.putTextwithoutRefresh(1, "pH: " + str(sensingData['ph']))
		ssd1327.putTextwithoutRefresh(2, "Air temp.: " + str(sensingData['airTemp']) + chr(176)+"C")
		ssd1327.putTextwithoutRefresh(3, "Humidity: " + str(sensingData['humidity']) + "%RH")
		ssd1327.putTextwithoutRefresh(4, "Liquid temp.: " + str(sensingData['liquidTemp']) + chr(176)+"C")
		ssd1327.displayCanvas()
	elif DISPLAY_TYPE == 1: 
		lcd2004.setBlinkOff()
		lcd2004.putTextwithRefresh("EC: " + str(sensingData['ec']) + "uS" + " pH: " + str(sensingData['ph']))
		lcd2004.putTextwithoutRefresh("\nAir temp.: " + str(sensingData['airTemp']) +"^")
		lcd2004.putTextwithoutRefresh("\n\nHumidity: " + str(sensingData['humidity']) + "%RH")
		lcd2004.putTextwithoutRefresh("\n\n\nLiq temp.: " + str(sensingData['liquidTemp']) +"^")
コード例 #7
0
def runMainMenu():
    print "************************"
    print " 1: Monitoring"
    print " 2: Wireless setup"
    print " 3: Shutdown"
    print "************************"
    # Main menu
    ssd1327.clearCanvas()
    ssd1327.putCursorandTextwithoutRefresh(0, "1: Monitoring")
    ssd1327.putTextwithoutRefresh(1, "2: Wireless setup")
    ssd1327.putTextwithoutRefresh(2, "3: Shutdown")
    ssd1327.displayCanvas()

    count = 0
    itemNum = 0
    while True:
        if button.checkButton0State(Move_Button_Pin):
            count += 1
            itemNum = count % 3

            if itemNum == 0:
                ssd1327.putTextwithRefresh(2, "3: Shutdown")
                ssd1327.putCursorandTextwithRefresh(0, "1: Monitoring")
            elif itemNum == 1:
                ssd1327.putTextwithRefresh(0, "1: Monitoring")
                ssd1327.putCursorandTextwithRefresh(1, "2: Wireless setup")
            else:
                ssd1327.putTextwithRefresh(1, "2: Wireless setup")
                ssd1327.putCursorandTextwithRefresh(2, "3: Shutdown")
        if button.checkButton0State(Enter_Exit_Button_Pin):
            if itemNum == 0:
                runSubMenu1()
                break
            elif itemNum == 1:
                runSubMenu2()
                break
            else:
                runSubMenu3()
                break
        time.sleep(0.1)
コード例 #8
0
def runSubMenu2():
    print "************************"
    print " 1: BT pairing"
    print " 2: Wi-Fi provisioning"
    print " 3: Exit"
    print "************************"
    ssd1327.clearCanvas()
    ssd1327.putCursorandTextwithoutRefresh(0, "1: BT pairing")
    ssd1327.putTextwithoutRefresh(1, "2: Wi-Fi provisioning")
    ssd1327.putTextwithoutRefresh(2, "3: Exit")
    ssd1327.displayCanvas()

    count = 0
    itemNum = 0
    while True:
        if button.checkButton0State(Move_Button_Pin):
            count += 1
            itemNum = count % 3

            if itemNum == 0:
                ssd1327.putTextwithRefresh(2, "3: Exit")
                ssd1327.putCursorandTextwithRefresh(0, "1: BT pairing")
            elif itemNum == 1:
                ssd1327.putTextwithRefresh(0, "1: BT pairing")
                ssd1327.putCursorandTextwithRefresh(1, "2: Wi-Fi provisioning")
            else:
                ssd1327.putTextwithRefresh(1, "2: Wi-Fi provisioning")
                ssd1327.putCursorandTextwithRefresh(2, "3: Exit")
        if button.checkButton0State(Enter_Exit_Button_Pin):
            if itemNum == 0:
                wifi_provisioning_app.bluetoothPairing(60)  # Seconds
                break
            elif itemNum == 1:
                wifi_provisioning_app.wifiProvisioning()
                break
            else:
                break
        time.sleep(0.1)
コード例 #9
0
def runSubMenu1():
    print "************************"
    print " 1: Start Monitoring"
    print " 2: Exit"
    print "************************"
    ssd1327.clearCanvas()
    ssd1327.putCursorandTextwithoutRefresh(0, "1: Start Monitoring")
    ssd1327.putTextwithoutRefresh(1, "2: Exit")
    ssd1327.displayCanvas()

    count = 0
    itemNum = 0
    while True:
        if button.checkButton0State(Move_Button_Pin):
            count += 1
            itemNum = count % 2

            if itemNum == 0:
                ssd1327.putTextwithRefresh(1, "2: Exit")
                ssd1327.putCursorandTextwithRefresh(0, "1: Start Monitoring")
            else:
                ssd1327.putTextwithRefresh(0, "1: Start Monitoring")
                ssd1327.putCursorandTextwithRefresh(1, "2: Exit")
        if button.checkButton0State(Enter_Exit_Button_Pin):
            if itemNum == 0:
                sensing_app.displaySensingResult()
                sensing_app.performSensing(10)  # Seconds
                while sensing_app.getEventDetectFlag() == False:
                    time.sleep(0.1)
                    pass
                sensing_app.removeEventDetect(Enter_Exit_Button_Pin)
                sensing_app.clearEventDetectFlag()
                break
            else:
                break
        time.sleep(0.1)
コード例 #10
0
def bluetoothPairing(timeout): # Timeout: seconds
	bt_pairing.readyToPairBluetooth()
	displayNotice1()
	(status, name) = bt_pairing.waitForPairingRequest(timeout)

	if status == 0:
		if DISPLAY_TYPE == 0:
			ssd1327.clearCanvas()
			ssd1327.putTextwithoutRefresh(0, "Pairing timeout,")
			ssd1327.putTextwithoutRefresh(1, "try again")
			ssd1327.displayCanvas()
		elif DISPLAY_TYPE == 1:
			lcd2004.setBlinkOff()
			lcd2004.putTextwithRefresh("Pairing timeout, try again")
	elif status == 1:
		if DISPLAY_TYPE == 0:
			ssd1327.clearCanvas()
			ssd1327.putTextwithoutRefresh(0, "Pairing successful")
			ssd1327.putTextwithoutRefresh(1, "BT client name: ")
			ssd1327.putTextwithoutRefresh(2, name)
			ssd1327.displayCanvas()
		elif DISPLAY_TYPE == 1:
			lcd2004.setBlinkOff()
			lcd2004.putTextwithRefresh("Pairing successful")
			lcd2004.putTextwithoutRefresh("\nBT client name: ")
			lcd2004.putTextwithoutRefresh("\n\n" + name)
	elif status == 2:
		if DISPLAY_TYPE == 0:
			ssd1327.clearCanvas()
			ssd1327.putTextwithoutRefresh(0, "Already connected")
			ssd1327.putTextwithoutRefresh(1, "BT client name: ")
			ssd1327.putTextwithoutRefresh(2, name)
			ssd1327.displayCanvas()
		elif DISPLAY_TYPE == 1:
			lcd2004.setBlinkOff()
			lcd2004.putTextwithRefresh("Already connected")
			lcd2004.putTextwithoutRefresh("\nBT client name: ")
			lcd2004.putTextwithoutRefresh("\n\n" + name)
	time.sleep(3)
コード例 #11
0
def wifiProvisioning():
	if wifi_provisioning.checkWlan0(): # IP has been allocated
		if DISPLAY_TYPE == 0:
			ssd1327.clearCanvas()
			ssd1327.putTextwithoutRefresh(0, "IP has been")
			ssd1327.putTextwithoutRefresh(1, "successfully allocated")
			ssd1327.putTextwithoutRefresh(2, "by WLAN AP")
			ssd1327.displayCanvas()
		elif DISPLAY_TYPE == 1:
			lcd2004.setBlinkOff()
			lcd2004.putTextwithRefresh("IP has been successfully allocated by WLAN AP")
		time.sleep(3)
	else: # IP has not been allocated	
		if DISPLAY_TYPE == 0:
			ssd1327.clearCanvas()
			ssd1327.putTextwithoutRefresh(0, "IP has not been")
			ssd1327.putTextwithoutRefresh(1, "allocated by AP")
			ssd1327.putTextwithoutRefresh(2, "Wi-Fi provisioning is")
			ssd1327.putTextwithoutRefresh(3, "needed")
			ssd1327.displayCanvas()
		elif DISPLAY_TYPE == 1:
			lcd2004.setBlinkOff()
			lcd2004.putTextwithRefresh("IP has not been allocated by WLAN AP\nWi-Fi provisioning is needed")
		time.sleep(3)
		if checkBtTerminalReadyState():	# BlueTerm is ready		
			retVal = wifi_provisioning.configureWiFi()
			if retVal == 0: # 0: Invalid input 
				if DISPLAY_TYPE == 0:
					ssd1327.clearCanvas()
					ssd1327.putTextwithoutRefresh(0, "Invalid input")
					ssd1327.displayCanvas()
				elif DISPLAY_TYPE == 1: 
					lcd2004.setBlinkOff()
					lcd2004.putTextwithRefresh("Invalid input")
			elif retVal == 1: # 1: Valid input  
				if DISPLAY_TYPE == 0:
					ssd1327.clearCanvas()
					ssd1327.putTextwithoutRefresh(0, "Valid input")
					ssd1327.putTextwithoutRefresh(1, "Rebooting...")
					ssd1327.displayCanvas()
				elif DISPLAY_TYPE == 1: 
					lcd2004.setBlinkOff()
					lcd2004.putTextwithRefresh("Valid input")		
					lcd2004.putTextwithoutRefresh("\nRebooting...")	
				wifi_provisioning.closeBtSockets()
				os.system('sudo init 6')
			elif retVal == -1: # -1: Type error
				if DISPLAY_TYPE == 0:
					ssd1327.clearCanvas()
					ssd1327.putTextwithoutRefresh(0, "Type error")
					ssd1327.displayCanvas()
				elif DISPLAY_TYPE == 1:
					lcd2004.setBlinkOff()
					lcd2004.putTextwithRefresh("Type error")
			else: # -2: I/O error
				if DISPLAY_TYPE == 0:
					ssd1327.clearCanvas()
					ssd1327.putTextwithoutRefresh(0, "I/O error")
					ssd1327.displayCanvas()
				elif DISPLAY_TYPE == 1:
					lcd2004.setBlinkOff()
					lcd2004.putTextwithRefresh("I/O error")
			time.sleep(3)
		else: # BlueTerm is not ready		
			if DISPLAY_TYPE == 0:
				ssd1327.clearCanvas()
				ssd1327.putTextwithoutRefresh(0, "If BlueTerm is ready,")
				ssd1327.putTextwithoutRefresh(1, "try again")
				ssd1327.displayCanvas()
			elif DISPLAY_TYPE == 1:
				lcd2004.setBlinkOff()
				lcd2004.putTextwithRefresh("If BlueTerm is ready, try again")
			time.sleep(3)
コード例 #12
0
def exit():
    ssd1327.clearCanvas()
    ssd1327.putTextwithoutRefresh(0, "Exiting...")
    ssd1327.displayCanvas()
    time.sleep(1)
    os.system('sudo init 0')