From Mark Clohesy, 5 Months ago, written in Python.
This paste will shuffle off the mortal coil in 1 Second.
Embed
  1. #!/usr/bin/python3
  2. #
  3. # DC-Panel.py
  4. # Python Ver 3
  5. # Linux Systems
  6. # Author Mark 'POCKETS' Clohesy
  7. # hamshack.org
  8. #
  9. ################################################################################################################
  10. #
  11. # This is a linux CLI program sends serial commands to the an arduino that switches a
  12. # radio shack control panel via a relay control board.
  13. #
  14. # It uses the letters A-F. Uppercase turns the relay on while lowercase turns it off the panel
  15. # has 6 swirches and relays hence A-F. A CLI program was choosen over a GUI as the code can be modified
  16. # with pygame to have a GUI or broken down in  to small parts and modules that would allow control with
  17. # things like cron or ifttt makers channel in the future.
  18. #
  19. # These are the devices that are being controlled
  20. #
  21. # A- Radio 1 FT8900
  22. # B- Radio 2 IC2200
  23. # C- Radio 3 FT 991
  24. # D- Diesel Heater
  25. # E- Accessories
  26. # F- Not Used (Spare)
  27. #
  28. ################################################################################################################
  29. #
  30. # Import Modules
  31. import curses
  32. from os import system, name
  33. import serial
  34. import time
  35. import sys
  36. #
  37. #Setup Serial Port
  38. serA = sys.argv[1]
  39. ser = serial.Serial(
  40.     port=('/dev/ttyUSB'+serA),
  41.     baudrate = 9600,
  42.     stopbits=1,
  43.     bytesize=8,
  44.     timeout=1
  45. )
  46. #
  47. #Start Main Code
  48. def main(win):
  49.     win.nodelay(True)
  50.     key=""
  51.     win.clear()
  52. #
  53. # Display Main Screen showing options for the contorl panel
  54.     win.addstr("\n")
  55.     win.addstr("Twistedshack DC Control\n")
  56.     win.addstr("Menu Choices\n")
  57.     win.addstr("This program sends serial commands to the radio shack control panel\n")
  58.     win.addstr("It uses Letters A to F : Uppercase will turn the Device on and lowercase will turn it off\n")
  59.     win.addstr("There is no need to press enter after a keypress it is automatic \n")
  60.     win.addstr("A- Radio 1 FT8900\n")
  61.     win.addstr("B- Radio 2 IC2200\n")
  62.     win.addstr("C- Radio 3 FT 991\n")
  63.     win.addstr("D- Diesel Heater Warning: Make Sure it has completed the shutdwdown procedure\n")
  64.     win.addstr("E- Accessories\n")
  65.     win.addstr("F- Not Used (Spare)\n")
  66.     win.addstr("\n")
  67.     win.addstr("Key Selected:")
  68. #Loop waiting for keypress and if valid sending it to the serial port
  69.     while 1:
  70.         try:
  71.            key = win.getkey()
  72.            win.clear()
  73.            win.addstr("\n")
  74.            win.addstr("Twistedshack DC Control\n")
  75.            win.addstr("Menu Choices\n")
  76.            win.addstr("This program sends serial commands to the radio shack control panel\n")
  77.            win.addstr("It uses Letters A to E : Uppercase will turn the Device on and lowercase will turn it off\n")
  78.            win.addstr("There is no need to press enter after a keypress it is automatic \n")
  79.            win.addstr("A- Radio 1 FT8900\n")
  80.            win.addstr("B- Radio 2 IC2200\n")
  81.            win.addstr("C- Radio 3 FT 991\n")
  82.            win.addstr("D- Diesel Heater Warning: Make Sure it has completed the shutdwdown procedure\n")
  83.            win.addstr("E- Accessories\n")
  84.            win.addstr("F- Not Used (Spare)\n")
  85.            win.addstr("\n")
  86.            win.addstr("Key Selected:")
  87.            win.addstr(str(key))
  88.            if key == "A":
  89.              ser.write(("A").encode('ascii'))
  90.            if key == "a":
  91.              ser.write(("a").encode('ascii'))
  92.            if key == "B":
  93.              ser.write(("B").encode('ascii'))
  94.            if key == "b":
  95.              ser.write(("b").encode('ascii'))
  96.            if key == "C":
  97.              ser.write(("C").encode('ascii'))
  98.            if key == "c":
  99.              ser.write(("c").encode('ascii'))
  100.            if key == "D":
  101.              ser.write(("D").encode('ascii'))
  102.            if key == "d":
  103.              ser.write(("d").encode('ascii'))
  104.            if key == "E":
  105.              ser.write(("E").encode('ascii'))
  106.            if key == "e":
  107.              ser.write(("e").encode('ascii'))
  108.            if key == "F":
  109.              ser.write(("F").encode('ascii'))
  110.            if key == "f":
  111.              ser.write(("f").encode('ascii'))
  112.            if key == os.linesep:
  113.               break
  114.         except Exception as e:
  115.            # No input
  116.            pass
  117. curses.wrapper(main)
  118. #EOF
  119.  
  120.