123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #!/usr/bin/env python3.5
- # Copyright 2017 Digital
- #
- # This file is part of BeeWatch.
- #
- # BeeWatch 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.
- #
- # BeeWatch 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 BeeWatch. If not, see <http://www.gnu.org/licenses/>.
- #
- # Python Libraries
- import curio
- import logging
- import threaing
- import time
- # My Libraries
- import digilib.pin
- log = logging.getLogger(__name__+"")
- lpin = logging.getLogger(__name__+".pin")
- # log = logging.getLogger(__name__+"")
- print("*"*20)
- print("USE TRIO WHEN CODING THE PIN STUFF")
- print("this message is printed by {}".format(__file__))
- print("*"*20)
- class LoadCell(digilib.pin.PinControllerBase):
- """interface for a single load cell"""
- pass
- class BeeWeighingScale(digilib.pin.PinAPIBase):
- """handles all load cells"""
- pass
- class PinAPIBee(digilib.pin.PinAPIBase):
- engine_left = None
- engine_right = None
- action_in_process = False
- def __init__(self):
- super(PinAPIBee,self).__init__()
- self.engine_right = self.make_engine(4,17)
- self.engine_left = self.make_engine(27,22)
- def __enter__(self):
- if self.action_in_process:
- lpin.debug("action already in process, not entering")
- return False
- def make_engine(self,*args):
- return digilib.pin.PCEngine(*args)
- def turn(self,direction,respond_method):
- lpin.debug(threading.current_thread())
- with self ad
- lpin.info("turning {}".format(direction))
- right_state = self.engine_right.is_on
- right_speed = self.engine_right.speed
- left_state = self.engine_left.is_on
- left_speed = self.engine_left.speed
- if direction == "right":
- self.engine_right.set_state(False)
- self.engine_left.set_state(True)
- self.engine_left.set_speed(1)
- elif direction == "left":
- self.engine_right.set_state(True)
- self.engine_right.set_speed(1)
- self.engine_left.set_state(False)
- # curio.sleep(2)
- time.sleep(2)
- self.engine_right.set_state(right_state)
- self.engine_right.set_speed(right_speed)
- self.engine_left.set_state(left_state)
- self.engine_left.set_speed(left_speed)
- lpin.info("done turning {}".format(direction))
- # set engines to previous values
- def turn_left(self,respond_method):
- self.turn("left")
- def turn_right(self):
- self.turn("right")
|