Files @ ab94f8a0a0c6
Branch filter:

Location: HydroBot/protomodule-firmware/Src/main.c - annotation

matthewreed
Read analog ph sensor
#include "stm32f0xx_hal.h"
#include "can.h"
#include "gpio.h"
#include "system.h"
#include "led.h"
#include "protocol.h"
#include "ph.h"


int main(void)
{

    HAL_Init();
    system_init();
    gpio_init();
    ph_init();

    protocol_init(PROTOMODULE);

    led_init();
    led_blink(LED_STATUS, 2000);
    led_blink_once(LED_CAN, 2000);
    led_set(LED_ERROR, 0);

    uint32_t loop_timer_1ms = 0;
    uint32_t loop_timer_10ms = 0;
    uint32_t loop_timer_200ms = 0;
    uint32_t loop_timer_1s = 0;
    uint32_t loop_timer_2s = 0;
    uint32_t loop_timer_data = 0;

    while (1)
    {
        can_receive();

        if (HAL_GetTick() - loop_timer_1ms >= 1)
        {
            can_process_receive_buffer();
            led_update_all();

            loop_timer_1ms = HAL_GetTick();
        }

        if (HAL_GetTick() - loop_timer_10ms >= 10)
        {

            loop_timer_10ms = HAL_GetTick();
        }

        if (HAL_GetTick() - loop_timer_200ms >= 200)
        {

            loop_timer_200ms = HAL_GetTick();
        }

        if (HAL_GetTick() - loop_timer_1s >= 1000)
        {
        	ph_update();

            loop_timer_1s = HAL_GetTick();
        }
        if (HAL_GetTick() - loop_timer_2s >= 2000)
        {

            loop_timer_2s = HAL_GetTick();
        }
        if (HAL_GetTick() - loop_timer_data >= (protocol_get_settings()->val.data_rate))
        {

            protocol_send_data(WATER_PH, 0, ph_get());

            loop_timer_data = HAL_GetTick();
        }
    }

}

bool protocol_set_output(protocol_message_t* message)
{
    bool result = false;

    return result;
}

bool protocol_get_data(protocol_message_t* message)
{
    bool result = false;

    return result;
}

bool protocol_config(protocol_message_t* message)
{
    bool result = false;
    protocol_data_key_t data = (protocol_data_key_t)(uint16_t)message->data.float_data;

    return result;
}

bool protocol_calibrate(protocol_message_t* message)
{
    bool result = false;

    return result;
}