From 472cab8f5a9ab4fdd333d3b8ba13d7baeccc0f35 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 7 Jul 2022 11:04:14 -0400 Subject: [PATCH] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 152 ++++++++++++++++++++++++++++++++++---- 1 file changed, 137 insertions(+), 15 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 886f9676..920725b4 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2290,21 +2290,9 @@ void loop1() { // check pushbutton int pb_value; pb_value = digitalRead(MAIN_PB_PIN); - if (pb_value == PRESSED) { - if (pb_state == RELEASED) { - pb_press_start = millis(); - } else { // still held - if ((millis() - pb_press_start) > 1000) { - blink(150); - } - - } else if (pb_state == HELD) { - // pushbutton is released - Serial.print("New mode is: "); - Serial.println(mode_count); - pb_state = RELEASED; - } -} + if (pb_value == PRESSED) + process_pushbutton(); +} void sleep(float time) { @@ -2317,3 +2305,137 @@ void sleep(float time) { } } +void process_pushbutton() { + + int release = FALSE; + + sleep(1.0); + pb_value = digitalRead(MAIN_PB_PIN); + if (pb_value == RELEASED) { + Serial.println("PB: Reboot!"); + release = TRUE; + sleep(10.0); + } + digitalWrite(MAIN_PB_PIN, LOW); + sleep(0.1); + digitalWrite(MAIN_PB_PIN, HIGH); +/* + GPIO.output(powerPin, 0); # blink once + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(1.5) + if (GPIO.input(26) and (release == False)): + print("switch to AFSK") + f = open("/home/pi/CubeSatSim/.mode", "w") + f.write("a") + f.close() + os.system("sudo systemctl restart cubesatsim") + release = True; + if (release == False): + GPIO.output(powerPin, 0); # blink twice + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(0.1); + GPIO.output(powerPin, 0); + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(1.5) + if (GPIO.input(26) and (release == False)): + print("switch to FSK") + f = open("/home/pi/CubeSatSim/.mode", "w") + f.write("f") + f.close() + os.system("sudo systemctl restart cubesatsim") + release = True; + if (release == False): + GPIO.output(powerPin, 0); # blink three times + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(0.1); + GPIO.output(powerPin, 0); + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(0.1) + GPIO.output(powerPin, 0); + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(1.5) + if (GPIO.input(26) and (release == False)): + print("switch to BPSK") + f = open("/home/pi/CubeSatSim/.mode", "w") + f.write("b") + f.close() + os.system("sudo systemctl restart cubesatsim") + release = True; + if (release == False): + GPIO.output(powerPin, 0); # blink four times + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(0.1); + GPIO.output(powerPin, 0); + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(0.1) + GPIO.output(powerPin, 0); + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(0.1) + GPIO.output(powerPin, 0); + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(1.5) + if (GPIO.input(26) and (release == False)): + print("switch to SSTV") + f = open("/home/pi/CubeSatSim/.mode", "w") + f.write("s") + f.close() + os.system("sudo systemctl restart cubesatsim") + release = True; + if (release == False): + GPIO.output(powerPin, 0); # blink five times + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(0.1); + GPIO.output(powerPin, 0); + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(0.1) + GPIO.output(powerPin, 0); + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(0.1) + GPIO.output(powerPin, 0); + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(0.1) + GPIO.output(powerPin, 0); + time.sleep(0.1); + GPIO.output(powerPin, 1); + time.sleep(1.5) + if (GPIO.input(26) and (release == False)): + print("switch to CW") + f = open("/home/pi/CubeSatSim/.mode", "w") + f.write("m") + f.close() + os.system("sudo systemctl restart cubesatsim") + release = True; + if (release == False): + print("sudo shutdown -h now") + GPIO.setwarnings(False) + GPIO.setup(powerPin, GPIO.OUT) + GPIO.output(powerPin, 0); # blink slowly to indicate shutdown + time.sleep(0.5); + GPIO.output(powerPin, 1); + time.sleep(0.5); + GPIO.output(powerPin, 0); + time.sleep(0.5); + GPIO.output(powerPin, 1); + time.sleep(0.5); + GPIO.output(powerPin, 0); + subprocess.call(['shutdown', '-h', 'now'], shell=False) + if (txPin != 0): + GPIO.setwarnings(False) + GPIO.output(txPin, 0) + +*/ +}