From 87c78566c1750aac86c0cd99cae85489e6dee182 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Wed, 1 Mar 2023 15:14:06 +0000 Subject: [PATCH] 3. Added builder --- fuse.go | 35 ++------------------------------ internal/fusefs/fuse.go | 44 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/fuse.go b/fuse.go index 3b7ee77..5496f6c 100644 --- a/fuse.go +++ b/fuse.go @@ -12,7 +12,7 @@ import ( func startFuse(ctx context.Context, dev *infinitime.Device) error { // This is where we'll mount the FS os.Mkdir(k.String("fuse.mountpoint"), 0755) - root := &ITNode{kind: 0} + root := fusefs.BuildRootNode(dev) server, err := fs.Mount(k.String("fuse.mountpoint"), root, &fs.Options{ MountOptions: fuse.MountOptions{ // Set to true to see how the file system works. @@ -32,43 +32,12 @@ func startFuse(ctx context.Context, dev *infinitime.Device) error { Str("target", k.String("fuse.mountpoint")). Send() - properties[0] = ITProperty{"heartrate", 2, - func(ctx context.Context) (<-chan []byte, error) { - ans, err := dev.WatchHeartRate(ctx) - return converterU8(ctx, ans), err - }} - properties[1] = ITProperty{"battery", 3, - func(ctx context.Context) (<-chan []byte, error) { - ans, err := dev.WatchBatteryLevel(ctx) - return converterU8(ctx, ans), err - }} - properties[2] = ITProperty{"motion", 4, - func(ctx context.Context) (<-chan []byte, error) { - ans, err := dev.WatchMotion(ctx) - return converterMotionValues(ctx, ans), err - }} - properties[3] = ITProperty{"stepcount", 5, - func(ctx context.Context) (<-chan []byte, error) { - ans, err := dev.WatchStepCount(ctx) - return converterU32(ctx, ans), err - }} - properties[4] = ITProperty{"version", 6, - func(ctx context.Context) (<-chan []byte, error) { - ans, err := dev.Version() - return converter1String(ctx, ans), err - }} - properties[5] = ITProperty{"address", 7, - func(ctx context.Context) (<-chan []byte, error) { - ans := dev.Address() - return converter1String(ctx, ans), nil - }} + fusefs.BuildProperties(dev) - myfs, err = dev.FS() if err != nil { log.Warn("Error getting BLE filesystem").Err(err).Send() return err } - inodemap = make(map[string]uint64) // Wait until unmount before exiting go server.Serve() diff --git a/internal/fusefs/fuse.go b/internal/fusefs/fuse.go index d8b6530..feb5c03 100644 --- a/internal/fusefs/fuse.go +++ b/internal/fusefs/fuse.go @@ -89,7 +89,51 @@ type ITNode struct { path string } +func BuildRootNode(dev *infinitime.Device) *ITNode { + inodemap = make(map[string]uint64) + myfs, _ = dev.FS() + + return &ITNode{kind: 0} +} + var properties = make([]ITProperty, 6) + +func BuildProperties(dev *infinitime.Device) { + properties[0] = ITProperty{"heartrate", 2, + func(ctx context.Context) (<-chan []byte, error) { + ans, err := dev.WatchHeartRate(ctx) + return converterU8(ctx, ans), err + }} + properties[1] = ITProperty{"battery", 3, + func(ctx context.Context) (<-chan []byte, error) { + ans, err := dev.WatchBatteryLevel(ctx) + return converterU8(ctx, ans), err + }} + properties[2] = ITProperty{"motion", 4, + func(ctx context.Context) (<-chan []byte, error) { + ans, err := dev.WatchMotion(ctx) + return converterMotionValues(ctx, ans), err + }} + properties[3] = ITProperty{"stepcount", 5, + func(ctx context.Context) (<-chan []byte, error) { + ans, err := dev.WatchStepCount(ctx) + return converterU32(ctx, ans), err + }} + properties[4] = ITProperty{"version", 6, + func(ctx context.Context) (<-chan []byte, error) { + ans, err := dev.Version() + return converter1String(ctx, ans), err + }} + properties[5] = ITProperty{"address", 7, + func(ctx context.Context) (<-chan []byte, error) { + ans := dev.Address() + return converter1String(ctx, ans), nil + }} + +} + + + var myfs *blefs.FS = nil; var inodemap map[string]uint64 = nil;