Post by Steve Caldwell on Apr 26, 2024 22:27:22 GMT
Wrote this wrapper in AutoHotKey 2.0 after getting my Blync light. Lot's of stuff commented out as I was experimenting. I'm not a professional program just a self taught person that did this out of need. I searched high and low on the internet and couldn't find anything so I decided to just try and build it myself. So far, it works pretty good.
#Requires AutoHotkey v2
#Warn VarUnset, Off ;StdOut
/* Blync Busilight API Wrapper.
Requires the DLL API From Embrava
embrava.com/pages/embrava-software-sdk
This wrapper was written by Steven J. Caldwell
Last Update 26-Apr-2024
Currently only supporting 1 light but can pretty easily be expanded.
*/
class Blync {
__Init(){ ; Alway References the base class
;Msgbox("__Init Called",,mboxtimeout)
}
__New() { ; Happens on creating new instance. Called after __Init
BL.BL_PATH := "D:\Personal\Embrava\BlynclightTest_Source\BlyncLightTest\x64\Release\"
BL.BL_DLL := "BlynclightNative"
BL.DLL := DllCall("LoadLibrary", "Str", BL.BL_PATH . BL.BL_DLL . ".dll", "Ptr")
; msgbox "BL.DLL=" BL.DLL
; msgbox("Fullpath=" BL.BL_PATH . BL.BL_DLL . ".dll")
; BL.__getAddresses() ; Not doing lookup for now
;Msgbox("__New Called",,mboxtimeout)
this.devices:=this.InitBlync()
if (this.devices<1)
{
msgbox("No Blink Devices. Exiting ...",,T3)
}
else
{
this.device:=this.devices-1
this.speed:=3
this.SetFlash(this.speed)
}
}
__Delete() {
; msgbox Free
this.CloseDevices(this.devices)
; MsgBox ,,Blync,Blync Devices Closed,2
DllCall("FreeLibrary", "Ptr", BL.DLL)
;Msgbox("__Delete Called",,mboxtimeout)
}
; Meta Functions Happen when the class does not have a property
__Get(Name,Params){
MsgBox("No Property called: " Name ,, mboxtimeout)
; ExitApp
}
/* Let the base class handle these for now
__Set(Name,Params,Value){
this._name:=value
}
__Call(Name,Params){
}
*/
; Set when called using array indexing and is the default returned for the class
/*
static __Item[name] {
get => name
set => name := value
}
*/
/* For All Fixed Color Commands */
MakeColor(color) {
command:="BlynclightNative\TurnOn" . color . "Light"
; msgbox(command)
DLLCall(command,"Int",0,"Cdecl Int")
}
InitBlync() {
return DLLCall("BlynclightNative\InitBlyncDevices","Cdecl Int")
}
CloseDevices(num:=0){
return DLLCall("BlynclightNative\CloseDevices","Int",num,"Cdecl Int")
}
Flash() {
; msgbox("Flash Called",,"T2")
return DLLCall("BlynclightNative\StartLightFlash","Int",0,"Cdecl Int")
}
UnFlash() {
return DLLCall("BlynclightNative\StopLightFlash","Int",0,"Cdecl Int")
}
SetFlash(speed) {
; msgbox("Speed set to " . speed ,"Object","T2")
return DLLCall("BlynclightNative\SelectLightFlashSpeed","Int",0,"Int",speed,"Cdecl Int")
}
Off(){
return DLLCall("BlynclightNative\ResetLight","Int",0,"Cdecl Int")
}
Bright(){
return DLLCall("BlynclightNative\ClearLightDim","Int",0,"Cdecl Int")
}
Dim(){
return DLLCall("BlynclightNative\SetLightDim","Int",0,"Cdecl Int")
}
Mute(){
return DLLCall("BlynclightNative\SetVolumeMute","Int",0,"Cdecl Int")
}
UnMute(){
return DLLCall("BlynclightNative\ClearVolumeMute","Int",0,"Cdecl Int")
}
Play(){
return DLLCall("BlynclightNative\StartMusicPlay","Int",0,"Cdecl Int")
}
Stop(){
return DLLCall("BlynclightNative\StopMusicPlay","Int",0,"Cdecl Int")
}
Repeat(){
return DLLCall("BlynclightNative\SetMusicRepeat","Int",0,"Cdecl Int")
}
NoRepeat(){
return DLLCall("BlynclightNative\ClearMusicRepeat","Int",0,"Cdecl Int")
}
SongSelect(song){
return DLLCall("BlynclightNative\SelectMusicToPlay","Int",0,"Int",song,"Cdecl Int")
}
Volume(level){
; msgbox("Volume at " level ,, "T1")
return DLLCall("BlynclightNative\SetMusicVolume","Int",0,"Int",level,"Cdecl Int")
}
rgb(red,green,blue){
return DLLCall("BlynclightNative\TurnOnRGBLights","Int",0,"Int",red,"Int",green,"Int",blue,"Cdecl Int")
}
} ; Class Blync
Class BL {
; static DLL, BL_PATH , BL_DLL
static FUNC_ADDR := map()
static __getAddresses(){
; Msgbox __getAddresses
for fName in BL.BL_COMMANDS {
(BL.FUNC_ADDR)[fName] := DllCall("GetProcAddress", "Ptr", BL.DLL, "AStr", fName, "Ptr")
; Msgbox("func_name=" . fName . "Address=" . BL.FUNC_ADDR[fName] )
}
}
/* static BL_COMMANDS :=map(InitBlyncDevices,0
,CloseDevices,0)
*/
/* We will not do lookups
static BL_COMMANDS :=map("InitBlyncDevices",0
,"CloseDevices",0
,"ResetLight",0
,"TurnOnRedLight",0
,"TurnOnGreenLight",0
,"TurnOnBlueLight",0
,"TurnOnCyanLight",0
,"TurnOnMagentaLight",0
,"TurnOnYellowLight",0
,"TurnOnWhiteLight",0
,"TurnOnOrangeLight",0
,"TurnOnRGBLights",0
,"SetLightDim",0
,"ClearLightDim",0
,"SelectLightFlashSpeed",0
,"StartLightFlash",0
,"StopLightFlash",0
,"SelectMusicToPlay",0
,"StartMusicPlay",0
,"StopMusicPlay",0
,"SetMusicRepeat",0
,"ClearMusicRepeat",0
,"SetMusicVolume",0
,"SetVolumeMute",0
,"ClearVolumeMute",0
,"GetDeviceUniqueId",0 )
*/
} ; Class BL
class FuncArrayType extends Array {
Call(params*) {
; Call a list of functions.
for fn in this
fn(params*)
}
}
/* Testing code starts here
^!q:: ExitApp
mboxtimeout:="T1"
;---------------------------------------------------
; fat arrow examples returns a function
; mesgbox w timeout;
mbto:= a => msgbox(a,"MBTO","T2")
; mtbo:= a => msgbox.bind(a,"MTBO","T2")
;mbto("hello")
;mbto("what is this?")
; double:= a => a * 2
; msgbox (double(4))
/*
; call setcolor with paramter a
color:= a => setcolor(a)
; now call the function
mycolor:= color("red")
; define the function
setcolor(a){
return a
}
; print the return value with delay
;mbto(mycolor)
red := setcolor.bind("red")
blue := setcolor.bind("blue")
Green := setcolor.bind("green")
; for c in [red,blue,green]
; mbto(c())
color_array := ["orange","yellow","purple"]
;; Create a Function Array ... See above
global clr:=FuncArrayType()
*/
/*
for c in color_array
{
; cmd:= c " := setcolor.bind(" "`"" c "`")"
; mbto(cmd)
clr.InsertAt(0,c)
clr[a_index] := setcolor.bind(c)
mbto(clr[a_index]())
}
mbto(clr[2]())
mclr:=clr[3]()
mkcolor(c){
clr.InsertAt(0,c)
return c
}
*/
/*
mbto(red())
mbto(blue())
mbto(green())
; Testing use of cynamic variables
;chosen:="none"
variable:="chosen"
%variable%:="red"
mbto("chosen=" chosen)
msgbox(%chosen%())
msgbox()
clrs := Map()
clrs["Red"] := "ff0000"
clrs["Green"] := "00ff00"
clrs["Blue"] := "0000ff"
for clr in Array("Blue", "Green", "Red")
mbto(clr . " " . clrs[clr])
ExitApp
tb:= Blync()
msgbox("tb created",,mboxtimeout)
; Test Naming objects
tb[]:="Steve"
; msgbox("tb[]=" . tb[],, mboxtimeout)
; msgbox(tb.__item)
if (tb.name != "")
msgbox(tb.name)
tb.name:="junk"
msgbox(tb.name)
*/
;;-------- Associative Array test - Doesn't work on V2
/*
array := {ten: 10, twenty: 20, thirty: 30}
For key, value in array
MsgBox %key% = %value%
*/
/*
tb:=Blync()
tb.InitBlink()
tb.MakeColor("Orange")
; tb.TurnOnMagentaLight()
msgbox("Any Key to End")
ExitApp
*/
#Requires AutoHotkey v2
#Warn VarUnset, Off ;StdOut
/* Blync Busilight API Wrapper.
Requires the DLL API From Embrava
embrava.com/pages/embrava-software-sdk
This wrapper was written by Steven J. Caldwell
Last Update 26-Apr-2024
Currently only supporting 1 light but can pretty easily be expanded.
*/
class Blync {
__Init(){ ; Alway References the base class
;Msgbox("__Init Called",,mboxtimeout)
}
__New() { ; Happens on creating new instance. Called after __Init
BL.BL_PATH := "D:\Personal\Embrava\BlynclightTest_Source\BlyncLightTest\x64\Release\"
BL.BL_DLL := "BlynclightNative"
BL.DLL := DllCall("LoadLibrary", "Str", BL.BL_PATH . BL.BL_DLL . ".dll", "Ptr")
; msgbox "BL.DLL=" BL.DLL
; msgbox("Fullpath=" BL.BL_PATH . BL.BL_DLL . ".dll")
; BL.__getAddresses() ; Not doing lookup for now
;Msgbox("__New Called",,mboxtimeout)
this.devices:=this.InitBlync()
if (this.devices<1)
{
msgbox("No Blink Devices. Exiting ...",,T3)
}
else
{
this.device:=this.devices-1
this.speed:=3
this.SetFlash(this.speed)
}
}
__Delete() {
; msgbox Free
this.CloseDevices(this.devices)
; MsgBox ,,Blync,Blync Devices Closed,2
DllCall("FreeLibrary", "Ptr", BL.DLL)
;Msgbox("__Delete Called",,mboxtimeout)
}
; Meta Functions Happen when the class does not have a property
__Get(Name,Params){
MsgBox("No Property called: " Name ,, mboxtimeout)
; ExitApp
}
/* Let the base class handle these for now
__Set(Name,Params,Value){
this._name:=value
}
__Call(Name,Params){
}
*/
; Set when called using array indexing and is the default returned for the class
/*
static __Item[name] {
get => name
set => name := value
}
*/
/* For All Fixed Color Commands */
MakeColor(color) {
command:="BlynclightNative\TurnOn" . color . "Light"
; msgbox(command)
DLLCall(command,"Int",0,"Cdecl Int")
}
InitBlync() {
return DLLCall("BlynclightNative\InitBlyncDevices","Cdecl Int")
}
CloseDevices(num:=0){
return DLLCall("BlynclightNative\CloseDevices","Int",num,"Cdecl Int")
}
Flash() {
; msgbox("Flash Called",,"T2")
return DLLCall("BlynclightNative\StartLightFlash","Int",0,"Cdecl Int")
}
UnFlash() {
return DLLCall("BlynclightNative\StopLightFlash","Int",0,"Cdecl Int")
}
SetFlash(speed) {
; msgbox("Speed set to " . speed ,"Object","T2")
return DLLCall("BlynclightNative\SelectLightFlashSpeed","Int",0,"Int",speed,"Cdecl Int")
}
Off(){
return DLLCall("BlynclightNative\ResetLight","Int",0,"Cdecl Int")
}
Bright(){
return DLLCall("BlynclightNative\ClearLightDim","Int",0,"Cdecl Int")
}
Dim(){
return DLLCall("BlynclightNative\SetLightDim","Int",0,"Cdecl Int")
}
Mute(){
return DLLCall("BlynclightNative\SetVolumeMute","Int",0,"Cdecl Int")
}
UnMute(){
return DLLCall("BlynclightNative\ClearVolumeMute","Int",0,"Cdecl Int")
}
Play(){
return DLLCall("BlynclightNative\StartMusicPlay","Int",0,"Cdecl Int")
}
Stop(){
return DLLCall("BlynclightNative\StopMusicPlay","Int",0,"Cdecl Int")
}
Repeat(){
return DLLCall("BlynclightNative\SetMusicRepeat","Int",0,"Cdecl Int")
}
NoRepeat(){
return DLLCall("BlynclightNative\ClearMusicRepeat","Int",0,"Cdecl Int")
}
SongSelect(song){
return DLLCall("BlynclightNative\SelectMusicToPlay","Int",0,"Int",song,"Cdecl Int")
}
Volume(level){
; msgbox("Volume at " level ,, "T1")
return DLLCall("BlynclightNative\SetMusicVolume","Int",0,"Int",level,"Cdecl Int")
}
rgb(red,green,blue){
return DLLCall("BlynclightNative\TurnOnRGBLights","Int",0,"Int",red,"Int",green,"Int",blue,"Cdecl Int")
}
} ; Class Blync
Class BL {
; static DLL, BL_PATH , BL_DLL
static FUNC_ADDR := map()
static __getAddresses(){
; Msgbox __getAddresses
for fName in BL.BL_COMMANDS {
(BL.FUNC_ADDR)[fName] := DllCall("GetProcAddress", "Ptr", BL.DLL, "AStr", fName, "Ptr")
; Msgbox("func_name=" . fName . "Address=" . BL.FUNC_ADDR[fName] )
}
}
/* static BL_COMMANDS :=map(InitBlyncDevices,0
,CloseDevices,0)
*/
/* We will not do lookups
static BL_COMMANDS :=map("InitBlyncDevices",0
,"CloseDevices",0
,"ResetLight",0
,"TurnOnRedLight",0
,"TurnOnGreenLight",0
,"TurnOnBlueLight",0
,"TurnOnCyanLight",0
,"TurnOnMagentaLight",0
,"TurnOnYellowLight",0
,"TurnOnWhiteLight",0
,"TurnOnOrangeLight",0
,"TurnOnRGBLights",0
,"SetLightDim",0
,"ClearLightDim",0
,"SelectLightFlashSpeed",0
,"StartLightFlash",0
,"StopLightFlash",0
,"SelectMusicToPlay",0
,"StartMusicPlay",0
,"StopMusicPlay",0
,"SetMusicRepeat",0
,"ClearMusicRepeat",0
,"SetMusicVolume",0
,"SetVolumeMute",0
,"ClearVolumeMute",0
,"GetDeviceUniqueId",0 )
*/
} ; Class BL
class FuncArrayType extends Array {
Call(params*) {
; Call a list of functions.
for fn in this
fn(params*)
}
}
/* Testing code starts here
^!q:: ExitApp
mboxtimeout:="T1"
;---------------------------------------------------
; fat arrow examples returns a function
; mesgbox w timeout;
mbto:= a => msgbox(a,"MBTO","T2")
; mtbo:= a => msgbox.bind(a,"MTBO","T2")
;mbto("hello")
;mbto("what is this?")
; double:= a => a * 2
; msgbox (double(4))
/*
; call setcolor with paramter a
color:= a => setcolor(a)
; now call the function
mycolor:= color("red")
; define the function
setcolor(a){
return a
}
; print the return value with delay
;mbto(mycolor)
red := setcolor.bind("red")
blue := setcolor.bind("blue")
Green := setcolor.bind("green")
; for c in [red,blue,green]
; mbto(c())
color_array := ["orange","yellow","purple"]
;; Create a Function Array ... See above
global clr:=FuncArrayType()
*/
/*
for c in color_array
{
; cmd:= c " := setcolor.bind(" "`"" c "`")"
; mbto(cmd)
clr.InsertAt(0,c)
clr[a_index] := setcolor.bind(c)
mbto(clr[a_index]())
}
mbto(clr[2]())
mclr:=clr[3]()
mkcolor(c){
clr.InsertAt(0,c)
return c
}
*/
/*
mbto(red())
mbto(blue())
mbto(green())
; Testing use of cynamic variables
;chosen:="none"
variable:="chosen"
%variable%:="red"
mbto("chosen=" chosen)
msgbox(%chosen%())
msgbox()
clrs := Map()
clrs["Red"] := "ff0000"
clrs["Green"] := "00ff00"
clrs["Blue"] := "0000ff"
for clr in Array("Blue", "Green", "Red")
mbto(clr . " " . clrs[clr])
ExitApp
tb:= Blync()
msgbox("tb created",,mboxtimeout)
; Test Naming objects
tb[]:="Steve"
; msgbox("tb[]=" . tb[],, mboxtimeout)
; msgbox(tb.__item)
if (tb.name != "")
msgbox(tb.name)
tb.name:="junk"
msgbox(tb.name)
*/
;;-------- Associative Array test - Doesn't work on V2
/*
array := {ten: 10, twenty: 20, thirty: 30}
For key, value in array
MsgBox %key% = %value%
*/
/*
tb:=Blync()
tb.InitBlink()
tb.MakeColor("Orange")
; tb.TurnOnMagentaLight()
msgbox("Any Key to End")
ExitApp
*/