You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.1KB

  1. # -*- coding: utf-8 -*-
  2. import time
  3. from modules import cbpi
  4. from modules.core.hardware import ActorBase, SensorPassive, SensorActive
  5. from modules.core.props import Property
  6. try:
  7. import RPi.GPIO as GPIO
  8. GPIO.setmode(GPIO.BCM)
  9. except Exception as e:
  10. print e
  11. pass
  12. @cbpi.actor
  13. class GPIOSimple(ActorBase):
  14. gpio = Property.Select("GPIO", options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27])
  15. def init(self):
  16. GPIO.setup(int(self.gpio), GPIO.OUT)
  17. GPIO.output(int(self.gpio), 0)
  18. def on(self, power=0):
  19. print "GPIO ON %s" % str(self.gpio)
  20. GPIO.output(int(self.gpio), 1)
  21. def off(self):
  22. print "GPIO OFF"
  23. GPIO.output(int(self.gpio), 0)
  24. @cbpi.actor
  25. class GPIOPWM(ActorBase):
  26. gpio = Property.Select("GPIO", options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27])
  27. duty_cylce = Property.Number("Duty Cycle", configurable=True)
  28. p = None
  29. power = 100
  30. def init(self):
  31. GPIO.setup(int(self.gpio), GPIO.OUT)
  32. GPIO.output(int(self.gpio), 0)
  33. def on(self, power=None):
  34. if power is not None:
  35. self.power = int(power)
  36. if self.duty_cylce is None:
  37. duty_cylce = 50
  38. self.p = GPIO.PWM(int(self.gpio), int(self.duty_cylce))
  39. self.p.start(int(self.power))
  40. def set_power(self, power):
  41. if power is not None:
  42. self.power = int(power)
  43. self.p.ChangeDutyCycle(self.power)
  44. def off(self):
  45. print "GPIO OFF"
  46. self.p.stop()
  47. @cbpi.actor
  48. class RelayBoard(ActorBase):
  49. gpio = Property.Select("GPIO", options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27])
  50. def init(self):
  51. GPIO.setup(int(self.gpio), GPIO.OUT)
  52. GPIO.output(int(self.gpio), 1)
  53. def on(self, power=0):
  54. GPIO.output(int(self.gpio), 0)
  55. def off(self):
  56. GPIO.output(int(self.gpio), 1)
  57. @cbpi.actor
  58. class Dummy(ActorBase):
  59. def on(self, power=100):
  60. print "ON"
  61. def off(self):
  62. print "OFF"