Преглед изворни кода

minor bugfixes, added test commands/controllers

digital пре 8 година
родитељ
комит
5e37f3848b
4 измењених фајлова са 69 додато и 11 уклоњено
  1. 54 0
      config/commands.yaml
  2. 6 2
      config/controllers.yaml
  3. 1 1
      lib/beewatch/__init__.py
  4. 8 8
      lib/beewatch/server/__init__.py

+ 54 - 0
config/commands.yaml

@@ -2,3 +2,57 @@ commands:
     turn:
         controller: engines_ctrl
         function: turn
+    led_1_on:
+        controller: led_test_1
+        function: "on"
+    led_1_off:
+        controller: led_test_1
+        function: "off"
+    led_2_on:
+        controller: led_test_2
+        function: "on"
+    led_2_off:
+        controller: led_test_2
+        function: "off"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 6 - 2
config/controllers.yaml

@@ -3,8 +3,12 @@ controllers:
         target: digilib.pin.EnginesController
         left: [4,17]
         right: [27,22]
-
-
+    led_test_1:
+        target: digilib.pin.LED
+        pin: 5
+    led_test_2:
+        target: digilib.pin.LED
+        pin: 6
 
 
 

+ 1 - 1
lib/beewatch/__init__.py

@@ -69,7 +69,7 @@ class Configure(object):
             if not callable(ctrl):
                 if ctrl not in _controllers.keys():
                     raise ValueError("No controller found with name " + ctrl)
-                ctrl = _controllers[ctrl]
+            ctrl = _controllers[ctrl]
             if not hasattr(ctrl,function):
                 raise ValueError(
                     "{} doesn't have attribute {}".format(ctrl,function))

+ 8 - 8
lib/beewatch/server/__init__.py

@@ -58,7 +58,7 @@ class ConnHandlerBeeWatch(digilib.network.ConnHandlerBase):
         self.text_to_func = {
             "turn":self.engines_ctrl.turn
         }
-    def call(self,func_name,args,respond_method,kwargs):
+    def call(self,func_name,args,respond,kwargs):
         ttf = beewatch._commands
         if func_name in ttf.keys():
             try:
@@ -66,16 +66,16 @@ class ConnHandlerBeeWatch(digilib.network.ConnHandlerBase):
                     ttf[func_name](
                         # self.bee_api,
                         *args,
-                        respond_method=respond_method,
+                        respond=respond,
                         **kwargs,
                     )
                 )
             except:
                 tb = traceback.format_exc()
                 print(tb)
-                respond_method(tb)
+                respond(tb)
         else:
-            respond_method("Unknown command")
+            respond("Unknown command")
     def welcome_client(self):
         self.send("this is the server speaking, hello new client!")
     def handle(self, data_decoded):
@@ -90,21 +90,21 @@ class ConnHandlerBeeWatch(digilib.network.ConnHandlerBase):
         kwargs = {}
         self.call(
             cmd,
-            respond_method=self.respond,
+            respond=self.respond,
             args=args,
             kwargs={},
         )
-    def do(self,func_num,*args,respond_method):
+    def do(self,func_num,*args,respond):
         arg_to_func = {
             "1":self.bee_api.do_something_1,
             "2":self.bee_api.do_something_2,
             "3":self.bee_api.do_something_3,
         }
-        arg_to_func[func_num](*args,respond_method=respond_method)
+        arg_to_func[func_num](*args,respond=respond)
     def echo(self,*args,**kwargs):
         lchat.info(str(args))
         lchat.info(str(kwargs))
-    def speedcheck(self,respond_method):
+    def speedcheck(self,respond):
         left_speed=str(self.bee_api.c.movement_control.get_speed("left"))
         right_speed=str(self.bee_api.c.movement_control.get_speed("right"))
         result = "left: "+left_speed+", right: "+right_speed