respeaker_gencfg.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Author: furushchev <furushchev@jsk.imi.i.u-tokyo.ac.jp>
4 
5 import os
6 import sys
7 from respeaker_node import PARAMETERS, init_respeaker
8 
9 
10 def main(out):
11  dev = init_respeaker()
12  if not dev:
13  print('No device found. Please connect a device.')
14  return
15  with open(out, "w") as f:
16  f.write("""\
17 #!/usr/bin/env python
18 #
19 # WARNING!!
20 # This file is automatically generated.
21 # DO NOT MODIFY THIS FILE!
22 #
23 # To generate this file, please run:
24 # cd /path/to/this/package
25 # python ./scripts/respeaker_gencfg.py
26 #
27 
28 from dynamic_reconfigure.parameter_generator_catkin import *
29 
30 gen = ParameterGenerator()
31 
32 # name type level description default min max""")
33 
34  for key, val in PARAMETERS.items():
35  type_, max_, min_, rw_ = val[2:6]
36  desc_ = " ".join(val[6:])
37  def_ = dev.read(key)
38  if rw_ != "rw":
39  continue
40  if type_ == "int" and max_ == 1 and min_ == 0:
41  if def_ == 1:
42  def_ = True
43  else:
44  def_ = False
45  f.write("""
46 gen.add("{name}", bool_t, 0, "{desc}", {def_})""".format(
47  name=key, desc=desc_, def_=def_))
48  elif type_ == "int":
49  f.write("""
50 gen.add("{name}", int_t, 0, "{desc}", {def_}, {min_}, {max_})""".format(
51  name=key, desc=desc_, def_=def_, min_=min_, max_=max_))
52  elif type_ == "float":
53  f.write("""
54 gen.add("{name}", double_t, 0, "{desc}", {def_:f}, {min_:f}, {max_:f})""".format(
55  name=key, desc=desc_, def_=def_, min_=min_, max_=max_))
56  else:
57  print "Param '{name}' is ignored.".format(name=key)
58 
59  f.write("""
60 
61 exit(gen.generate("respaker_ros", "respeaker_ros", "Respeaker"))
62 """)
63 
64  os.chmod(out, 0775)
65 
66  print "Saved cfg to %s" % out
67 
68 
69 if __name__ == '__main__':
70  if len(sys.argv) > 1:
71  outpath = sys.argv[1]
72  else:
73  outpath = os.path.join(
74  os.path.abspath(os.path.dirname(__file__)),
75  "..", "cfg", "Respeaker.cfg")
76  main(outpath)


respeaker_ros
Author(s): Yuki Furuta
autogenerated on Wed Jul 10 2019 03:47:13