Skip to content

Commit 8bb8555

Browse files
committed
rpc_wrappers: gravity_reference_update: added
Add a wrapper for the gravity reference update command. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 9378cc1 commit 8bb8555

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
3+
import errno
4+
import os
5+
6+
import infuse_iot.generated.rpc_definitions as defs
7+
from infuse_iot.commands import InfuseRpcCommand
8+
9+
10+
class gravity_reference_update(InfuseRpcCommand, defs.gravity_reference_update):
11+
@classmethod
12+
def add_parser(cls, parser):
13+
parser.add_argument("--variance", type=int, default=0, help="Maximum axis variance to accept")
14+
15+
def __init__(self, args):
16+
self._max_variance = args.variance
17+
18+
def request_struct(self):
19+
return self.request(self._max_variance)
20+
21+
def request_json(self):
22+
return {"max_variance": str(self._max_variance)}
23+
24+
def handle_response(self, return_code, response):
25+
r = response
26+
27+
if return_code == -errno.EIO:
28+
print(f"IMU variance too large: {r.variance.x:6d} {r.variance.y:6d} {r.variance.z:6d}")
29+
return
30+
elif return_code < 0:
31+
print(f"Failed to update gravity reference vector ({os.strerror(-return_code)})")
32+
return
33+
34+
print(f"\t Gravity: {r.reference.x:6d} {r.reference.y:6d} {r.reference.z:6d}")
35+
print(f"\t Variance: {r.variance.x:6d} {r.variance.y:6d} {r.variance.z:6d}")
36+
print(f"\t Samples: {r.num_samples:d}")
37+
print(f"\t Period: {r.sample_period_us:d} us")

0 commit comments

Comments
 (0)