From 3d169c46acafa8db3a500447f2abb206a9676b66 Mon Sep 17 00:00:00 2001 From: Andreas Muttscheller Date: Sun, 11 Sep 2022 21:43:27 +0200 Subject: [PATCH] Migrate bluetooth stack to tinygo.org/x/bluetooth --- README.md | 2 +- cmd/root.go | 4 +-- go.mod | 2 +- go.sum | 35 +++++++++++++++--- idasen/constants.go | 21 ++++++----- idasen/discover.go | 87 +++++++++++++++------------------------------ idasen/height.go | 10 ++---- idasen/idasen.go | 70 ++++++++++++++++++++++-------------- idasen/move.go | 37 ++++++++++--------- main.go | 1 - 10 files changed, 137 insertions(+), 132 deletions(-) diff --git a/README.md b/README.md index a1156b9..bc591e3 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ $ go get -u github.com/amuttsch/go-idasen ## Configuration Configuration that is not expected to change frequency can be provided via a -YAML configuration file located at ``~/.config/idasen/idasen.yaml``. +YAML configuration file located at ``./idasen.yaml``. You can use this command to initialize a new configuartion file: diff --git a/cmd/root.go b/cmd/root.go index 360b808..5109538 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -70,9 +70,7 @@ func init() { } func getConfigFilePath() string { - path, _ := os.UserConfigDir() - - return path + "/idasen/idasen.yaml" + return "./idasen.yaml" } func initConfig() { diff --git a/go.mod b/go.mod index d38020e..c515d6f 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/amuttsch/go-idasen go 1.15 require ( - github.com/muka/go-bluetooth v0.0.0-20201211051136-07f31c601d33 github.com/sirupsen/logrus v1.6.0 github.com/spf13/cobra v1.1.1 github.com/spf13/viper v1.7.0 gopkg.in/yaml.v2 v2.4.0 // indirect + tinygo.org/x/bluetooth v0.5.0 ) diff --git a/go.sum b/go.sum index 3a4c2e9..b4d4a28 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/JuulLabs-OSS/cbgo v0.0.2 h1:gCDyT0+EPuI8GOFyvAksFcVD2vF4CXBAVwT6uVnD9oo= +github.com/JuulLabs-OSS/cbgo v0.0.2/go.mod h1:L4YtGP+gnyD84w7+jN66ncspFRfOYB5aj9QSXaFHmBA= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -23,6 +25,7 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bgould/http v0.0.0-20190627042742-d268792bdee7/go.mod h1:BTqvVegvwifopl4KTEDth6Zezs9eR+lCWhvGKvkxJHE= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= @@ -37,9 +40,11 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= +github.com/frankban/quicktest v1.10.2/go.mod h1:K+q6oSqb0W0Ininfk863uOk1lMy69l/P6txr3mVT54s= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -47,6 +52,8 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9 github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI= +github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME= github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -64,6 +71,7 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Z github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -113,6 +121,7 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -124,7 +133,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5 github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= @@ -134,8 +142,8 @@ github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQz github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/muka/go-bluetooth v0.0.0-20201211051136-07f31c601d33 h1:p3srutpE8TpQmOUQ5Qw94jYFUdoG2jBbILeYLroQNoI= -github.com/muka/go-bluetooth v0.0.0-20201211051136-07f31c601d33/go.mod h1:dMCjicU6vRBk34dqOmIZm0aod6gUwZXOXzBROqGous0= +github.com/muka/go-bluetooth v0.0.0-20210812063148-b6c83362e27d h1:EG/xyWjHT19rkUpwsWSkyiCCmyqNwFovr9m10rhyOxU= +github.com/muka/go-bluetooth v0.0.0-20210812063148-b6c83362e27d/go.mod h1:dMCjicU6vRBk34dqOmIZm0aod6gUwZXOXzBROqGous0= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= @@ -166,6 +174,7 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo= github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= @@ -197,6 +206,7 @@ github.com/suapapa/go_eddystone v1.3.1/go.mod h1:bXC11TfJOS+3g3q/Uzd7FKd5g62STQE github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -246,6 +256,7 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -270,12 +281,16 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1 h1:sIky/MyNRSHTrdxfsiUSS4WIAMvInbeXljJz+jDjeYE= golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -299,6 +314,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200925191224-5d1fdd8fa346/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= @@ -343,3 +359,12 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +tinygo.org/x/bluetooth v0.5.0 h1:UftQTmx/snuTbeoS/R6+ZixmxSl5d6BvyfxlmD8eDng= +tinygo.org/x/bluetooth v0.5.0/go.mod h1:3rm7IKtmhP7aU2XRJI/Ods3J9Lqc3BAPPTNZmTtb42Q= +tinygo.org/x/drivers v0.14.0/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI= +tinygo.org/x/drivers v0.15.1/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI= +tinygo.org/x/drivers v0.16.0/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI= +tinygo.org/x/drivers v0.20.0/go.mod h1:uJD/l1qWzxzLx+vcxaW0eY464N5RAgFi1zTVzASFdqI= +tinygo.org/x/tinyfont v0.2.1/go.mod h1:eLqnYSrFRjt5STxWaMeOWJTzrKhXqpWw7nU3bPfKOAM= +tinygo.org/x/tinyfs v0.1.0/go.mod h1:ysc8Y92iHfhTXeyEM9+c7zviUQ4fN9UCFgSOFfMWv20= +tinygo.org/x/tinyterm v0.1.0/go.mod h1:/DDhNnGwNF2/tNgHywvyZuCGnbH3ov49Z/6e8LPLRR4= diff --git a/idasen/constants.go b/idasen/constants.go index a27765f..f5fe8a5 100644 --- a/idasen/constants.go +++ b/idasen/constants.go @@ -1,22 +1,27 @@ package idasen -import "encoding/binary" +import ( + "encoding/binary" + "tinygo.org/x/bluetooth" +) var ( + adapter = bluetooth.DefaultAdapter + // Minimum desk height in meters. _MIN_HEIGHT = 0.62 // Maximum desk height in meters. _MAX_HEIGHT = 1.27 - _UUID_HEIGHT = "99fa0021-338a-1024-8a49-009c0215f78a" - _UUID_COMMAND = "99fa0002-338a-1024-8a49-009c0215f78a" + _UUID_HEIGHT = "99fa0021-338a-1024-8a49-009c0215f78a" + _UUID_COMMAND = "99fa0002-338a-1024-8a49-009c0215f78a" _UUID_REFERENCE_INPUT = "99fa0031-338a-1024-8a49-009c0215f78a" - _COMMAND_REFERENCE_INPUT_STOP = []byte{0x01, 0x80} - _COMMAND_UP = []byte{0x47, 0x00} - _COMMAND_DOWN = []byte{0x46, 0x00} - _COMMAND_STOP = []byte{0xFF, 0x00} + _COMMAND_REFERENCE_INPUT_STOP = []byte{0x01, 0x80} + _COMMAND_UP = []byte{0x47, 0x00} + _COMMAND_DOWN = []byte{0x46, 0x00} + _COMMAND_STOP = []byte{0xFF, 0x00} ) func getOptions() map[string]interface{} { @@ -30,5 +35,5 @@ func heightBytesToMeter(b []byte) float64 { } raw := binary.LittleEndian.Uint16(b[0:2]) - return float64(float64(raw) / 10000) + _MIN_HEIGHT + return float64(float64(raw)/10000) + _MIN_HEIGHT } diff --git a/idasen/discover.go b/idasen/discover.go index 8688869..c954285 100644 --- a/idasen/discover.go +++ b/idasen/discover.go @@ -3,35 +3,35 @@ package idasen import ( "errors" "fmt" - "github.com/muka/go-bluetooth/api" - "github.com/muka/go-bluetooth/bluez/profile/adapter" - "github.com/muka/go-bluetooth/bluez/profile/device" "os" "os/signal" "regexp" "time" + "tinygo.org/x/bluetooth" ) const _DISCOVER_TIMEOUT = 5 * time.Second func DiscoverDesk() (*desk, error) { - //clean up connection on exit - defer api.Exit() - - a, err := adapter.GetDefaultAdapter() + result, err := getDesk("") if err != nil { return nil, err } + return &desk{ + Name: result.LocalName(), + Address: result.Address.String(), + }, nil +} + +func getDesk(mac string) (*bluetooth.ScanResult, error) { log.Debug("Start discovery") - discovery, cancel, err := api.Discover(a, nil) + err := adapter.Enable() if err != nil { - return nil, err + return nil, fmt.Errorf("must enable adapter: %w", err) } - defer cancel() - discoverTimeout := time.NewTimer(_DISCOVER_TIMEOUT) - deskChan := make(chan *desk) + resultCh := make(chan bluetooth.ScanResult, 1) deskNameRegex, err := regexp.Compile("Desk \\d+") if err != nil { @@ -39,62 +39,31 @@ func DiscoverDesk() (*desk, error) { return nil, errors.New("invalid regex") } - go func() { - - for ev := range discovery { - - if ev.Type == adapter.DeviceRemoved { - continue - } - - dev, err := device.NewDevice1(ev.Path) - if err != nil { - log.Errorf("%s: %s", ev.Path, err) - continue + // Start scanning. + log.Debugln("Scanning...") + err = adapter.Scan(func(adapter *bluetooth.Adapter, result bluetooth.ScanResult) { + if mac == "" { + if deskNameRegex.MatchString(result.LocalName()) { + log.Infoln("Found Desk:", result.Address.String(), result.RSSI, result.LocalName()) + adapter.StopScan() + resultCh <- result } - - if dev == nil { - log.Errorf("%s: not found", ev.Path) - continue - } - - log.Debugf("name=%s addr=%s rssi=%d\n", dev.Properties.Name, dev.Properties.Address, dev.Properties.RSSI) - - if deskNameRegex.MatchString(dev.Properties.Name) { - if !dev.Properties.Paired { - err = dev.Pair() - if err != nil { - log.Errorf("Pairing failed: %s", err) - return - } - - log.Debugf("Paired device %s", dev.Properties.Name) - } - - err = dev.SetTrusted(true) - if err != nil { - log.Errorf("Trusting failed: %s", err) - return - } - log.Debugf("Trusting device %s", dev.Properties.Name) - - deskChan <- &desk{ - Name: dev.Properties.Name, - Address: dev.Properties.Address, - } - - return + } else { + if result.Address.String() == mac { + adapter.StopScan() + resultCh <- result } } - }() + }) + discoverTimeout := time.NewTimer(_DISCOVER_TIMEOUT) ch := make(chan os.Signal) signal.Notify(ch, os.Interrupt, os.Kill) select { - case desk := <-deskChan: - return desk, nil + case result := <-resultCh: + return &result, nil case <-discoverTimeout.C: e := fmt.Errorf("Discover timeout reached after %s", _DISCOVER_TIMEOUT.String()) log.Debugln(e) diff --git a/idasen/height.go b/idasen/height.go index 41e7bfe..ff8f81c 100644 --- a/idasen/height.go +++ b/idasen/height.go @@ -1,15 +1,9 @@ package idasen func (i *Idasen) HeightInMeters() (float64, error) { - height, err := i.device.GetCharByUUID(_UUID_HEIGHT) + raw, err := i.readValue(_UUID_HEIGHT) if err != nil { - log.Errorf("Cannot get height %s", err) - return 0, err - } - - raw, err := height.ReadValue(getOptions()) - if err != nil { - log.Errorf("Cannot ReadValue %s", err) + log.Errorf("Cannot get height: %s", err) return 0, err } diff --git a/idasen/idasen.go b/idasen/idasen.go index 6c6a2d5..d41b9a9 100644 --- a/idasen/idasen.go +++ b/idasen/idasen.go @@ -1,21 +1,19 @@ package idasen import ( - "github.com/muka/go-bluetooth/api" - "github.com/muka/go-bluetooth/bluez/profile/adapter" - "github.com/muka/go-bluetooth/bluez/profile/device" "github.com/sirupsen/logrus" + "tinygo.org/x/bluetooth" ) var log = logrus.New() type Idasen struct { - device *device.Device1 + device *bluetooth.Device } type Configuration struct { - MacAddress string `mapstructure:"mac_address"` - Positions map[string]float64 `mapstructure:"positions"` + MacAddress string `mapstructure:"mac_address"` + Positions map[string]float64 `mapstructure:"positions"` } type desk struct { @@ -24,47 +22,65 @@ type desk struct { } func New(config Configuration) (*Idasen, error) { - - a, err := adapter.GetDefaultAdapter() + desk, err := getDesk(config.MacAddress) if err != nil { - api.Exit() - return nil, err - } - - d, err := a.GetDeviceByAddress(config.MacAddress) - if err != nil || d == nil { log.Errorf("Could not find device %s: %s", config.MacAddress, err) - api.Exit() return nil, err } - err = d.Connect() + d, err := adapter.Connect(desk.Address, bluetooth.ConnectionParams{}) if err != nil { log.Errorf("Cannot connect to device %s: %s", config.MacAddress, err) - api.Exit() return nil, err } log.Debugf("Connected to desk %s", config.MacAddress) - if !d.Properties.Paired { - err = d.Pair() + return &Idasen{ + device: d, + }, nil +} + +func (i *Idasen) readValue(uuid string) ([]byte, error) { + srvcs, _ := i.device.DiscoverServices(nil) + + for _, srvc := range srvcs { + chars, err := srvc.DiscoverCharacteristics(nil) if err != nil { - log.Errorf("Cannot connect to device %s: %s", config.MacAddress, err) - api.Exit() - return nil, err + println(err) + } + for _, char := range chars { + if char.UUID().String() == uuid { + raw := make([]byte, 255) + _, err = char.Read(raw) + + return raw, err + } } + } + + return nil, nil +} + +func (i *Idasen) writeValue(uuid string, value []byte) (int, error) { + srvcs, _ := i.device.DiscoverServices(nil) - log.Debugf("Paired with desk %s", config.MacAddress) + for _, srvc := range srvcs { + chars, err := srvc.DiscoverCharacteristics(nil) + if err != nil { + println(err) + } + for _, char := range chars { + if char.UUID().String() == uuid { + return char.WriteWithoutResponse(value) + } + } } - return &Idasen{ - device: d, - }, nil + return -1, nil } func (i *Idasen) Close() { - defer api.Exit() defer i.device.Disconnect() } diff --git a/idasen/move.go b/idasen/move.go index b1a8d51..30a0848 100644 --- a/idasen/move.go +++ b/idasen/move.go @@ -1,42 +1,41 @@ package idasen -import ( - "fmt" -) +import "fmt" func (i *Idasen) MoveUp() error { - char, err := i.device.GetCharByUUID(_UUID_COMMAND) + _, err := i.writeValue(_UUID_COMMAND, _COMMAND_UP) if err != nil { - log.Errorf("Cannot get command char %s", err) + log.Errorf("Cannot move desk: %s", err) return err } - return char.WriteValue(_COMMAND_UP, getOptions()) + + return nil } func (i *Idasen) MoveDown() error { - char, err := i.device.GetCharByUUID(_UUID_COMMAND) + _, err := i.writeValue(_UUID_COMMAND, _COMMAND_DOWN) if err != nil { - log.Errorf("Cannot get command char %s", err) + log.Errorf("Cannot move desk: %s", err) return err } - return char.WriteValue(_COMMAND_DOWN, getOptions()) + + return nil } func (i *Idasen) MoveStop() error { - char_cmd, err := i.device.GetCharByUUID(_UUID_COMMAND) + _, err := i.writeValue(_UUID_COMMAND, _COMMAND_STOP) if err != nil { - log.Errorf("Cannot get command char %s", err) + log.Errorf("Cannot stop desk: %s", err) return err } - - char_ref, err := i.device.GetCharByUUID(_UUID_REFERENCE_INPUT) + + _, err = i.writeValue(_UUID_REFERENCE_INPUT, _COMMAND_STOP) if err != nil { - log.Errorf("Cannot get reference input char %s", err) + log.Errorf("Cannot stop desk: %s", err) return err } - _ = char_cmd.WriteValue(_COMMAND_STOP, getOptions()) - return char_ref.WriteValue(_COMMAND_REFERENCE_INPUT_STOP, getOptions()) + return nil } func (i *Idasen) MoveToTarget(targetInMeters float64) error { @@ -62,12 +61,12 @@ func (i *Idasen) MoveToTarget(targetInMeters float64) error { if err != nil { return err } - + // Check if the safety stop was triggered if (height > previousHeight && !willMoveUp) || (height < previousHeight && willMoveUp) { _ = i.MoveStop() return fmt.Errorf("safety stop was trigged") - } + } difference := 0.0 if willMoveUp { @@ -91,7 +90,7 @@ func (i *Idasen) MoveToTarget(targetInMeters float64) error { if err != nil { return err } - + previousHeight = height } diff --git a/main.go b/main.go index ac72402..7e86ebb 100644 --- a/main.go +++ b/main.go @@ -7,4 +7,3 @@ import ( func main() { cmd.Execute() } -