Added FUSE support #55
@ -1,61 +0,0 @@
|
|||||||
package fusefs
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.arsenm.dev/infinitime"
|
|
||||||
"context"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
func converterU8(ctx context.Context, in <-chan uint8) <-chan []byte {
|
|
||||||
out := make(chan []byte, 2)
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <- ctx.Done():
|
|
||||||
return
|
|
||||||
case event := <-in:
|
|
||||||
out <- []byte(strconv.Itoa(int(event)) + "\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func converterU32(ctx context.Context, in <-chan uint32) <-chan []byte {
|
|
||||||
out := make(chan []byte, 2)
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <- ctx.Done():
|
|
||||||
return
|
|
||||||
case event := <-in:
|
|
||||||
out <- []byte(strconv.Itoa(int(event)) + "\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func converterMotionValues(ctx context.Context, in <-chan infinitime.MotionValues) <-chan []byte {
|
|
||||||
out := make(chan []byte, 2)
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <- ctx.Done():
|
|
||||||
return
|
|
||||||
case event := <-in:
|
|
||||||
out <- []byte(strconv.Itoa(int(event.X)) + " " + strconv.Itoa(int(event.Y)) + " " + strconv.Itoa(int(event.Z)) + "\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func converter1String(ctx context.Context, in string) <-chan []byte {
|
|
||||||
out := make(chan []byte, 2)
|
|
||||||
out <- []byte(in + "\n")
|
|
||||||
close(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -10,13 +10,13 @@ import (
|
|||||||
"github.com/hanwen/go-fuse/v2/fuse"
|
"github.com/hanwen/go-fuse/v2/fuse"
|
||||||
"io"
|
"io"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ITProperty struct {
|
type ITProperty struct {
|
||||||
name string
|
name string
|
||||||
Ino uint64
|
Ino uint64
|
||||||
oneshot bool
|
gen func() ([]byte, error)
|
||||||
gen func(context.Context) (<-chan []byte, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -55,40 +55,35 @@ func BuildRootNode(dev *infinitime.Device) (*ITNode, error) {
|
|||||||
var properties = make([]ITProperty, 6)
|
var properties = make([]ITProperty, 6)
|
||||||
|
|
||||||
func BuildProperties(dev *infinitime.Device) {
|
func BuildProperties(dev *infinitime.Device) {
|
||||||
properties[0] = ITProperty{"heartrate", 2, true,
|
properties[0] = ITProperty{"heartrate", 2,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func() ([]byte, error) {
|
||||||
ans, err := dev.WatchHeartRate(ctx)
|
ans, err := dev.HeartRate()
|
||||||
return converterU8(ctx, ans), err
|
return []byte(strconv.Itoa(int(ans)) + "\n"), err
|
||||||
}}
|
}}
|
||||||
properties[1] = ITProperty{"battery", 3, true,
|
properties[1] = ITProperty{"battery", 3,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func() ([]byte, error) {
|
||||||
ans, err := dev.WatchBatteryLevel(ctx)
|
ans, err := dev.BatteryLevel()
|
||||||
return converterU8(ctx, ans), err
|
return []byte(strconv.Itoa(int(ans)) + "\n"), err
|
||||||
}}
|
}}
|
||||||
properties[2] = ITProperty{"motion", 4, true,
|
properties[2] = ITProperty{"motion", 4,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func() ([]byte, error) {
|
||||||
ans, err := dev.WatchMotion(ctx)
|
ans, err := dev.Motion()
|
||||||
return converterMotionValues(ctx, ans), err
|
return []byte(strconv.Itoa(int(ans.X)) + " " + strconv.Itoa(int(ans.Y)) + " " + strconv.Itoa(int(ans.Z)) + "\n"), err
|
||||||
}}
|
}}
|
||||||
properties[3] = ITProperty{"motion", 5, true,
|
properties[3] = ITProperty{"stepcount", 6,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func() ([]byte, error) {
|
||||||
ans, err := dev.WatchMotion(ctx)
|
ans, err := dev.StepCount()
|
||||||
return converterMotionValues(ctx, ans), err
|
return []byte(strconv.Itoa(int(ans)) + "\n"), err
|
||||||
}}
|
}}
|
||||||
properties[4] = ITProperty{"stepcount", 6, true,
|
properties[4] = ITProperty{"version", 7,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func() ([]byte, error) {
|
||||||
ans, err := dev.WatchStepCount(ctx)
|
|
||||||
return converterU32(ctx, ans), err
|
|
||||||
}}
|
|
||||||
properties[5] = ITProperty{"version", 7, true,
|
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
|
||||||
ans, err := dev.Version()
|
ans, err := dev.Version()
|
||||||
return converter1String(ctx, ans), err
|
return []byte(ans + "\n"), err
|
||||||
}}
|
}}
|
||||||
properties[6] = ITProperty{"address", 8, true,
|
properties[5] = ITProperty{"address", 8,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func() ([]byte, error) {
|
||||||
ans := dev.Address()
|
ans := dev.Address()
|
||||||
return converter1String(ctx, ans), nil
|
return []byte(ans + "\n"), nil
|
||||||
}}
|
}}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user