__init__.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python3.5
  2. # Copyright 2017 Digital
  3. #
  4. # This file is part of BeeWatch.
  5. #
  6. # BeeWatch is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # BeeWatch is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with BeeWatch. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Python Libraries
  20. import curio
  21. import logging
  22. import threaing
  23. import time
  24. # My Libraries
  25. import digilib.pin
  26. log = logging.getLogger(__name__+"")
  27. lpin = logging.getLogger(__name__+".pin")
  28. # log = logging.getLogger(__name__+"")
  29. print("*"*20)
  30. print("USE TRIO WHEN CODING THE PIN STUFF")
  31. print("this message is printed by {}".format(__file__))
  32. print("*"*20)
  33. class LoadCell(digilib.pin.PinControllerBase):
  34. """interface for a single load cell"""
  35. pass
  36. class BeeWeighingScale(digilib.pin.PinAPIBase):
  37. """handles all load cells"""
  38. pass
  39. class PinAPIBee(digilib.pin.PinAPIBase):
  40. engine_left = None
  41. engine_right = None
  42. action_in_process = False
  43. def __init__(self):
  44. super(PinAPIBee,self).__init__()
  45. self.engine_right = self.make_engine(4,17)
  46. self.engine_left = self.make_engine(27,22)
  47. def __enter__(self):
  48. if self.action_in_process:
  49. lpin.debug("action already in process, not entering")
  50. return False
  51. def make_engine(self,*args):
  52. return digilib.pin.PCEngine(*args)
  53. def turn(self,direction,respond_method):
  54. lpin.debug(threading.current_thread())
  55. with self ad
  56. lpin.info("turning {}".format(direction))
  57. right_state = self.engine_right.is_on
  58. right_speed = self.engine_right.speed
  59. left_state = self.engine_left.is_on
  60. left_speed = self.engine_left.speed
  61. if direction == "right":
  62. self.engine_right.set_state(False)
  63. self.engine_left.set_state(True)
  64. self.engine_left.set_speed(1)
  65. elif direction == "left":
  66. self.engine_right.set_state(True)
  67. self.engine_right.set_speed(1)
  68. self.engine_left.set_state(False)
  69. # curio.sleep(2)
  70. time.sleep(2)
  71. self.engine_right.set_state(right_state)
  72. self.engine_right.set_speed(right_speed)
  73. self.engine_left.set_state(left_state)
  74. self.engine_left.set_speed(left_speed)
  75. lpin.info("done turning {}".format(direction))
  76. # set engines to previous values
  77. def turn_left(self,respond_method):
  78. self.turn("left")
  79. def turn_right(self):
  80. self.turn("right")