forked from Elara6331/itd
		
	Add context support and update lrpc
This commit is contained in:
		| @@ -1,12 +1,15 @@ | ||||
| package api | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
|  | ||||
| 	"go.arsenm.dev/infinitime" | ||||
| ) | ||||
|  | ||||
| func (c *Client) FirmwareUpgrade(upgType UpgradeType, files ...string) (chan infinitime.DFUProgress, error) { | ||||
| func (c *Client) FirmwareUpgrade(ctx context.Context, upgType UpgradeType, files ...string) (chan infinitime.DFUProgress, error) { | ||||
| 	progressCh := make(chan infinitime.DFUProgress, 5) | ||||
| 	err := c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"FirmwareUpgrade", | ||||
| 		FwUpgradeData{ | ||||
|   | ||||
							
								
								
									
										20
									
								
								api/fs.go
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								api/fs.go
									
									
									
									
									
								
							| @@ -1,7 +1,10 @@ | ||||
| package api | ||||
|  | ||||
| func (c *Client) Remove(paths ...string) error { | ||||
| import "context" | ||||
|  | ||||
| func (c *Client) Remove(ctx context.Context, paths ...string) error { | ||||
| 	return c.client.Call( | ||||
| 		ctx, | ||||
| 		"FS", | ||||
| 		"Remove", | ||||
| 		paths, | ||||
| @@ -9,8 +12,9 @@ func (c *Client) Remove(paths ...string) error { | ||||
| 	) | ||||
| } | ||||
|  | ||||
| func (c *Client) Rename(old, new string) error { | ||||
| func (c *Client) Rename(ctx context.Context, old, new string) error { | ||||
| 	return c.client.Call( | ||||
| 		ctx, | ||||
| 		"FS", | ||||
| 		"Rename", | ||||
| 		[2]string{old, new}, | ||||
| @@ -18,8 +22,9 @@ func (c *Client) Rename(old, new string) error { | ||||
| 	) | ||||
| } | ||||
|  | ||||
| func (c *Client) Mkdir(paths ...string) error { | ||||
| func (c *Client) Mkdir(ctx context.Context, paths ...string) error { | ||||
| 	return c.client.Call( | ||||
| 		ctx, | ||||
| 		"FS", | ||||
| 		"Mkdir", | ||||
| 		paths, | ||||
| @@ -27,8 +32,9 @@ func (c *Client) Mkdir(paths ...string) error { | ||||
| 	) | ||||
| } | ||||
|  | ||||
| func (c *Client) ReadDir(dir string) (out []FileInfo, err error) { | ||||
| func (c *Client) ReadDir(ctx context.Context, dir string) (out []FileInfo, err error) { | ||||
| 	err = c.client.Call( | ||||
| 		ctx, | ||||
| 		"FS", | ||||
| 		"ReadDir", | ||||
| 		dir, | ||||
| @@ -37,9 +43,10 @@ func (c *Client) ReadDir(dir string) (out []FileInfo, err error) { | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (c *Client) Upload(dst, src string) (chan FSTransferProgress, error) { | ||||
| func (c *Client) Upload(ctx context.Context, dst, src string) (chan FSTransferProgress, error) { | ||||
| 	progressCh := make(chan FSTransferProgress, 5) | ||||
| 	err := c.client.Call( | ||||
| 		ctx, | ||||
| 		"FS", | ||||
| 		"Upload", | ||||
| 		[2]string{dst, src}, | ||||
| @@ -52,9 +59,10 @@ func (c *Client) Upload(dst, src string) (chan FSTransferProgress, error) { | ||||
| 	return progressCh, nil | ||||
| } | ||||
|  | ||||
| func (c *Client) Download(dst, src string) (chan FSTransferProgress, error) { | ||||
| func (c *Client) Download(ctx context.Context, dst, src string) (chan FSTransferProgress, error) { | ||||
| 	progressCh := make(chan FSTransferProgress, 5) | ||||
| 	err := c.client.Call( | ||||
| 		ctx, | ||||
| 		"FS", | ||||
| 		"Download", | ||||
| 		[2]string{dst, src}, | ||||
|   | ||||
							
								
								
									
										20
									
								
								api/get.go
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								api/get.go
									
									
									
									
									
								
							| @@ -1,11 +1,14 @@ | ||||
| package api | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
|  | ||||
| 	"go.arsenm.dev/infinitime" | ||||
| ) | ||||
|  | ||||
| func (c *Client) HeartRate() (out uint8, err error) { | ||||
| func (c *Client) HeartRate(ctx context.Context) (out uint8, err error) { | ||||
| 	err = c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"HeartRate", | ||||
| 		nil, | ||||
| @@ -14,8 +17,9 @@ func (c *Client) HeartRate() (out uint8, err error) { | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (c *Client) BatteryLevel() (out uint8, err error) { | ||||
| func (c *Client) BatteryLevel(ctx context.Context) (out uint8, err error) { | ||||
| 	err = c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"BatteryLevel", | ||||
| 		nil, | ||||
| @@ -24,8 +28,9 @@ func (c *Client) BatteryLevel() (out uint8, err error) { | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (c *Client) Motion() (out infinitime.MotionValues, err error) { | ||||
| func (c *Client) Motion(ctx context.Context) (out infinitime.MotionValues, err error) { | ||||
| 	err = c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"Motion", | ||||
| 		nil, | ||||
| @@ -34,8 +39,9 @@ func (c *Client) Motion() (out infinitime.MotionValues, err error) { | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (c *Client) StepCount() (out uint32, err error) { | ||||
| func (c *Client) StepCount(ctx context.Context) (out uint32, err error) { | ||||
| 	err = c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"StepCount", | ||||
| 		nil, | ||||
| @@ -44,8 +50,9 @@ func (c *Client) StepCount() (out uint32, err error) { | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (c *Client) Version() (out string, err error) { | ||||
| func (c *Client) Version(ctx context.Context) (out string, err error) { | ||||
| 	err = c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"Version", | ||||
| 		nil, | ||||
| @@ -54,8 +61,9 @@ func (c *Client) Version() (out string, err error) { | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (c *Client) Address() (out string, err error) { | ||||
| func (c *Client) Address(ctx context.Context) (out string, err error) { | ||||
| 	err = c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"Address", | ||||
| 		nil, | ||||
|   | ||||
| @@ -1,7 +1,10 @@ | ||||
| package api | ||||
|  | ||||
| func (c *Client) Notify(title, body string) error { | ||||
| import "context" | ||||
|  | ||||
| func (c *Client) Notify(ctx context.Context, title, body string) error { | ||||
| 	return c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"Notify", | ||||
| 		NotifyData{ | ||||
|   | ||||
| @@ -1,11 +1,13 @@ | ||||
| package api | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| func (c *Client) SetTime(t time.Time) error { | ||||
| func (c *Client) SetTime(ctx context.Context, t time.Time) error { | ||||
| 	return c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"SetTime", | ||||
| 		t, | ||||
|   | ||||
| @@ -1,7 +1,10 @@ | ||||
| package api | ||||
|  | ||||
| func (c *Client) WeatherUpdate() error { | ||||
| import "context" | ||||
|  | ||||
| func (c *Client) WeatherUpdate(ctx context.Context) error { | ||||
| 	return c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"WeatherUpdate", | ||||
| 		nil, | ||||
|   | ||||
							
								
								
									
										46
									
								
								api/watch.go
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								api/watch.go
									
									
									
									
									
								
							| @@ -1,81 +1,71 @@ | ||||
| package api | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
|  | ||||
| 	"go.arsenm.dev/infinitime" | ||||
| ) | ||||
|  | ||||
| func (c *Client) WatchHeartRate() (<-chan uint8, func(), error) { | ||||
| func (c *Client) WatchHeartRate(ctx context.Context) (<-chan uint8, error) { | ||||
| 	outCh := make(chan uint8, 2) | ||||
| 	err := c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"WatchHeartRate", | ||||
| 		nil, | ||||
| 		outCh, | ||||
| 	) | ||||
| 	if err != nil { | ||||
| 		return nil, nil, err | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	doneFn := func() { | ||||
| 		close(outCh) | ||||
| 	} | ||||
|  | ||||
| 	return outCh, doneFn, nil | ||||
| 	return outCh, nil | ||||
| } | ||||
|  | ||||
| func (c *Client) WatchBatteryLevel() (<-chan uint8, func(), error) { | ||||
| func (c *Client) WatchBatteryLevel(ctx context.Context) (<-chan uint8, error) { | ||||
| 	outCh := make(chan uint8, 2) | ||||
| 	err := c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"WatchBatteryLevel", | ||||
| 		nil, | ||||
| 		outCh, | ||||
| 	) | ||||
| 	if err != nil { | ||||
| 		return nil, nil, err | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	doneFn := func() { | ||||
| 		close(outCh) | ||||
| 	} | ||||
|  | ||||
| 	return outCh, doneFn, nil | ||||
| 	return outCh, nil | ||||
| } | ||||
|  | ||||
| func (c *Client) WatchStepCount() (<-chan uint32, func(), error) { | ||||
| func (c *Client) WatchStepCount(ctx context.Context) (<-chan uint32, error) { | ||||
| 	outCh := make(chan uint32, 2) | ||||
| 	err := c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"WatchStepCount", | ||||
| 		nil, | ||||
| 		outCh, | ||||
| 	) | ||||
| 	if err != nil { | ||||
| 		return nil, nil, err | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	doneFn := func() { | ||||
| 		close(outCh) | ||||
| 	} | ||||
|  | ||||
| 	return outCh, doneFn, nil | ||||
| 	return outCh, nil | ||||
| } | ||||
|  | ||||
| func (c *Client) WatchMotion() (<-chan infinitime.MotionValues, func(), error) { | ||||
| func (c *Client) WatchMotion(ctx context.Context) (<-chan infinitime.MotionValues, error) { | ||||
| 	outCh := make(chan infinitime.MotionValues, 2) | ||||
| 	err := c.client.Call( | ||||
| 		ctx, | ||||
| 		"ITD", | ||||
| 		"WatchMotion", | ||||
| 		nil, | ||||
| 		outCh, | ||||
| 	) | ||||
| 	if err != nil { | ||||
| 		return nil, nil, err | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	doneFn := func() { | ||||
| 		close(outCh) | ||||
| 	} | ||||
|  | ||||
| 	return outCh, doneFn, nil | ||||
| 	return outCh, nil | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user