Merge pull request #247 from alanbjohnston/pico-pf

Pico pf
pull/248/head
alanbjohnston 3 years ago committed by GitHub
commit 93207f53a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -214,6 +214,8 @@ void start_clockgen();
bool TimerHandler1(struct repeating_timer *t); bool TimerHandler1(struct repeating_timer *t);
void load_sstv_image_1_as_cam_dot_jpg(); void load_sstv_image_1_as_cam_dot_jpg();
void load_sstv_image_2_as_cam_dot_jpg(); void load_sstv_image_2_as_cam_dot_jpg();
void get_input();
void transmit_led(bool status);
#ifndef STASSID #ifndef STASSID
#define STASSID "Pico" #define STASSID "Pico"
@ -378,6 +380,7 @@ RPI_PICO_Timer ITimer1(1);
bool timer0_on = false; bool timer0_on = false;
volatile int timer_counter; volatile int timer_counter;
bool filter_present = false; // BPF installation state for transmitter
char callsign[20]; char callsign[20];
int morse_timing = 60; // ms for a dit int morse_timing = 60; // ms for a dit

@ -98,9 +98,11 @@ void setup() {
// otherwise, run CubeSatSim Pico code // 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(); start_clockgen();
@ -164,15 +166,18 @@ void setup() {
// start_pwm(); // start_pwm();
program_radio(); program_radio();
prompt = PROMPT_HELP; // display input help menu
prompt_for_input();
/**/ /**/
Serial.println("Transmitting callsign"); // Serial.println("Transmitting callsign");
// strcpy(callsign, call); // strcpy(callsign, call);
if (mode != CW) if (mode != CW)
transmit_callsign(callsign); transmit_callsign(callsign);
// sleep(5.0); // sleep(5.0);
sleep(1.0); sleep(1.0);
/**/ /**/
config_telem(); config_telem();
// start_button_isr(); // try before start_isr // start_button_isr(); // try before start_isr
@ -187,17 +192,17 @@ void setup() {
sampleTime = (unsigned int) millis(); sampleTime = (unsigned int) millis();
ready = TRUE; // flag for core1 to start looping ready = TRUE; // flag for core1 to start looping
prompt = PROMPT_HELP; // display input help menu get_input();
prompt_for_input(); /*
Serial.print("s"); Serial.print("s");
Serial.print(" "); Serial.print(" ");
Serial.println(millis()); Serial.println(millis());
*/
} }
void loop() { void loop() {
int startSleep = millis(); int startSleep = millis();
loop_count++; loop_count++;
@ -218,7 +223,6 @@ void loop() {
if (mode == AFSK) { if (mode == AFSK) {
send_aprs_packet(); send_aprs_packet();
} else if (mode == CW) { } else if (mode == CW) {
Serial.printf("DE %s \n", callsign);
send_cw(); send_cw();
} }
} }
@ -254,12 +258,12 @@ void loop() {
// send_sstv(image_file); // send_sstv(image_file);
// LittleFS.remove("/cam.bin"); // LittleFS.remove("/cam.bin");
show_dir(); // show_dir();
char input_file[] = "/cam.jpg"; char input_file[] = "/cam.jpg";
// char output_file2[] = "/cam2.bin"; // char output_file2[] = "/cam2.bin";
char output_file[] = "/cam.bin"; char output_file[] = "/cam.bin";
// jpeg_decode(image_file, output_file, true); // debug_mode); // 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(); show_dir();
// char telem_display[] = " BATT: STATUS: TEMP: "; // char telem_display[] = " BATT: STATUS: TEMP: ";
@ -272,9 +276,7 @@ void loop() {
if (debug_mode) if (debug_mode)
Serial.println("Start transmit!!!"); Serial.println("Start transmit!!!");
digitalWrite(PTT_PIN, LOW); // start transmit digitalWrite(PTT_PIN, LOW); // start transmit
// if (!wifi) transmit_led(HIGH);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(MAIN_LED_BLUE, HIGH);
// scottie1_transmit_file(output_file, debug_mode); // scottie1_transmit_file(output_file, debug_mode);
@ -286,9 +288,7 @@ void loop() {
if (debug_mode) if (debug_mode)
Serial.println("Stop transmit!"); Serial.println("Stop transmit!");
digitalWrite(PTT_PIN, HIGH); // stop transmit digitalWrite(PTT_PIN, HIGH); // stop transmit
// if (!wifi) transmit_led(LOW);
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(MAIN_LED_BLUE, LOW);
if (debug_mode) if (debug_mode)
Serial.println("\nImage sent!"); Serial.println("\nImage sent!");
@ -296,7 +296,8 @@ void loop() {
} }
else else
Serial.println("Unknown mode!"); Serial.println("Unknown mode!");
get_input();
// while ((millis() - sampleTime) < ((unsigned int)samplePeriod)) // - 250)) // was 250 100 // while ((millis() - sampleTime) < ((unsigned int)samplePeriod)) // - 250)) // was 250 100
while ((millis() - sampleTime) < ((unsigned int)frameTime)) // - 250)) // was 250 100 while ((millis() - sampleTime) < ((unsigned int)frameTime)) // - 250)) // was 250 100
@ -307,72 +308,12 @@ void loop() {
// test_radio(); // test_radio();
if ((mode == FSK) || (mode == BPSK)) { if ((mode == FSK) || (mode == BPSK)) {
// if (!wifi) transmit_led(LOW);
digitalWrite(LED_BUILTIN, LOW); sleep(0.2);
digitalWrite(MAIN_LED_BLUE, LOW); transmit_led(HIGH);
// delay(3000);
sleep(0.2); // 2.845); // 3.0);
// if (!wifi)
digitalWrite(LED_BUILTIN, HIGH);
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 get_input();
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();
}
// Calculate loop time // Calculate loop time
if (debug_mode) { if (debug_mode) {
@ -526,18 +467,23 @@ void send_aprs_packet() {
if (debug_mode) if (debug_mode)
Serial.println("Sending APRS packet!"); Serial.println("Sending APRS packet!");
transmit_on(); transmit_on();
transmit_led(HIGH);
send_packet(_FIXPOS_STATUS, debug_mode); send_packet(_FIXPOS_STATUS, debug_mode);
transmit_led(LOW);
transmit_off(); transmit_off();
} }
void send_cw() { void send_cw() {
if (filter_present) { // only transmit CW packet if BPF filter is present
char de[] = " DE "; char de[] = " DE ";
char telem[1000]; char telem[1000];
char space[] = " "; char space[] = " ";
if (debug_mode) if (debug_mode)
Serial.println("Sending CW packet!"); Serial.println("Sending CW packet!");
Serial.printf("DE %s \n", callsign);
strcpy(telem, de); strcpy(telem, de);
strcat(telem, callsign); strcat(telem, callsign);
strcat(telem, space); strcat(telem, space);
@ -545,15 +491,15 @@ void send_cw() {
if (debug_mode) if (debug_mode)
print_string(telem); print_string(telem);
// Serial.println(strlen(telem)); // Serial.println(strlen(telem));
transmit_string(telem);
transmit_string(telem); }
} }
void transmit_on() { void transmit_on() {
if ((mode == SSTV) || (mode == AFSK)) { // this isn't quite right for APRS - should only do when sending APRS packet if ((mode == SSTV) || (mode == AFSK)) { // this isn't quite right for APRS - should only do when sending APRS packet
if (debug_mode) if (debug_mode)
Serial.println("Transmit on!"); Serial.println("Transmit on!");
digitalWrite(MAIN_LED_BLUE, HIGH); // digitalWrite(MAIN_LED_BLUE, HIGH);
digitalWrite(PTT_PIN, LOW); digitalWrite(PTT_PIN, LOW);
} }
else if ((mode == BPSK) || (mode == FSK)) { else if ((mode == BPSK) || (mode == FSK)) {
@ -593,8 +539,8 @@ void transmit_off() {
digitalWrite(PTT_PIN, HIGH); digitalWrite(PTT_PIN, HIGH);
if (debug_mode) if (debug_mode)
Serial.println("Transmit off!"); Serial.println("Transmit off!");
digitalWrite(MAIN_LED_BLUE, LOW); /// digitalWrite(MAIN_LED_BLUE, LOW);
digitalWrite(LED_BUILTIN, LOW); /// digitalWrite(LED_BUILTIN, LOW);
if ((mode == BPSK) || (mode == FSK)) { if ((mode == BPSK) || (mode == FSK)) {
digitalWrite(BPSK_CONTROL_A, LOW); digitalWrite(BPSK_CONTROL_A, LOW);
digitalWrite(BPSK_CONTROL_B, LOW); digitalWrite(BPSK_CONTROL_B, LOW);
@ -2204,6 +2150,7 @@ void write_little_endian(unsigned int word, int num_bytes, FILE *wav_file)
void config_radio() void config_radio()
{ {
if (filter_present) {
Serial.println("Configuring radio"); Serial.println("Configuring radio");
/* /*
if (!wifi) if (!wifi)
@ -2261,6 +2208,9 @@ void config_radio()
} }
transmit_on(); transmit_on();
} }
} else
Serial.println("Radio not configured since no BPF present - no transmitting after CW ID");
} }
void test_radio() void test_radio()
@ -3579,10 +3529,12 @@ void config_gpio() {
pinMode(BPF_PIN, INPUT_PULLUP); // Read LPF to see if present pinMode(BPF_PIN, INPUT_PULLUP); // Read LPF to see if present
// pinMode(SQUELCH, INPUT); // Squelch from TXC // pinMode(SQUELCH, INPUT); // Squelch from TXC
if (digitalRead(BPF_PIN) == FALSE) if (digitalRead(BPF_PIN) == FALSE) {
Serial.println("BPF present"); Serial.println("BPF present - transmit enabled");
filter_present = true;
}
else else
Serial.println("BPF not present"); Serial.println("BPF not present - no transmitting after CW ID");
if (digitalRead(TXC_PIN) == FALSE) if (digitalRead(TXC_PIN) == FALSE)
Serial.println("TXC present"); Serial.println("TXC present");
@ -3899,7 +3851,7 @@ void transmit_callsign(char *callsign) {
char id[20]; char id[20];
strcpy(id, de); strcpy(id, de);
strcat(id, callsign); strcat(id, callsign);
Serial.print("Transmitting id: "); Serial.print("Transmitting CW id: ");
print_string(id); print_string(id);
/* /*
if (reset_count == 0) { if (reset_count == 0) {
@ -4545,3 +4497,64 @@ void start_clockgen() {
clockgen.enableOutputs(false); 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();
*/
}
}
void transmit_led(bool status) {
if(filter_present) {
// if (!wifi)
digitalWrite(LED_BUILTIN, status);
digitalWrite(MAIN_LED_BLUE, status);
}
}

Loading…
Cancel
Save

Powered by TurnKey Linux.