mirror of
https://github.com/gryf/linak-ctrl.git
synced 2025-12-20 04:38:01 +01:00
Rearranged argument parsing.
This commit is contained in:
@@ -113,8 +113,8 @@ class LinakDevice:
|
|||||||
if self._dev.is_kernel_driver_active(0):
|
if self._dev.is_kernel_driver_active(0):
|
||||||
self._dev.detach_kernel_driver(0)
|
self._dev.detach_kernel_driver(0)
|
||||||
|
|
||||||
def get_position(self, loop=False):
|
def get_position(self, args):
|
||||||
if loop:
|
if args.loop:
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
report = self._get_report()
|
report = self._get_report()
|
||||||
@@ -126,21 +126,21 @@ class LinakDevice:
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
report = self._get_report()
|
report = self._get_report()
|
||||||
LOG.warning('Position: %s, height: %scm, moving: %s',
|
LOG.warning('Position: %s, height: %.2fcm, moving: %s',
|
||||||
report.position, report.position_in_cm, report.moving)
|
report.position, report.position_in_cm, report.moving)
|
||||||
|
|
||||||
def move(self, position):
|
def move(self, args):
|
||||||
retry_count = 3
|
retry_count = 3
|
||||||
previous_position = 0
|
previous_position = 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
self._move(position)
|
self._move(args.position)
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
||||||
status_report = self._get_report()
|
status_report = self._get_report()
|
||||||
LOG.info("Current position: %s", status_report.position)
|
LOG.info("Current position: %s", status_report.position)
|
||||||
|
|
||||||
if status_report.position == position:
|
if status_report.position == args.position:
|
||||||
break
|
break
|
||||||
|
|
||||||
if previous_position == status_report.position:
|
if previous_position == status_report.position:
|
||||||
@@ -177,6 +177,8 @@ class LinakDevice:
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
device = LinakDevice()
|
||||||
|
|
||||||
parser = argparse.ArgumentParser('An utility to interact with USB2LIN06 '
|
parser = argparse.ArgumentParser('An utility to interact with USB2LIN06 '
|
||||||
'device.')
|
'device.')
|
||||||
subparsers = parser.add_subparsers(help='supported commands',
|
subparsers = parser.add_subparsers(help='supported commands',
|
||||||
@@ -186,10 +188,12 @@ def main():
|
|||||||
'device.')
|
'device.')
|
||||||
parser_status.add_argument('-l', '--loop', help='run indefinitely, use '
|
parser_status.add_argument('-l', '--loop', help='run indefinitely, use '
|
||||||
'ctrl-c to stop.', action="store_true")
|
'ctrl-c to stop.', action="store_true")
|
||||||
|
parser_status.set_defaults(func=device.get_position)
|
||||||
parser_move = subparsers.add_parser('move', help='move to the desired '
|
parser_move = subparsers.add_parser('move', help='move to the desired '
|
||||||
'height. Note, that height need to be '
|
'height. Note, that height need to be '
|
||||||
'provided as reported by status.')
|
'provided as reported by status.')
|
||||||
parser_move.add_argument('position', type=int)
|
parser_move.add_argument('position', type=int)
|
||||||
|
parser_move.set_defaults(func=device.move)
|
||||||
group = parser.add_mutually_exclusive_group()
|
group = parser.add_mutually_exclusive_group()
|
||||||
group.add_argument("-q", "--quiet", help='please, be quiet. Adding more '
|
group.add_argument("-q", "--quiet", help='please, be quiet. Adding more '
|
||||||
'"q" will decrease verbosity', action="count",
|
'"q" will decrease verbosity', action="count",
|
||||||
@@ -200,12 +204,7 @@ def main():
|
|||||||
|
|
||||||
LOG.set_verbose(args.verbose, args.quiet)
|
LOG.set_verbose(args.verbose, args.quiet)
|
||||||
|
|
||||||
device = LinakDevice()
|
args.func(args)
|
||||||
|
|
||||||
if args.subcommand == 'move':
|
|
||||||
device.move(args.position)
|
|
||||||
elif args.subcommand == 'status':
|
|
||||||
device.get_position(args.loop)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user