-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathselector_test.py
More file actions
executable file
·92 lines (80 loc) · 2.61 KB
/
selector_test.py
File metadata and controls
executable file
·92 lines (80 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2020-2021 by Murray Altheim. All rights reserved. This file is part
# of the Robot Operating System project, released under the MIT License. Please
# see the LICENSE file included as part of this package.
#
# author: Murray Altheim
# created: 2021-01-02
# modified: 2021-01-02
#
# Provides a six-position selector with colored knob indicator for each of
# the 60 degree quadrants.
#
# R
#
# M Y
#
# B G
#
# C
#
import pytest
import sys, traceback
from colorama import init, Fore, Style
init()
from lib.i2c_scanner import I2CScanner
from lib.config_loader import ConfigLoader
from lib.rate import Rate
from lib.logger import Logger, Level
from lib.selector import Selector
# ..............................................................................
@pytest.mark.unit
def test_selector():
_log = Logger("sel-test", Level.INFO)
# _i2c_scanner = I2CScanner(Level.WARN)
# if not _i2c_scanner.has_address([0x0F]):
# _log.warning('test ignored: no rotary encoder found.')
# return
_selector = None
try:
# read YAML configuration
_loader = ConfigLoader(Level.INFO)
filename = 'config.yaml'
_config = _loader.configure(filename)
_selector = Selector(_config, Level.INFO)
_count = 0
_updates = 0
_rate = Rate(20)
_last_value = 0
_limit = 45
_log.info('live-updating from rotary encoder...')
while _updates < _limit:
_value = _selector.read()
if _value != _last_value:
_updates += 1
_log.info(Style.BRIGHT + 'returned value: {:d}; updates remaining: {:d}'.format(_value, _limit - _updates))
else:
_log.info(Style.DIM + 'returned value: {:d}; updates remaining: {:d}'.format(_value, _limit - _updates))
_last_value = _value
_count += 1
if _count % 33 == 0:
_log.info('waiting…')
_rate.wait()
finally:
if _selector:
_selector.reset()
# main .........................................................................
_rot = None
def main(argv):
try:
test_selector()
except KeyboardInterrupt:
print(Fore.CYAN + 'caught Ctrl-C; exiting...' + Style.RESET_ALL)
except Exception:
print(Fore.RED + 'error starting ros: {}'.format(traceback.format_exc()) + Style.RESET_ALL)
# call main ....................................................................
if __name__== "__main__":
main(sys.argv[1:])
#EOF