3. Added builder

This commit is contained in:
Yannick Ulrich 2023-03-01 15:14:06 +00:00
parent 8dd8f3d012
commit 87c78566c1
2 changed files with 46 additions and 33 deletions

35
fuse.go
View File

@ -12,7 +12,7 @@ import (
func startFuse(ctx context.Context, dev *infinitime.Device) error { func startFuse(ctx context.Context, dev *infinitime.Device) error {
// This is where we'll mount the FS // This is where we'll mount the FS
os.Mkdir(k.String("fuse.mountpoint"), 0755) 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{ server, err := fs.Mount(k.String("fuse.mountpoint"), root, &fs.Options{
MountOptions: fuse.MountOptions{ MountOptions: fuse.MountOptions{
// Set to true to see how the file system works. // 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")). Str("target", k.String("fuse.mountpoint")).
Send() Send()
properties[0] = ITProperty{"heartrate", 2, fusefs.BuildProperties(dev)
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 { if err != nil {
log.Warn("Error getting BLE filesystem").Err(err).Send() log.Warn("Error getting BLE filesystem").Err(err).Send()
return err return err
} }
inodemap = make(map[string]uint64)
// Wait until unmount before exiting // Wait until unmount before exiting
go server.Serve() go server.Serve()

View File

@ -89,7 +89,51 @@ type ITNode struct {
path string 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) 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 myfs *blefs.FS = nil;
var inodemap map[string]uint64 = nil; var inodemap map[string]uint64 = nil;