From edb6abd17985328fd1827c4ec4827fe41f52ba6b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 3 Dec 2022 22:18:41 -0500 Subject: [PATCH 01/14] added get_input 2x in setup and loop and v0.34 --- cubesatsim/cubesatsim.ino | 125 ++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 60 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index b00019eaa..1071b0262 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -98,9 +98,11 @@ void setup() { // otherwise, run CubeSatSim Pico code - Serial.println("CubeSatSim Pico v0.33 starting...\n"); + Serial.println("CubeSatSim Pico v0.34 starting...\n"); - config_gpio(); + config_gpio(); + + get_input(); start_clockgen(); @@ -187,6 +189,8 @@ void setup() { sampleTime = (unsigned int) millis(); ready = TRUE; // flag for core1 to start looping + + get_input(); prompt = PROMPT_HELP; // display input help menu prompt_for_input(); @@ -197,7 +201,7 @@ void setup() { } void loop() { - + int startSleep = millis(); loop_count++; @@ -254,12 +258,12 @@ void loop() { // send_sstv(image_file); // LittleFS.remove("/cam.bin"); - show_dir(); +// show_dir(); char input_file[] = "/cam.jpg"; // char output_file2[] = "/cam2.bin"; char output_file[] = "/cam.bin"; // jpeg_decode(image_file, output_file, true); // debug_mode); - jpeg_decode(input_file, output_file, true); // debug_mode); + jpeg_decode(input_file, output_file, false); // debug_mode); show_dir(); // char telem_display[] = " BATT: STATUS: TEMP: "; @@ -296,7 +300,8 @@ void loop() { } else Serial.println("Unknown mode!"); - + + get_input(); // while ((millis() - sampleTime) < ((unsigned int)samplePeriod)) // - 250)) // was 250 100 while ((millis() - sampleTime) < ((unsigned int)frameTime)) // - 250)) // was 250 100 @@ -319,60 +324,7 @@ void loop() { digitalWrite(MAIN_LED_BLUE, HIGH); } - - serial_input(); - -// check for button press - if (digitalRead(MAIN_PB_PIN) == PRESSED) // pushbutton is pressed - process_pushbutton(); - if (BOOTSEL) // boot selector button is pressed on Pico - process_bootsel(); - - if (prompt) { -// Serial.println("Need to prompt for input!"); - prompt_for_input(); - prompt = false; - } - - // check to see if the mode has changed - if (mode != new_mode) { - Serial.println("Changing mode"); - cw_stop = false; // enable CW or won't hear CW ID -/// if (mode == SSTV) { -/// ITimer1.detachInterrupt(); -/// start_button_isr(); // restart button isr -/// } - int old_mode = mode; - bool config_done = false; - mode = new_mode; // change modes if button pressed - write_mode(); -/* -// if ((mode == BPSK) || ((new_mode == FSK) && (old_mode == CW))) { - if (mode == BPSK) { - config_telem(); // run this before cw only for BPSK mode - config_done = true; - } -*/ - Serial.println("Rebooting..."); - watchdog_reboot (0, SRAM_END, 10); // restart Pico - - sleep(20.0); - - if (new_mode != CW) - transmit_callsign(callsign); - sleep(0.5); - - if (!config_done) - config_telem(); // run this here for all other modes - - config_radio(); - if ((mode == FSK) || (mode == BPSK)) { - digitalWrite(LED_BUILTIN, HIGH); - digitalWrite(MAIN_LED_BLUE, HIGH); - } - - sampleTime = (unsigned int) millis(); - } + get_input(); // Calculate loop time if (debug_mode) { @@ -4545,3 +4497,56 @@ void start_clockgen() { clockgen.enableOutputs(false); } + +void get_input() { + + serial_input(); + +// check for button press + if (digitalRead(MAIN_PB_PIN) == PRESSED) // pushbutton is pressed + process_pushbutton(); + if (BOOTSEL) // boot selector button is pressed on Pico + process_bootsel(); + + if (prompt) { +// Serial.println("Need to prompt for input!"); + prompt_for_input(); + prompt = false; + } + + // check to see if the mode has changed + if (mode != new_mode) { + Serial.println("Changing mode"); + cw_stop = false; // enable CW or won't hear CW ID +/// if (mode == SSTV) { +/// ITimer1.detachInterrupt(); +/// start_button_isr(); // restart button isr +/// } + int old_mode = mode; + bool config_done = false; + mode = new_mode; // change modes if button pressed + write_mode(); + + Serial.println("Rebooting..."); + watchdog_reboot (0, SRAM_END, 10); // restart Pico + + sleep(20.0); +/* + if (new_mode != CW) + transmit_callsign(callsign); + sleep(0.5); + + if (!config_done) + config_telem(); // run this here for all other modes + + config_radio(); + if ((mode == FSK) || (mode == BPSK)) { + digitalWrite(LED_BUILTIN, HIGH); + digitalWrite(MAIN_LED_BLUE, HIGH); + } + + sampleTime = (unsigned int) millis(); +*/ + } + +} From 65833579529b85fbda818c53420dc2e8945c2e42 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 3 Dec 2022 22:18:51 -0500 Subject: [PATCH 02/14] added get_input() --- cubesatsim/cubesatsim.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index f3b69de1f..87acffdd0 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -214,6 +214,7 @@ void start_clockgen(); bool TimerHandler1(struct repeating_timer *t); void load_sstv_image_1_as_cam_dot_jpg(); void load_sstv_image_2_as_cam_dot_jpg(); +void get_input(); #ifndef STASSID #define STASSID "Pico" From 91c5bff0459d2b8180602da933d8c04a07b51f9b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Dec 2022 09:07:30 -0500 Subject: [PATCH 03/14] added filter_present --- cubesatsim/cubesatsim.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 87acffdd0..0fed2585e 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -379,6 +379,7 @@ RPI_PICO_Timer ITimer1(1); bool timer0_on = false; volatile int timer_counter; +bool filter_present = false; // BPF installation state for transmitter char callsign[20]; int morse_timing = 60; // ms for a dit From 11b42461476ef15b490d047d9bb52347b78a16ab Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Dec 2022 09:09:20 -0500 Subject: [PATCH 04/14] added filter_present to not configure radio if no BPF present --- cubesatsim/cubesatsim.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 1071b0262..e2824f04a 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2156,6 +2156,7 @@ void write_little_endian(unsigned int word, int num_bytes, FILE *wav_file) void config_radio() { + if (filter_present) { Serial.println("Configuring radio"); /* if (!wifi) @@ -2213,6 +2214,8 @@ void config_radio() } transmit_on(); } + else + Serial.println("Radio not configured since no BPF present - no transmitting after CW ID"); } void test_radio() From 48163c1d048fa5fda7c6730c6b951a3128e45b6d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Dec 2022 09:12:15 -0500 Subject: [PATCH 05/14] missing } --- cubesatsim/cubesatsim.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index e2824f04a..13e20a66a 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -2214,7 +2214,8 @@ void config_radio() } transmit_on(); } - else + + } else Serial.println("Radio not configured since no BPF present - no transmitting after CW ID"); } From 347d592ee9c2d8b230fd51cdda985d4344d18314 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Dec 2022 09:25:54 -0500 Subject: [PATCH 06/14] added filter_present for CW mode --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 13e20a66a..a681ba077 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -497,8 +497,8 @@ void send_cw() { if (debug_mode) print_string(telem); // Serial.println(strlen(telem)); - - transmit_string(telem); + if (filter_present) // only transmit CW packet if BPF filter is present + transmit_string(telem); } void transmit_on() { From 9c7598c48d18eb799492adce0ef74227924946cf Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Dec 2022 09:29:02 -0500 Subject: [PATCH 07/14] don't print DE when not transmitting --- cubesatsim/cubesatsim.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index a681ba077..1acbe3d95 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -483,6 +483,8 @@ void send_aprs_packet() { } void send_cw() { + if (filter_present) { // only transmit CW packet if BPF filter is present + char de[] = " DE "; char telem[1000]; char space[] = " "; @@ -497,8 +499,8 @@ void send_cw() { if (debug_mode) print_string(telem); // Serial.println(strlen(telem)); - if (filter_present) // only transmit CW packet if BPF filter is present transmit_string(telem); + } } void transmit_on() { From 33bf38c54e132bff4bfe47c0a9a57d82d740e777 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Dec 2022 09:40:20 -0500 Subject: [PATCH 08/14] don't print DE CALLSIGN if no BPF --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 1acbe3d95..29fd26f6e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -222,7 +222,6 @@ void loop() { if (mode == AFSK) { send_aprs_packet(); } else if (mode == CW) { - Serial.printf("DE %s \n", callsign); send_cw(); } } @@ -491,7 +490,8 @@ void send_cw() { if (debug_mode) Serial.println("Sending CW packet!"); - + + Serial.printf("DE %s \n", callsign); strcpy(telem, de); strcat(telem, callsign); strcat(telem, space); From df17d50808c211ee797c1393e98ef7a4d205ecb4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Dec 2022 09:43:04 -0500 Subject: [PATCH 09/14] move print input options --- cubesatsim/cubesatsim.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 29fd26f6e..48367f832 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -166,6 +166,9 @@ void setup() { // start_pwm(); program_radio(); + prompt = PROMPT_HELP; // display input help menu + prompt_for_input(); + /**/ Serial.println("Transmitting callsign"); // strcpy(callsign, call); @@ -174,7 +177,7 @@ void setup() { // sleep(5.0); sleep(1.0); /**/ - + config_telem(); // start_button_isr(); // try before start_isr @@ -192,9 +195,6 @@ void setup() { get_input(); - prompt = PROMPT_HELP; // display input help menu - prompt_for_input(); - Serial.print("s"); Serial.print(" "); Serial.println(millis()); From 6c7bca14c71d27147306920bbde0389a6956d929 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Dec 2022 09:48:14 -0500 Subject: [PATCH 10/14] added pin test for filter_present --- cubesatsim/cubesatsim.ino | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 48367f832..924c13d5a 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -170,7 +170,7 @@ void setup() { prompt_for_input(); /**/ - Serial.println("Transmitting callsign"); +// Serial.println("Transmitting callsign"); // strcpy(callsign, call); if (mode != CW) transmit_callsign(callsign); @@ -194,10 +194,11 @@ void setup() { ready = TRUE; // flag for core1 to start looping get_input(); - +/* Serial.print("s"); Serial.print(" "); - Serial.println(millis()); + Serial.println(millis()); +*/ } void loop() { @@ -3537,10 +3538,12 @@ void config_gpio() { pinMode(BPF_PIN, INPUT_PULLUP); // Read LPF to see if present // pinMode(SQUELCH, INPUT); // Squelch from TXC - if (digitalRead(BPF_PIN) == FALSE) - Serial.println("BPF present"); + if (digitalRead(BPF_PIN) == FALSE) { + Serial.println("BPF present - transmit enabled"); + filter_present = true; + } else - Serial.println("BPF not present"); + Serial.println("BPF not present - no transmitting after CW ID"); if (digitalRead(TXC_PIN) == FALSE) Serial.println("TXC present"); @@ -3857,7 +3860,7 @@ void transmit_callsign(char *callsign) { char id[20]; strcpy(id, de); strcat(id, callsign); - Serial.print("Transmitting id: "); + Serial.print("Transmitting CW id: "); print_string(id); /* if (reset_count == 0) { From 971da1501899015e3fdb0671a3edbb1e8950c2dc Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Dec 2022 10:01:18 -0500 Subject: [PATCH 11/14] added transmit_led --- cubesatsim/cubesatsim.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cubesatsim/cubesatsim.h b/cubesatsim/cubesatsim.h index 0fed2585e..47c27f9a6 100644 --- a/cubesatsim/cubesatsim.h +++ b/cubesatsim/cubesatsim.h @@ -215,6 +215,7 @@ bool TimerHandler1(struct repeating_timer *t); void load_sstv_image_1_as_cam_dot_jpg(); void load_sstv_image_2_as_cam_dot_jpg(); void get_input(); +void transmit_led(bool status); #ifndef STASSID #define STASSID "Pico" From 67c6ea6d35172aae0405c5b08f53a93a1a5518db Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Dec 2022 10:01:22 -0500 Subject: [PATCH 12/14] added transmit_led function --- cubesatsim/cubesatsim.ino | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 924c13d5a..3d228ffc3 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -312,16 +312,9 @@ void loop() { // test_radio(); if ((mode == FSK) || (mode == BPSK)) { -// if (!wifi) - digitalWrite(LED_BUILTIN, LOW); - digitalWrite(MAIN_LED_BLUE, LOW); - - // delay(3000); - sleep(0.2); // 2.845); // 3.0); - -// if (!wifi) - digitalWrite(LED_BUILTIN, HIGH); - digitalWrite(MAIN_LED_BLUE, HIGH); + transmit_led(LOW); + sleep(0.2); + transmit_led(HIGH); } get_input(); @@ -4559,3 +4552,11 @@ void get_input() { } } + +void transmit_led(bool status) { + if(filter_present) { +// if (!wifi) + digitalWrite(LED_BUILTIN, status); + digitalWrite(MAIN_LED_BLUE, status); + } +} From a9b1dd47092150628f7abbc6415a50648fea833b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Dec 2022 10:08:09 -0500 Subject: [PATCH 13/14] added transmit_led to AFSK and SSTV --- cubesatsim/cubesatsim.ino | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 3d228ffc3..39739163f 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -276,9 +276,7 @@ void loop() { if (debug_mode) Serial.println("Start transmit!!!"); digitalWrite(PTT_PIN, LOW); // start transmit -// if (!wifi) - digitalWrite(LED_BUILTIN, HIGH); - digitalWrite(MAIN_LED_BLUE, HIGH); + transmit_led(HIGH); // scottie1_transmit_file(output_file, debug_mode); @@ -290,9 +288,7 @@ void loop() { if (debug_mode) Serial.println("Stop transmit!"); digitalWrite(PTT_PIN, HIGH); // stop transmit -// if (!wifi) - digitalWrite(LED_BUILTIN, LOW); - digitalWrite(MAIN_LED_BLUE, LOW); + transmit_led(LOW); if (debug_mode) Serial.println("\nImage sent!"); @@ -471,7 +467,9 @@ void send_aprs_packet() { if (debug_mode) Serial.println("Sending APRS packet!"); transmit_on(); + transmit_led(HIGH); send_packet(_FIXPOS_STATUS, debug_mode); + transmit_led(LOW); transmit_off(); } @@ -501,7 +499,7 @@ void transmit_on() { if ((mode == SSTV) || (mode == AFSK)) { // this isn't quite right for APRS - should only do when sending APRS packet if (debug_mode) Serial.println("Transmit on!"); - digitalWrite(MAIN_LED_BLUE, HIGH); +// digitalWrite(MAIN_LED_BLUE, HIGH); digitalWrite(PTT_PIN, LOW); } else if ((mode == BPSK) || (mode == FSK)) { From 5e7a66d51b3f0e0c045f4add5efb309487da71d5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 4 Dec 2022 10:35:28 -0500 Subject: [PATCH 14/14] Update cubesatsim.ino --- cubesatsim/cubesatsim.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index 39739163f..f4f3d584f 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -539,8 +539,8 @@ void transmit_off() { digitalWrite(PTT_PIN, HIGH); if (debug_mode) Serial.println("Transmit off!"); - digitalWrite(MAIN_LED_BLUE, LOW); - digitalWrite(LED_BUILTIN, LOW); +/// digitalWrite(MAIN_LED_BLUE, LOW); +/// digitalWrite(LED_BUILTIN, LOW); if ((mode == BPSK) || (mode == FSK)) { digitalWrite(BPSK_CONTROL_A, LOW); digitalWrite(BPSK_CONTROL_B, LOW);