Hello, thanks for the advice dude, so i started learn Python, but now i have some questions  
 
Here is my first success :
Code: Select all
    
def onAttachHandler(self):
    e = self
    print("Phidget attached!") 
    # Get device informations and display it
    serialNumber = e.getDeviceSerialNumber()
    hubPort = e.getHubPort()
    channel = e.getChannel()
    deviceclass = e.getDeviceClassName()
    channelClassName = e.getChannelClassName()
    print("\nSerial number : " + str(serialNumber) + "\nHubPort : " + str(hubPort) 
    + "\nChannel : " + str(channel) + "\nDeviceClass : " + deviceclass + "\nChannelClass : " + channelClassName )
    # Set datainterval and voltageratiochangetrigger
    e.setDataInterval(20)
    print("\nSetting DataInterval to 20ms")
    e.setVoltageRatioChangeTrigger(0.1)
    print("Setting Voltage Ratio ChangeTrigger to 0.1")
    # Set the sensortype
    if(e.getChannelSubclass() == ChannelSubclass.PHIDCHSUBCLASS_VOLTAGERATIOINPUT_SENSOR_PORT):
        print("\tSetting VoltageRatio SensorType")
        e.setSensorType(VoltageRatioSensorType.SENSOR_TYPE_VOLTAGERATIO)
 
    
def onVoltageRatioChangeHandler(self, voltageRatio):
    print("Voltage Ratio: " + str(voltageRatio))
    keyboard = PyKeyboard()
    if voltageRatio > 0.2:
        keyboard.press_key('a')
    elif 0 < voltageRatio < 0.2:
        keyboard.release_key('a')
            
def main():
    try:
        vi = VoltageRatioInput()
    except PhidgetException as e:
        sys.stderr.write("Runtime Error -> Creating VoltageRatioInput: \n\t")
        DisplayError(e)
        raise
    except RuntimeError as e:
        sys.stderr.write("Runtime Error -> Creating VoltageRatioInput: \n\t" + e)
        raise
    
    vi.setDeviceSerialNumber(539622)
    vi.setHubPort(0)
    vi.setIsHubPortDevice(0)
    vi.setChannel(1)
    
    vi.setOnAttachHandler(onAttachHandler)
        
    print("\nSetting OnVoltageRatioChangeHandler...")
    vi.setOnVoltageRatioChangeHandler(onVoltageRatioChangeHandler)
               
    try:
        vi.openWaitForAttachment(5000)
    except PhidgetException as e:
        PrintOpenErrorMessage(e, vi)
        raise EndProgramSignal("Program Terminated: Open Failed")
    print("Sampling data for 10 seconds...")
        
    print("You can do  tuff with your Phidgets here and/or in the event handlers.")
               
    time.sleep(10)
     
main()   
    
Basically it print voltage ratio and press 'a' if > 0.2V. It work for one axe of my thumbstick.
Now i would like to make it work with the two axes simultaneously but i'm kinda stuck. I guess i have to make another main function, changing channel adress of device parameters, but how to start two function main?
The answer is the "thread" thing in think but i can't make it work without multiple errors...
Thanks for your help !