File tree 3 files changed +31
-1
lines changed
3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
package main
4
4
5
+ import "errors"
6
+
7
+ var errNoBattery = errors .New ("no battery" )
8
+
5
9
func initExtras () {
6
10
// nop
7
11
}
12
+
13
+ func batteryVoltage () (float64 , error ) {
14
+ return 0 , errNoBattery
15
+ }
Original file line number Diff line number Diff line change @@ -15,9 +15,25 @@ import "machine"
15
15
16
16
var (
17
17
pinChargeCurrent = machine .P0_13
18
+ pinRead = machine .P0_14
19
+ pinVoltage = machine .P0_31
20
+
21
+ adc machine.ADC
18
22
)
19
23
20
24
func initExtras () {
21
25
pinChargeCurrent .Configure (machine.PinConfig {Mode : machine .PinOutput })
22
26
pinChargeCurrent .Low () // enable charging at high current, 100mA
27
+
28
+ // Shall keep this low while reading voltage
29
+ pinRead .Configure (machine.PinConfig {Mode : machine .PinOutput })
30
+
31
+ // Battery sensor pin
32
+ adc = machine.ADC {Pin : pinVoltage }
33
+ adc .Configure (machine.ADCConfig {})
34
+ }
35
+
36
+ func batteryVoltage () (float64 , error ) {
37
+ pinRead .Low ()
38
+ return float64 (adc .Get ()) / 7050 , nil
23
39
}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"math"
5
+ "strconv"
5
6
"time"
6
7
7
8
"github.com/ysoldak/HeadTracker/src/display"
@@ -60,7 +61,12 @@ func init() {
60
61
61
62
func main () {
62
63
63
- d .AddText (0 , "Head Tracker" )
64
+ batVolts , err := batteryVoltage ()
65
+ batString := ""
66
+ if err == nil {
67
+ batString = strconv .FormatFloat (batVolts , 'f' , 2 , 64 ) + "V"
68
+ }
69
+ d .AddText (0 , "Head Tracker " + batString )
64
70
d .AddText (1 , Version + " @ysoldak" )
65
71
66
72
// warm up IMU (1 sec)
You can’t perform that action at this time.
0 commit comments