import subprocess import string import R64.GPIO as GPIO # NOTE: the R64GPIO package doesn't support "add_event_detect", so we can't use callbacks # Initialize GPIO.cleanup() GPIO.setmode(GPIO.BOARD) PCB = 10 RESET = 3 POWER = 5 LED = 7 FAN = 8 # Tell the script if this is running on a ROCK64 or ROCKPRO64 GPIO.setrock("ROCK64") # Setup GPIO.setup(PCB, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(RESET, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(POWER, GPIO.IN) GPIO.setup(LED, GPIO.OUT) GPIO.setup(FAN, GPIO.OUT) IGNORE_PWR_OFF = False if(GPIO.input(POWER) == "0"): # System was started with power switch off IGNORE_PWR_OFF = True # Turn on LED AND FAN GPIO.output(LED, GPIO.HIGH) GPIO.output(FAN, GPIO.HIGH)
MQTT_ON = "ON" MQTT_OFF = "OFF" MQTT_TOGGLE = "TOGGLE" # The RockPro version of the library seems to return strings not ints - is this # intended behavior? HIGH = "1" LOW = "0" #LED_PIN = 27 #BUTTON_PIN = 4 LED_PIN = 16 BUTTON_PIN = 13 GPIO.setmode(GPIO.BOARD) GPIO.setrock('ROCKPRO64') GPIO.setwarnings(False); GPIO.setup(LED_PIN, GPIO.OUT) GPIO.output(LED_PIN, GPIO.LOW) led_state = False time.sleep(1) GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) class MyHandlerForHTTP(BaseHTTPRequestHandler): """ Handler for HTTP messages """ def do_GET(self):
# Initialize GPIO.setwarnings(False) GPIO.cleanup() GPIO.setmode(GPIO.BOARD) PCB = 10 RESET = 3 POWER = 5 LED = 7 FAN = 8 arch = subprocess.check_output(["batocera-es-swissknife", "--arch"]).strip().upper() # Tell the script if this is running on a ROCK64 or ROCKPRO64 GPIO.setrock(arch) # Setup GPIO.setup(PCB, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(RESET, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(POWER, GPIO.IN) GPIO.setup(LED, GPIO.OUT) GPIO.setup(FAN, GPIO.OUT) IGNORE_PWR_OFF = False if (GPIO.input(POWER) == "0"): # System was started with power switch off IGNORE_PWR_OFF = True # Turn on LED AND FAN GPIO.output(LED, GPIO.HIGH) GPIO.output(FAN, GPIO.HIGH)