Yocto-Knob: 5 Channel, USB input library.

Post your working scripts, libraries and tools
x32
Posts: 85
Joined: 25 Nov 2016, 16:44

Yocto-Knob: 5 Channel, USB input library.

13 Mar 2018, 09:09

Going along with my USB Relay library, I'm reviving my post, from the old forums, for capturing USB inputs.

Yocto-Knob: 5 Channel, USB, resistive sensing, analog-to-digital converter. HTML Library.

The Yocto-Knob device provides easy reading of 5 input buttons, contacts, switches or potentiometers (knobs) from USB. It is a kind of USB analog-to-digital converter (adc). It can also be used to read any analog resistive sensor, such as photodiodes.

Image

This is a partial library of basic functions using it's webserver interface and is dependent on the VirtualHub webserver. http://www.yoctopuce.com/FR/downloads/V ... .12553.zip

Multiple modules may by used simulaniously so most functions required the modules serial number to identify it. The serial number can be found by runiing VirtualHub and entering the following url into a web browser. http://127.0.0.1:4444/api/services/whitePages.txt. Look for the serial number that begins with "YBUTTON1" i.e. "YBUTTON1-12345" is a complete serial number.

Library functions:

Code: Select all

;;;;;;;  YoctoKnob
;  The Yocto-Knob device provides easy reading of 5 input buttons, contacts, switches or potentiometers (knobs)
; from USB. It is a kind of USB analog-to-digital converter (adc). It can also be used to read any analog resistive
; sensor, such as photodiodes.
;
;     WebSite - http://www.yoctopuce.com/EN/products/usb-sensors/yocto-knob
;     Manual - http://www.yoctopuce.com/EN/products/yocto-knob/doc/YBUTTON1.usermanual.html
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   This library is dependent on the VirtualHub webserver.
;   Download it at - http://www.yoctopuce.com/FR/downloads/VirtualHub.windows.12553.zip
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Note:  Most functions require the modules serial number, several modules may be connected to a machine.


YoctoKnob_Open(Path) ; Opens the VirtualHub webserver.  Run in autoexecute section of your script.  
    {   ;  Be sure to supply the path to VirtualHub.exe
    Run , %Path%\VirtualHub.exe, , Hide
    WinWait , %Path%\VirtualHub.exe
    WinSetTitle, %Path%\VirtualHub.exe, , YoctoKnob_Command_Window
    }

YoctoKnob_Close()   ;   Close VirtualHub webserver.
    {
    WinClose , YoctoKnob_Command_Window ahk_class ConsoleWindowClass
    }

YoctoKnob_State(ModSN)   ; Retrieves the status of the module.
    {
    Cmd = http://127.0.0.1:4444/bySerial/%ModSN%/api/module.txt
    Status := UrlDownloadToVar(Cmd)
    Return , Status
    }
    
YoctoKnob_GetBeacon(ModSN)   ;  Retrieves the status of the blue "find me" beacon.
    {
    Cmd = http://127.0.0.1:4444/bySerial/%ModSN%/api/module/beacon
    Status := UrlDownloadToVar(Cmd)
    Return , Status
    }    
    
YoctoKnob_SetBeaconOn(ModSN)   ; Turns on the "find me" beacon.  
    {     ; This allows you to locate the module when several are being used.
    Cmd = http://127.0.0.1:4444/bySerial/%ModSN%/api/module?beacon=on
    Status := UrlDownloadToVar(Cmd)
    }    

YoctoKnob_SetBeaconOff(ModSN)   ; Turns off the "find me" beacon.
    {
    Cmd = http://127.0.0.1:4444/bySerial/%ModSN%/api/module?beacon=off
    Status := UrlDownloadToVar(Cmd)
    }    

YoctoKnob_GetLum(ModSN)   ;  Retrieves the module's led brightness setting.
    {
    Cmd = http://127.0.0.1:4444/bySerial/%ModSN%/api/module/luminosity
    Status := UrlDownloadToVar(Cmd)
    Return , Status
    }    
    
YoctoKnob_SetLum(ModSN,Val)   ; Sets the module's led brightness.  A value of 0 to 100 is required.
    {
    Cmd = http://127.0.0.1:4444/bySerial/%ModSN%/api/module?luminosity=%Val%
    Status := UrlDownloadToVar(Cmd)
    }
    
YoctoKnob_ButtonVal(ModSN,Num)   ;  Retrieves the value of the inputs.  
    {     ;  Use in a timer to constantly monitor the input values.
    Cmd = http://127.0.0.1:4444/bySerial/%ModSN%/api/anButton%Num%/advertisedValue
    Status := UrlDownloadToVar(Cmd)
    Return , Status
    }
