From ffe9d43cf867c0bdbae228d11314bac2096c9a88 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sun, 26 Feb 2023 13:05:58 +0000 Subject: [PATCH] 2. Inherited from infinitime.Device to extend --- fuse.go | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/fuse.go b/fuse.go index 9e2cdec..30acaa0 100644 --- a/fuse.go +++ b/fuse.go @@ -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)