- HIN1100_0 thumbstick
- HIN1000_0 thumbstick touchpad
- HUB0000_0 VINT Hub
Does anyone have experience w wxPython to share? Particular widgets used to display data from the phidgets? Lessons' learned?
Code: Select all
# -*- coding: utf-8 -*-
from Phidget22.Devices.TemperatureSensor import *
from Phidget22.Devices.HumiditySensor import *
from Phidget22.Net import *
import wx
ct = TemperatureSensor()
ch = HumiditySensor()
try:
ct.openWaitForAttachment(500)
ch.openWaitForAttachment(500)
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Press Enter to Exit...\n")
readin = sys.stdin.read(1)
exit(1)
app = wx.App()
temp = ct.getTemperature()
ct.close()
humd = ch.getHumidity()
ch.close()
# simple dialog
wx.MessageBox('Temperature: %0.2fC \n==============\n Humidity: %0.2f%%' % (temp, humd), 'Environment', wx.OK)
#print("Serial: %s Temperature: %0.2f°C" % (ct.getDeviceSerialNumber(), ct.getTemperature()))
#print("Serial: %s Humidity: %0.2f%%" % (ch.getDeviceSerialNumber(), ch.getHumidity()))
Code: Select all
from time import sleep
import sys
import wx
from Phidget22.Devices.VoltageRatioInput import *
minPress = 29
maxPress = 33
if len(sys.argv) > 1:
if sys.argv[1] in ['?', 'help', 'Help', 'HELP', '/?', '/h', '/help']:
print "1st argument is minimum pressure in PA to consider outake, " \
"2nd is max for intake \n min default:29 \n max default 33"
a = raw_input("any key to continue")
sys.exit(0)
minPress = sys.argv[1]
maxPress = sys.argv[2]
PresArray = []
def VoltageRatioChangeHandler(e, voltageRatio):
# print("VoltageRatio: %f" % voltageRatio)
# print("SensorValue: %f" % cp.getSensorValue())
pressure = 1000 * ((5 * cp.getSensorValue()) - 2.5)
PresArray.append(pressure)
# print ("Pressure in PA: %f" % pressure)
cp = VoltageRatioInput()
cp.setDeviceSerialNumber(-1)
cp.setHubPort(1)
cp.setIsHubPortDevice(1)
cp.setChannel(0)
cp.setOnVoltageRatioChangeHandler(VoltageRatioChangeHandler)
cp.openWaitForAttachment(5000)
sleep(2)
app = wx.App()
print ("Max PA: %f" % max(PresArray))
print ("Avg PA: %f" % (sum(PresArray)/len(PresArray)))
print ("Min PA: %f" % min(PresArray))
if max(PresArray) > maxPress:
fanstat = "Intake"
elif min(PresArray) < minPress:
fanstat = "Outake"
else:
fanstat = "NoFan"
print fanstat
wx.MessageBox('Max PA: %f \n Avg PA: %f \n Min PA: %f \n %s' % (max(PresArray), (sum(PresArray)/len(PresArray)), min(PresArray), fanstat), 'Pressure', wx.OK)
cp.close()
Users browsing this forum: No registered users and 9 guests