Compare commits

...

3 Commits

Author SHA1 Message Date
Yannick Ulrich 1a1bc30df9 Renamed device folder 2023-03-12 12:55:44 +00:00
Yannick Ulrich c5a6e0d298 Added oneshot property to ITProperty 2023-03-12 12:43:42 +00:00
Yannick Ulrich 84c7a33c40 Added unmount function
Designed by Arsen6331
2023-03-12 12:32:56 +00:00
2 changed files with 26 additions and 12 deletions

10
fuse.go
View File

@ -11,7 +11,15 @@ 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)
err := os.MkdirAll(k.String("fuse.mountpoint"), 0755)
if err != nil && !os.IsExist(err) {
return err
}
// Ignore the error because nothing might be mounted on the mountpoint
_ = fusefs.Unmount(k.String("fuse.mountpoint"))
root, err := fusefs.BuildRootNode(dev)
if err != nil {
log.Error("Building root node failed").

View File

@ -15,6 +15,7 @@ import (
type ITProperty struct {
name string
Ino uint64
oneshot bool
gen func(context.Context) (<-chan []byte, error)
}
@ -54,32 +55,37 @@ func BuildRootNode(dev *infinitime.Device) (*ITNode, error) {
var properties = make([]ITProperty, 6)
func BuildProperties(dev *infinitime.Device) {
properties[0] = ITProperty{"heartrate", 2,
properties[0] = ITProperty{"heartrate", 2, true,
func(ctx context.Context) (<-chan []byte, error) {
ans, err := dev.WatchHeartRate(ctx)
return converterU8(ctx, ans), err
}}
properties[1] = ITProperty{"battery", 3,
properties[1] = ITProperty{"battery", 3, true,
func(ctx context.Context) (<-chan []byte, error) {
ans, err := dev.WatchBatteryLevel(ctx)
return converterU8(ctx, ans), err
}}
properties[2] = ITProperty{"motion", 4,
properties[2] = ITProperty{"motion", 4, true,
func(ctx context.Context) (<-chan []byte, error) {
ans, err := dev.WatchMotion(ctx)
return converterMotionValues(ctx, ans), err
}}
properties[3] = ITProperty{"stepcount", 5,
properties[3] = ITProperty{"motion", 5, true,
func(ctx context.Context) (<-chan []byte, error) {
ans, err := dev.WatchMotion(ctx)
return converterMotionValues(ctx, ans), err
}}
properties[4] = ITProperty{"stepcount", 6, true,
func(ctx context.Context) (<-chan []byte, error) {
ans, err := dev.WatchStepCount(ctx)
return converterU32(ctx, ans), err
}}
properties[4] = ITProperty{"version", 6,
properties[5] = ITProperty{"version", 7, true,
func(ctx context.Context) (<-chan []byte, error) {
ans, err := dev.Version()
return converter1String(ctx, ans), err
}}
properties[5] = ITProperty{"address", 7,
properties[6] = ITProperty{"address", 8, true,
func(ctx context.Context) (<-chan []byte, error) {
ans := dev.Address()
return converter1String(ctx, ans), nil
@ -97,7 +103,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
// root folder
r := make([]fuse.DirEntry, 2)
r[0] = fuse.DirEntry{
Name: "device",
Name: "info",
Ino: 0,
Mode: fuse.S_IFDIR,
}
@ -109,7 +115,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
return fs.NewListDirStream(r), 0
case 1:
// device folder
// info folder
r := make([]fuse.DirEntry, 6)
for ind, value := range properties {
r[ind] = fuse.DirEntry{
@ -122,7 +128,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
return fs.NewListDirStream(r), 0
case 2:
// on device
// on info
files, err := myfs.ReadDir(n.path)
if err != nil {
log.Error("FUSE ReadDir failed").Str("path", n.path).Err(err).Send()
@ -179,7 +185,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
switch n.kind {
case 0:
// root folder
if name == "device" {
if name == "info" {
stable := fs.StableAttr{
Mode: fuse.S_IFDIR,
Ino: uint64(0),
@ -197,7 +203,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
return child, 0
}
case 1:
// device folder
// info folder
for _, value := range properties {
if value.name == name {
stable := fs.StableAttr{