Added FUSE support #55

Merged
Elara6331 merged 65 commits from yannickulrich/itd:fuse into master 2023-03-25 22:23:52 +00:00
Showing only changes of commit 083da5b3f0 - Show all commits

21
fuse.go
View File

@ -47,7 +47,7 @@ func (i Device) VersionBytes() ([]byte, error) {
type ITProperty struct { type ITProperty struct {
name string name string
Ino uint64 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 { for _, value := range properties {
if value.Ino == f.Ino { if value.Ino == f.Ino {
ans, err := value.f() ans, err := value.gen(ctx)
if err != nil { if err != nil {
return nil, 0, syscall.EROFS return nil, 0, syscall.EROFS
} }
fh = &bytesFileReadHandle{ fh = &sensorFileReadHandle{
content: ans, ch: ans,
} }
return fh, fuse.FOPEN_DIRECT_IO, 0 return fh, fuse.FOPEN_DIRECT_IO, 0
} }
@ -551,12 +551,13 @@ func startFuse(ctx context.Context, dev *infinitime.Device) error {
mydev := Device{dev : dev}; mydev := Device{dev : dev};
properties[0].f = mydev.HeartRateBytes; properties[0].gen = mydev.dev.WatchHeartRate;
properties[1].f = mydev.BatteryLevelBytes; // properties[0].f = mydev.HeartRateBytes;
properties[2].f = mydev.MotionBytes; // properties[1].f = mydev.BatteryLevelBytes;
properties[3].f = mydev.StepCountBytes; // properties[2].f = mydev.MotionBytes;
properties[4].f = mydev.VersionBytes; // properties[3].f = mydev.StepCountBytes;
properties[5].f = mydev.AddressBytes; // properties[4].f = mydev.VersionBytes;
// properties[5].f = mydev.AddressBytes;
myfs, err = dev.FS() myfs, err = dev.FS()
if err != nil { if err != nil {