2. Inherited from infinitime.Device to extend

This commit is contained in:
Yannick Ulrich 2023-02-26 13:05:58 +00:00
parent ec39e649c5
commit ffe9d43cf8

43
fuse.go
View File

@ -1,6 +1,7 @@
package main
import (
"go.arsenm.dev/infinitime"
"go.arsenm.dev/logger/log"
"os"
"context"
@ -10,28 +11,32 @@ import (
"strconv"
)
func (i *Device) HeartRateBytes() ([]byte, error) {
v, err := i.HeartRate()
type Device struct {
dev *infinitime.Device
}
func (i Device) HeartRateBytes() ([]byte, error) {
v, err := i.dev.HeartRate()
return []byte(strconv.Itoa(int(v)) + "\n"), err
}
func (i *Device) BatteryLevelBytes() ([]byte, error) {
v, err := i.BatteryLevel()
func (i Device) BatteryLevelBytes() ([]byte, error) {
v, err := i.dev.BatteryLevel()
return []byte(strconv.Itoa(int(v)) + "\n"), err
}
func (i *Device) StepCountBytes() ([]byte, error) {
v, err := i.StepCount()
func (i Device) StepCountBytes() ([]byte, error) {
v, err := i.dev.StepCount()
return []byte(strconv.Itoa(int(v)) + "\n"), err
}
func (i *Device) MotionBytes() ([]byte, error) {
v, err := i.Motion()
func (i Device) MotionBytes() ([]byte, error) {
v, err := i.dev.Motion()
return []byte(strconv.Itoa(int(v.X)) + " " + strconv.Itoa(int(v.Y)) + " " + strconv.Itoa(int(v.Z)) + "\n"), err
}
func (i *Device) AddressBytes() ([]byte, error) {
v := i.Address()
func (i Device) AddressBytes() ([]byte, error) {
v := i.dev.Address()
return []byte(v + "\n"), nil
}
func (i *Device) VersionBytes() ([]byte, error) {
v, err := i.Version()
func (i Device) VersionBytes() ([]byte, error) {
v, err := i.dev.Version()
return []byte(v + "\n"), err
}
@ -507,12 +512,14 @@ func startFuse(ctx context.Context, dev *infinitime.Device) error {
Str("target", mntDir).
Send()
properties[0].f = dev.HeartRateBytes;
properties[1].f = dev.BatteryLevelBytes;
properties[2].f = dev.MotionBytes;
properties[3].f = dev.StepCountBytes;
properties[4].f = dev.VersionBytes;
properties[5].f = dev.AddressBytes;
mydev := Device{dev : dev};
properties[0].f = mydev.HeartRateBytes;
properties[1].f = mydev.BatteryLevelBytes;
properties[2].f = mydev.MotionBytes;
properties[3].f = mydev.StepCountBytes;
properties[4].f = mydev.VersionBytes;
properties[5].f = mydev.AddressBytes;
myfs = &FS{};
inodemap = make(map[string]uint64)