From 083da5b3f0b592899e3c5c2b89b201749cda8bbf Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sun, 26 Feb 2023 19:03:27 +0000 Subject: [PATCH] Used generator instead of function in ITProperty --- fuse.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/fuse.go b/fuse.go index 708e9b9..fa1d855 100644 --- a/fuse.go +++ b/fuse.go @@ -47,7 +47,7 @@ func (i Device) VersionBytes() ([]byte, error) { type ITProperty struct { name string Ino uint64 - f func() ([]byte, error) + gen func(context.Context) (<-chan uint8, error) } @@ -393,13 +393,13 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle, for _, value := range properties { if value.Ino == f.Ino { - ans, err := value.f() + ans, err := value.gen(ctx) if err != nil { return nil, 0, syscall.EROFS } - fh = &bytesFileReadHandle{ - content: ans, + fh = &sensorFileReadHandle{ + ch: ans, } return fh, fuse.FOPEN_DIRECT_IO, 0 } @@ -551,12 +551,13 @@ func startFuse(ctx context.Context, dev *infinitime.Device) error { 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; + properties[0].gen = mydev.dev.WatchHeartRate; + // 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, err = dev.FS() if err != nil {