Used generator instead of function in ITProperty

This commit is contained in:
Yannick Ulrich 2023-02-26 19:03:27 +00:00
parent 4333b83ca2
commit 083da5b3f0

21
fuse.go
View File

@ -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 {