And here is a sample script:

Code: Select all

#NoEnv  
SendMode Input  
SetWorkingDir %A_ScriptDir%  
#SingleInstance , Force
DetectHiddenWindows, On
Gui , Margin, x5, y5

ModSN = YBUTTON1-12345  ;  Change to your module's serial number.
Path = %A_ScriptDir%  ; Path to VirtualHub.exe
YoctoKnob_Open(Path)
OnExit , CloseYoctoKnob

Gui , Add, Button, x5 y5 w100 gGetState, Get State
Gui , Add, Button, x135 y5 w100 gSetLum, Set Lum
Gui , Add, Edit, x240 y5 w30 r1 vLum,
Gui , Add, GroupBox, x295 y0 w100 h30, Beacon
Gui , Add, Radio, x300 y15 vBeacOn gSetBeaconOn, On
Gui , Add, Radio, x345 y15 vBeacOff gSetBeaconOff, Off

Gui , Add, Edit, x5 y35 w390 r20 vStatusEdit,

Gui , Add, Groupbox, x5 y305 w390 vgb1, Input 1
Gui , Add, Progress, x10 y320 w380 h20 Range0-1000 BackgroundBlack cBlue vpb1,

Gui , Add, Groupbox, x5 y350 w390 vgb2, Input 2
Gui , Add, Progress, x10 y365 w380 h20 Range0-1000 BackgroundBlack cBlue vpb2,

Gui , Add, Groupbox, x5 y395 w390 vgb3, Input 3
Gui , Add, Progress, x10 y410 w380 h20 Range0-1000 BackgroundBlack cBlue vpb3,

Gui , Add, Groupbox, x5 y440 w390 vgb4, Input 4
Gui , Add, Progress, x10 y455 w380 h20 Range0-1000 BackgroundBlack cBlue vpb4,

Gui , Add, Groupbox, x5 y485 w390 vgb5, Input 5
Gui , Add, Progress, x10 y500 w380 h20 Range0-1000 BackgroundBlack cBlue vpb5,

Gui , Show, x1400 w400 h600, Yocto-Knob-HTTP
GoSub , GetState
GoSub , GetLum
GoSub , GetBeacon
GoSub , GetButtons
Return

GetButtons:
SetTimer , Check, 25
Return

Check:
GoSub , Get1
GoSub , Get2
GoSub , Get3
GoSub , Get4
GoSub , Get5
GoSub , GetBeacon
Return

Get1:
Val := YoctoKnob_ButtonVal(ModSN,1)
GuiControl , , gb1 , Input 1 = %Val%
GuiControl , , pb1 , %Val%
Return

Get2:
Val := YoctoKnob_ButtonVal(ModSN,2)
GuiControl , , gb2 , Input 2 = %Val%
GuiControl , , pb2 , %Val%
Return

Get3:
Val := YoctoKnob_ButtonVal(ModSN,3)
GuiControl , , gb3 , Input 3 = %Val%
GuiControl , , pb3 , %Val%
Return

Get4:
Val := YoctoKnob_ButtonVal(ModSN,4)
GuiControl , , gb4 , Input 4 = %Val%
GuiControl , , pb4 , %Val%
Return

Get5:
Val := YoctoKnob_ButtonVal(ModSN,5)
GuiControl , , gb5 , Input 5 = %Val%
GuiControl , , pb5 , %Val%
Return

GetState:
Val := YoctoKnob_State(ModSN)
GuiControl , , StatusEdit , %Val%
Return

GetBeacon:
Val := YoctoKnob_GetBeacon(ModSN)
If Val = ON
    {
    GuiControl , , BeacOn , 1
    GuiControl , , BeacOff , 0
    }
If Val = Off
    {
    GuiControl , , BeacOff , 1
    GuiControl , , BeacOn , 0
    }    
Return

SetBeaconOn:
YoctoKnob_SetBeaconOn(ModSN)
Return

SetBeaconOff:
YoctoKnob_SetBeaconOff(ModSN)
Return

GetLum:
Gui , Submit, NoHide
Val := YoctoKnob_GetLum(ModSN)
GuiControl , , Lum , %Val%
Return

SetLum:
Gui , Submit, NoHide
YoctoKnob_SetLum(ModSN,Lum)
Return

CloseYoctoKnob:
YoctoKnob_Close()

Exit:
GuiEsc:
GuiClose:
Gui , Destroy
ExitApp
Return

Return to “Scripts and Functions”

Who is online

Users browsing this forum: EvetsNalon and 24 guests