From 2440cb954cd6f2c98582e0f37ee56861b29ebc8b Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sun, 26 Feb 2023 19:10:47 +0000 Subject: [PATCH] Merged two properties lists --- fuse.go | 63 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/fuse.go b/fuse.go index fc6f87c..5c3fdec 100644 --- a/fuse.go +++ b/fuse.go @@ -90,14 +90,7 @@ type ITNode struct { path string } -var properties = []ITProperty { - ITProperty{"heartrate", 2, nil}, - ITProperty{"battery", 3, nil}, - ITProperty{"motion", 4, nil}, - ITProperty{"stepcount", 5, nil}, - ITProperty{"version", 6, nil}, - ITProperty{"address", 7, nil}, -} +var properties = make([]ITProperty, 6) var myfs *blefs.FS = nil; var inodemap map[string]uint64 = nil; @@ -581,30 +574,36 @@ func startFuse(ctx context.Context, dev *infinitime.Device) error { Str("target", k.String("fuse.mountpoint")). Send() - properties[0].gen = func(ctx context.Context) (<-chan []byte, error) { - ans, err := dev.WatchHeartRate(ctx) - return converterU8(ctx, ans), err - } - properties[1].gen = func(ctx context.Context) (<-chan []byte, error) { - ans, err := dev.WatchBatteryLevel(ctx) - return converterU8(ctx, ans), err - } - properties[2].gen = func(ctx context.Context) (<-chan []byte, error) { - ans, err := dev.WatchMotion(ctx) - return converterMotionValues(ctx, ans), err - } - properties[3].gen = func(ctx context.Context) (<-chan []byte, error) { - ans, err := dev.WatchStepCount(ctx) - return converterU32(ctx, ans), err - } - properties[4].gen = func(ctx context.Context) (<-chan []byte, error) { - ans, err := dev.Version() - return converter1String(ctx, ans), err - } - properties[5].gen = func(ctx context.Context) (<-chan []byte, error) { - ans := dev.Address() - return converter1String(ctx, ans), nil - } + 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 + }} myfs, err = dev.FS() if err != nil {