Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pico pf #247

Merged
merged 15 commits into from
Dec 4, 2022
Merged
3 changes: 3 additions & 0 deletions cubesatsim/cubesatsim.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ 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();
void transmit_led(bool status);

#ifndef STASSID
#define STASSID "Pico"
Expand Down Expand Up @@ -378,6 +380,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
Expand Down
201 changes: 107 additions & 94 deletions cubesatsim/cubesatsim.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -164,15 +166,18 @@ void setup() {
// start_pwm();
program_radio();

prompt = PROMPT_HELP; // display input help menu
prompt_for_input();

/**/
Serial.println("Transmitting callsign");
// Serial.println("Transmitting callsign");
// strcpy(callsign, call);
if (mode != CW)
transmit_callsign(callsign);
// sleep(5.0);
sleep(1.0);
/**/

config_telem();

// start_button_isr(); // try before start_isr
Expand All @@ -187,17 +192,17 @@ void setup() {
sampleTime = (unsigned int) millis();

ready = TRUE; // flag for core1 to start looping

prompt = PROMPT_HELP; // display input help menu
prompt_for_input();


get_input();
/*
Serial.print("s");
Serial.print(" ");
Serial.println(millis());
Serial.println(millis());
*/
}

void loop() {

int startSleep = millis();
loop_count++;

Expand All @@ -218,7 +223,6 @@ void loop() {
if (mode == AFSK) {
send_aprs_packet();
} else if (mode == CW) {
Serial.printf("DE %s \n", callsign);
send_cw();
}
}
Expand Down Expand Up @@ -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: ";

Expand All @@ -272,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);

Expand All @@ -286,17 +288,16 @@ 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!");

}
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
Expand All @@ -307,72 +308,12 @@ 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);
}


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;
transmit_led(LOW);
sleep(0.2);
transmit_led(HIGH);
}

// 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) {
Expand Down Expand Up @@ -526,34 +467,39 @@ 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();
}

void send_cw() {
if (filter_present) { // only transmit CW packet if BPF filter is present

char de[] = " DE ";
char telem[1000];
char space[] = " ";

if (debug_mode)
Serial.println("Sending CW packet!");


Serial.printf("DE %s \n", callsign);
strcpy(telem, de);
strcat(telem, callsign);
strcat(telem, space);
strcat(telem, tlm_str); // don't send payload since it isn't encoded and has "."
if (debug_mode)
print_string(telem);
// Serial.println(strlen(telem));

transmit_string(telem);
transmit_string(telem);
}
}

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)) {
Expand Down Expand Up @@ -593,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);
Expand Down Expand Up @@ -2204,6 +2150,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)
Expand Down Expand Up @@ -2261,6 +2208,9 @@ void config_radio()
}
transmit_on();
}

} else
Serial.println("Radio not configured since no BPF present - no transmitting after CW ID");
}

void test_radio()
Expand Down Expand Up @@ -3579,10 +3529,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");
Expand Down Expand Up @@ -3899,7 +3851,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) {
Expand Down Expand Up @@ -4545,3 +4497,64 @@ 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();
*/
}

}

void transmit_led(bool status) {
if(filter_present) {
// if (!wifi)
digitalWrite(LED_BUILTIN, status);
digitalWrite(MAIN_LED_BLUE, status);
}
}