123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- # Copyright 2017 Digital
- #
- # This file is part of DigiLib.
- #
- # DigiLib is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # DigiLib is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with DigiLib. If not, see <http://www.gnu.org/licen
- import logging
- log = logging.getLogger(__name__+"")
- lctrl = logging.getLogger(__name__+".ctrl")
- import curio
- import digilib.network
- import digilib.misc
- import digilib.gpio.wrapper
- class ControllerBase(object):
- """
- ControllerBase is the baseclass for Controller. All collectors need to inherit from CollectorBase or provide the same methods.
- A collector collects information form sensors and puts them in a pipe, so the CtrlManager can access it. The minutely, hourly and daily methods are easy to use but there execution time depends on when the core was started. use curio's execute_at feature to execute a function at a specific time.
- Parameters
- ----------
- """
- def __init__(self):
- """
- during initilazion, a Controller should register its methods.
- """
- super().__init__()
- async def collect_loadcell_data(self):
- """
- This method collects data from a sensor.
- """
- async def daily(self):
- """
- This method is called once every day by the core.
- """
- async def hourly(self):
- """
- This method is called once every hour by the core.
- """
- async def main_loop(self):
- """
- This is the main loop of the Controller class.
- """
- async def minutely(self):
- """
- This method is called once every minute by the core.
- """
- async def on_startup(self):
- """
- This method is called by the core when it starts. This is a good entry point for a Controller class, however the main_loop should be in a different method wich can be called here.
- """
- # self.main_loop()
- async def on_shutdown(self):
- """
- This method is called by the core when it shuts down.
- """
- class ButtonController(object):
- """
- ButtonController can be used with a hardware push button. It provides events you can register a callback to, join it or test the buttons state.
- .. A collector collects information form sensors and puts them in a pipe, so the CtrlManager can access it. The minutely, hourly and daily methods are easy to use but there execution time depends on when the core was started. use curio's execute_at feature to execute a function at a specific time.
- Parameters
- ----------
- pin_num: int
- the number of the pin wich is connected to the button and to logical HIGH through an appropriate resistor.
- """
- def __init__(self,pin_num):
- """
- """
- super().__init__()
- self.pin_num = pin_num
- digilib.gpio.wrapper.setup(self.pin_num,digilib.gpio.wrapper.OUT)
- async def read_button_state(self):
- """
- This method reads the current state from the button's gpio pin.
- """
- return digilib.gpio.wrapper.read(self.pin_num)
- async def daily(self):
- """
- This method is called once every day by the core.
- """
- async def hourly(self):
- """
- This method is called once every hour by the core.
- """
- async def main_loop(self):
- """
- This is the main loop of the Controller class.
- """
- async def minutely(self):
- """
- This method is called once every minute by the core.
- """
- async def on_startup(self):
- """
- This method is called by the core when it starts. This is a good entry point for a Controller class, however the main_loop should be in a different method wich can be called here.
- """
- # self.main_loop()
- async def on_shutdown(self):
- """
- This method is called by the core when it shuts down.
- """
- #
|