base.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from alphasign import constants
  2. from alphasign import packet
  3. class BaseInterface(object):
  4. def write(self, data):
  5. pass
  6. def clear_memory(self):
  7. """Clear the sign's memory.
  8. """
  9. pkt = packet.Packet("%s%s" % (constants.WRITE_SPECIAL, "$"))
  10. self.write(pkt)
  11. def beep(self, frequency=0, duration=0.1, repeat=0):
  12. """Make the sign beep.
  13. Args:
  14. frequency: frequency integer (not in Hz), 0 - 254
  15. duration: beep duration, 0.1 - 1.5
  16. repeat: number of times to repeat, 0 - 15
  17. """
  18. if frequency < 0:
  19. frequency = 0
  20. elif frequency > 254:
  21. frequency = 254
  22. duration = int(duration / 0.1)
  23. if duration < 1:
  24. duration = 1
  25. elif duration > 15:
  26. duration = 15
  27. if repeat < 0:
  28. repeat = 0
  29. elif repeat > 15:
  30. repeat = 15
  31. pkt = packet.Packet("%s%s%02X%X%X" % (constants.WRITE_SPECIAL, "(2",
  32. frequency, duration, repeat))
  33. self.write(pkt)
  34. def soft_reset(self):
  35. """Perform a soft reset on the sign.
  36. This is non-destructive and does not clear the sign's memory.
  37. """
  38. pkt = packet.Packet("%s%s" % (constants.WRITE_SPECIAL, ","))
  39. self.write(pkt)