Files @ 702f27a0e203
Branch filter:

Location: FeatherHAB/wsprhab/src/main.c - annotation

Ethan Zonca
Add missing system file
//
// WSPRHAB: Minimal high-altitude balloon tracker with WSPR telemetry
//

#include "stm32f0xx_hal.h"
#include "adc.h"
#include "system.h"
#include "i2c.h"
#include "uart.h"
#include "gpio.h"
#include "gps.h"


int main(void)
{
    HAL_Init();

    sysclk_init();
    gpio_init();
    adc_init();
    i2c_init();
    gps_init();

    //jtencode_init();

    HAL_Delay(300);

    //gps_poweroff();

    // Disable ICs
    HAL_GPIO_WritePin(OSC_NOTEN, 1);
    HAL_GPIO_WritePin(TCXO_EN, 0);

    HAL_GPIO_TogglePin(LED_BLUE);

    uint32_t led_timer = HAL_GetTick();
    uint32_t last_gps  = HAL_GetTick();
    uint32_t last_wspr  = HAL_GetTick(); //0xfffff; // start immediately.

    HAL_GPIO_TogglePin(LED_BLUE);
    HAL_Delay(100);
    HAL_GPIO_TogglePin(LED_BLUE);
    HAL_Delay(100);
    HAL_GPIO_TogglePin(LED_BLUE);
    HAL_Delay(100);
    HAL_GPIO_TogglePin(LED_BLUE);
    HAL_Delay(100);

    uint8_t lastMinute = 0;
    uint16_t blink_rate = 250;

    gps_update_position();

    while (1)
    {
        // TODO: Trigger this when RTC thinks its time to go
        if(HAL_GetTick() - last_wspr > 500)
        {
            switch(gps_getstate())
            {
                case GPS_STATE_ACQUIRING:
                    blink_rate = 250;
                    break;
                case GPS_STATE_FRESHFIX:
                    blink_rate = 50;
                    break;
                case GPS_STATE_STALEFIX:
                case GPS_STATE_NOFIX:
                    gps_acquirefix();
                    blink_rate = 500;
                    break;
            }

            // EMZ TODO: this needs to trigger off of RTC minute, not GPS minute
//            volatile uint8_t minute = get_timestamp()[3] - 0x30;
//
//            // If last minute was odd and this minute is even (transition)
//            if(lastMinute%2 == 1 && minute%2 == 0)
//            {
//                // Wait until the first second of the minute
//                HAL_Delay(1000);
//                wspr_transmit();
//            }

//            lastMinute = minute;
            last_wspr = HAL_GetTick();
        }

        if(HAL_GetTick() - led_timer > blink_rate)
        {
            HAL_GPIO_TogglePin(LED_BLUE);
            led_timer = HAL_GetTick();
        }
        if(HAL_GetTick() - last_gps > 10)
        {
            //gps_process();
            last_gps = HAL_GetTick();
        }

        //enter_sleep();
    }
}