solar3s / goregen

golang client for regenbox
GNU General Public License v3.0
9 stars 10 forks source link

Firmware anode #23

Closed rkjdid closed 6 years ago

rkjdid commented 6 years ago

a good amount of rework to the firmware to use the idle time of the arduino to compute voltage.

this allows quasi-instant answers from the arduino, the average is constantly recalculated using some voodoo values (chunk sizes of 50, delay(5) in main loop)

there is also a cool auto-calibrate of AREF feature in there, taken from arduino's forum board.

feedback & testing welcome!

rkjdid commented 6 years ago

youpi from 250ms to 7ms ReadVoltage()

rkj@rkdeb:~/go/src/github.com/solar3s/goregen/regenbox$ go test -v -run=XX -bench=.
2017/11/28 02:50:01 trying "/dev/ttyUSB0"...
2017/11/28 02:50:02 connected to "/dev/ttyUSB0" in 481.641184ms
goos: linux
goarch: amd64
pkg: github.com/solar3s/goregen/regenbox
BenchmarkReadVoltage-4             5     234680815 ns/op
--- BENCH: BenchmarkReadVoltage-4
    regenbox_test.go:55: using firmware: cathode
    regenbox_test.go:67: b.N: 1
    regenbox_test.go:68: average voltage: 1355
    regenbox_test.go:67: b.N: 2
    regenbox_test.go:68: average voltage: 1350
    regenbox_test.go:67: b.N: 5
    regenbox_test.go:68: average voltage: 1347
PASS
ok      github.com/solar3s/goregen/regenbox 2.380s

rkj@rkdeb:~/go/src/github.com/solar3s/goregen/regenbox$ go test -v -run=XX -bench=.
2017/11/28 02:50:48 trying "/dev/ttyUSB0"...
2017/11/28 02:50:49 connected to "/dev/ttyUSB0" in 489.904641ms
goos: linux
goarch: amd64
pkg: github.com/solar3s/goregen/regenbox
BenchmarkReadVoltage-4           200       7156745 ns/op
--- BENCH: BenchmarkReadVoltage-4
    regenbox_test.go:55: using firmware: anode
    regenbox_test.go:67: b.N: 1
    regenbox_test.go:68: average voltage: 1346
    regenbox_test.go:67: b.N: 2
    regenbox_test.go:68: average voltage: 1346
    regenbox_test.go:67: b.N: 200
    regenbox_test.go:68: average voltage: 1335
PASS
ok      github.com/solar3s/goregen/regenbox 1.965s