Changeset - 8b77baddb5ab
[Not reviewed]
default
0 4 0
matthewreed - 7 years ago 2017-05-13 18:13:04

Updates to leds and protocol bug fixes
4 files changed with 13 insertions and 12 deletions:
0 comments (0 inline, 0 general)
inc/led.h
Show inline comments
 
#ifndef _LED_H_
 
#define _LED_H_
 
 
#include "stm32f0xx_hal.h"
 
#include <stdbool.h>
 
#include <string.h>
 
 
typedef enum {
 
    LED_STATUS = 0,
 
    LED_CAN,
 
    LED_ERROR,
 
} led_name_t;
 
 
void led_init(void);
 
void led_start(led_name_t led);
 
void led_start_time(led_name_t led, uint16_t time);
 
void led_update(led_name_t led);
 
void led_update_all(void);
 
void led_set(led_name_t led, bool value);
 
void led_toggle(led_name_t led);
 
 
__weak bool gpio_set_led(led_name_t led, bool value);
 
__weak bool gpio_toggle_led(led_name_t led);
 
bool gpio_set_led(led_name_t led, bool value);
 
bool gpio_toggle_led(led_name_t led);
 
 
#endif /* _LED_H_ */
inc/protocol.h
Show inline comments
 
@@ -45,30 +45,30 @@ typedef enum {
 
    DIGITAL_OUTPUT = 0x0004,
 
    FREQ_OUTPUT = 0x0005,
 
    ANALOG_OUTPUT = 0x0006,
 
    AIR_TEMP = 0x0007,
 
    AIR_HUMIDITY = 0x0008,
 
    AIR_PRESSURE = 0x0009,
 
    AMBIENT_LIGHT = 0x000A,
 
    WATER_TEMP = 0x000B,
 
    WATER_LEVEL = 0x000C,
 
    WATER_CONDUCTIVITY = 0x000D,
 
    WATER_PH = 0x000E,
 
    CAN_ID = 0x0100,
 
    DATA_RATE = 0x0101,
 
    GPIO = 0x0102,
 
    LED_BRIGHTNESS = 0x0103,
 
} protocol_data_key_t;
 
 
void protocol_init(protocol_device_t device);
 
bool protocol_receive_message(CanRxMsgTypeDef* can_message);
 
bool protocol_send_message(protocol_message_t* message);
 
bool protocol_process_message(protocol_message_t* message);
 
bool protocol_send_data(protocol_data_key_t key, uint8_t sensor, float data);
 
bool protocol_send_test();
 
 
__weak bool protocol_estop(bool value);
 
__weak bool protocol_set_output(protocol_message_t* message);
 
__weak bool protocol_get_data(protocol_message_t* message);
 
__weak bool protocol_config(protocol_message_t* message);
 
bool protocol_estop(bool value);
 
bool protocol_set_output(protocol_message_t* message);
 
bool protocol_get_data(protocol_message_t* message);
 
bool protocol_config(protocol_message_t* message);
 
 
#endif //_PROTOCOL_H_
src/led.c
Show inline comments
 
@@ -25,49 +25,50 @@ void led_start(led_name_t led)
 
    led_thresholds[led] = led_cycles[led]/2;
 
}
 
 
void led_start_time(led_name_t led, uint16_t time)
 
{
 
    if (led_timers[led] == 0)
 
    {
 
        led_timers[led] = time;
 
        led_thresholds[led] = time/2;
 
    }
 
}
 
 
void led_update(led_name_t led)
 
{
 
    if (led_timers[led] > led_thresholds[led])
 
    {
 
        led_set(led, 1);
 
        led_timers[led]--;
 
    }
 
    else if (led_timers[led] > 0)
 
    {
 
        led_set(led, 0);
 
        led_timers[led]--;
 
    }
 
    else {
 
    else if (led_cycles[led] > 0)
 
    {
 
        led_set(led, 0);
 
        led_timers[led] = led_cycles[led];
 
    }
 
}
 
 
void led_update_all(void)
 
{
 
    led_update(LED_STATUS);
 
    led_update(LED_CAN);
 
    led_update(LED_ERROR);
 
}
 
 
void led_set(led_name_t led, bool value)
 
{
 
    gpio_set_led(led, value);
 
}
 
 
void led_toggle(led_name_t led)
 
{
 
    gpio_toggle_led(led);
 
}
 
 
__weak bool gpio_set_led(led_name_t led, bool value)
 
{
src/protocol.c
Show inline comments
 
@@ -21,56 +21,56 @@ bool protocol_send_test()
 
bool protocol_receive_message(CanRxMsgTypeDef* can_message)
 
{
 
    bool result = true;
 
    
 
    protocol_message_t message;
 
    message.command = can_message->Data[0] & 0x80;
 
    message.id = can_message->Data[0] & 0x7F;
 
    message.key = (can_message->Data[1] << 8) & can_message->Data[2];
 
    message.sensor = can_message->Data[3];
 
    message.data.byte_data[0] = can_message->Data[4];
 
    message.data.byte_data[1] = can_message->Data[5];
 
    message.data.byte_data[2] = can_message->Data[6];
 
    message.data.byte_data[3] = can_message->Data[7];
 
    
 
    protocol_process_message(&message);
 
    
 
    return result;
 
}
 
 
bool protocol_send_message(protocol_message_t* message)
 
{
 
    bool result = true;
 
    uint8_t data[8];
 
    
 
    data[0] = (message->command & 0x80) & (message->id & 0x7F);
 
    data[0] = (message->command & 0x80) | (message->id & 0x7F);
 
    data[1] = (message->key >> 8) & 0xFF;
 
    data[2] = (message->key >> 0) & 0xFF;
 
    data[3] = message->sensor;
 
    data[4] = (message->data.byte_data[0] >> 24) & 0xFF;
 
    data[5] = (message->data.byte_data[1] >> 16) & 0xFF;
 
    data[6] = (message->data.byte_data[2] >> 8) & 0xFF;
 
    data[7] = (message->data.byte_data[3] >> 0) & 0xFF;
 
    data[4] = message->data.byte_data[0];
 
    data[5] = message->data.byte_data[1];
 
    data[6] = message->data.byte_data[2];
 
    data[7] = message->data.byte_data[3];
 
    
 
    can_send(protocol_settings.val.can_id | 0x00000001, CAN_ID_STD, 8, data);
 
    
 
    return result;
 
}
 
 
bool protocol_process_message(protocol_message_t* message)
 
{
 
    bool result = true;
 
    
 
    if (message->command)
 
    {
 
        switch(message->id)
 
        {
 
            case ESTOP:
 
                {
 
                    //call estop weak function
 
                    result = protocol_estop(message->data.float_data!=0.0f);
 
                }
 
                break;
 
            case SILENCE_BUS:
 
                {
 
                    //silence can bus
 
                    result = can_silence_bus(message->data.float_data!=0.0f);
0 comments (0 inline, 0 general)