Commits

Craig Swank committed a9b25c2 Merge

Merge branch 'master' of bitbucket.org:cswank/gadgets

Comments (0)

Files changed (5)

examples/greenhouse.py

 arguments = {
     'locations': {
         'bed one': {
-            'valve': {
+            'pump': {
                 'type': 'shift register switch',
-                'channel': 0,
+                'channel': 2,
                 },
-            'siphon': {
+            'float_switch': {
                 'type': 'input',
                 'input_type': 'gpio',
                 'pin': pins['gpio'][8][11],
                 }
             },
         'bed two': {
-            'valve': {
+            'pump': {
                 'type': 'shift register switch',
                 'channel': 1,
                 },
-            'siphon': {
+            'float_switch': {
                 'type': 'input',
                 'input_type': 'gpio',
                 'pin': pins['gpio'][8][14],
                 }
             },
         'bed three': {
-            'valve': {
+            'pump': {
                 'type': 'shift register switch',
-                'channel': 2,
+                'channel': 3,
                 },
-            'siphon': {
+            'float_switch': {
                 'type': 'input',
                 'input_type': 'gpio',
                 'pin': pins['gpio'][8][12],
                 }
             },
         'fish tank': {
-            'pump': {
-                'type': 'shift register switch',
-                'channel': 3,
-                },
+            'temperature': {
+                'type': 'thermometer',
+                'uid': '28-00000400bc1a'
+                }
             },
         'garage': {
             'temperature': {
     my aquaponics greenhouse.
     """
 
-    _siphons = {
-        'bed one siphon': 135,
-        'bed two siphon': 150,
-        'bed three siphon': 135
+    _float_switches = {
+        'bed one float_switch': 135,
+        'bed two float_switch': 150,
+        'bed three float_switch': 150
         }
 
     def event_received(self, event, message):
         sender = message.get('sender')
-        if sender in self._siphons:
-            location = sender.replace(' siphon', '')
-            self.sockets.send('turn off {0} valve'.format(location))
-            if self._all_valves_closed(message):
-                self.sockets.send('turn off fish tank pump')
-            self._start_timer(sender)
+        if sender in self._float_switches and self._float_switch_is_open(sender, message):
+            location = sender.replace(' float_switch', '')
+            self.sockets.send('turn off {0} pump'.format(location))
+            self._start_timer(location)
+
+    def _float_switch_is_open(self, sender, message):
+        location = sender.replace(' float_switch', '')
+        return not message.get('locations', {}).get(location, {}).get('input', {}).get('float_switch', {}).get('value')
             
     @property
     def events(self):
         return ['UPDATE']
 
     def on_start(self):
-        self.sockets.send('turn on bed one valve')
-        self.sockets.send('turn on bed two valve')
-        self.sockets.send('turn on bed three valve')
-        self.sockets.send('turn on fish tank pump')
+        self.sockets.send('turn on bed one pump')
+        self.sockets.send('turn on bed two pump')
+        self.sockets.send('turn on bed three pump')
 
     def _start_timer(self, location):
-        countdown = self._siphons['{0} siphon'.format(location)]
-        t = threading.Thread(target=self._siphon_finished, args=(location, countdown))
+        countdown = self._float_switches['{0} float_switch'.format(location)]
+        t = threading.Thread(target=self._float_switch_finished, args=(location, countdown))
         t.start()
 
-    def _siphon_finished(self, location, countdown):
+    def _float_switch_finished(self, location, countdown):
         time.sleep(countdown)
         s = self._get_sockets()
-        msg = 'turn on {0} valve'.format(location)
+        msg = 'turn on {0} pump'.format(location)
         s.send(msg)
         time.sleep(0.5)
-        s.send('turn on fish tank pump')
         s.close()
 
-    def _all_valves_closed(self, message):
-        """
-        >>> addresses = Addresses()
-        >>> siphons = Siphons('na', 'siphons monitor', addresses)
-        >>> msg = {
-        ...    'locations': {
-        ...        'bed one': {
-        ...            'output': {
-        ...                'valve': {
-        ...                    'value': True
-        ...                    }
-        ...                }
-        ...            },
-        ...        'bed two': {
-        ...            'output': {
-        ...                'valve': {
-        ...                    'value': False
-        ...                    }
-        ...                }
-        ...            },
-        ...        'bed three': {
-        ...            'output': {
-        ...                'valve': {
-        ...                    'value': True
-        ...                    }
-        ...                }
-        ...            }
-        ...        }
-        ...    }
-        >>> siphons._all_valves_closed(msg)
-        False
-        >>> msg = {
-        ...    'locations': {
-        ...        'bed one': {
-        ...            'output': {
-        ...                'valve': {
-        ...                    'value': False
-        ...                    }
-        ...                }
-        ...            },
-        ...        'bed two': {
-        ...            'output': {
-        ...                'valve': {
-        ...                    'value': False
-        ...                    }
-        ...                }
-        ...            },
-        ...        'bed three': {
-        ...            'output': {
-        ...                'valve': {
-        ...                    'value': True
-        ...                    }
-        ...                }
-        ...            }
-        ...        }
-        ...    }
-        >>> siphons._all_valves_closed(msg)
-        False
-        >>> msg = {
-        ...    'locations': {
-        ...        'bed one': {
-        ...            'output': {
-        ...                'valve': {
-        ...                    'value': False
-        ...                    }
-        ...                }
-        ...            },
-        ...        'bed two': {
-        ...            'output': {
-        ...                'valve': {
-        ...                    'value': False
-        ...                    }
-        ...                }
-        ...            },
-        ...        'bed three': {
-        ...            'output': {
-        ...                'valve': {
-        ...                    'value': False
-        ...                    }
-        ...                }
-        ...            }
-        ...        }
-        ...    }
-        >>> siphons._all_valves_closed(msg)
-        True
-        """
-        for siphon in self._siphons:
-            location = siphon.replace(' siphon', '')
-            val = message.get('locations', {}).get(location, {}).get('output', {}).get('valve', {}).get('value')
-            if val:
-                return False
-        return True
-
     def _register(self):
         pass
             

gadgets/coordinator.py

             self._update_method(message)
         else:
             self._update_location(message)
-            self._state['sender'] = message.get('sender')
         self.sockets.send('UPDATE', self._state)
         
     def _is_valid_update_message(self, message):

gadgets/devices/input/io.py

         if self._ticks:
             delta = self._end - self._start
             return self._ticks / delta.total_seconds(), 'ticks/second'
-        ret = val == '1\n' and 'closed' or 'open'
-        return ret, 'boolean'
+        return val == '1\n', 'boolean'

gadgets/io/poller.py

             self._timeout = -1
 
     def _setup_pin(self, pin):
-        mux = pin['mux']
+        mux = pin.get('mux')
         export = pin['export']
         self._path = self._base_path.format(export, 'value')
-        self._write_to_path('27', self._mux_path.format(mux))
+        if mux:
+            self._write_to_path('27', self._mux_path.format(mux))
         self._write_to_path(str(export), self._export_path)
         self._write_to_path('in', self._base_path.format(export, 'direction'))
         self._write_to_path(self._edge, self._base_path.format(export, 'edge'))

gadgets/pins/beaglebone_black.py

             },
         },
         9: {
+            12: {
+                'export':60
+            },
+            14: {
+                'export':50
+            },
+            15: {
+                'export':48
+            },
+            16: {
+                'export':51
+            },
         }
     },
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.