Skip to content

Commit

Permalink
power controller implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoantoniocardoso committed Dec 15, 2019
1 parent f6dc98e commit f736b2a
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 20 deletions.
1 change: 1 addition & 0 deletions firmware/src/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
//#define ADC_ON
#define MACHINE_ON
#define CHRONOMETER_ON
#define CONTROLLER_ON
//#define LED_ON
#define WATCHDOG_ON
//#define SLEEP_ON
Expand Down
66 changes: 66 additions & 0 deletions firmware/src/controller.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "controller.h"

static controller_power_channels_t controller_power_channels;
static uint8_t * active_power_channel;

void controller_init(void)
{
controller_power_channels.normal = 0;
controller_power_channels.turbo = INITIAL_TURBO_VALUE;
active_power_channel = &(controller_power_channels.normal);
}

void controller_power_channel_change(controller_power_channel_t *channel)
{
if(channel == NULL){
if(active_power_channel == &(controller_power_channels.normal)){
active_power_channel = &(controller_power_channels.turbo);
}else{
active_power_channel = &(controller_power_channels.normal);
}
}else{
active_power_channel = channel;
}
}

void controller_power_channel_increase(controller_power_channel_t *channel)
{
if(channel == NULL){
if((*active_power_channel) != 100) (*active_power_channel)++;
}else{
if((*channel) != 100) (*channel)++;
}
}

void controller_power_channel_decrease(controller_power_channel_t *channel)
{
if(channel == NULL){
if((*active_power_channel) != 0) (*active_power_channel)--;
}else{
if((*channel) != 0) (*channel)--;
}
}

uint8_t controller_power_channel_active_value(void)
{
return (*active_power_channel);
}

uint8_t controller_power_channel_normal_value(void)
{
return controller_power_channels.normal;
}

uint8_t controller_power_channel_turbo_value(void)
{
return controller_power_channels.turbo;
}

controller_power_channel_name_t controller_power_channel_active_channel_name(void)
{
if(active_power_channel == &(controller_power_channels.normal)){
return controller_power_channel_normal_name;
}else{
return controller_power_channel_turbo_name;
}
}
37 changes: 37 additions & 0 deletions firmware/src/controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file controller.h
*
* @brief The boat controller module
*
*/

#ifndef CONTROLLER_H
#define CONTROLLER_H

#include <stddef.h>
#include <inttypes.h>

#define INITIAL_TURBO_VALUE 100
typedef uint8_t controller_power_channel_t;

typedef struct{
controller_power_channel_t normal;
controller_power_channel_t turbo;
} controller_power_channels_t;

typedef enum{
controller_power_channel_normal_name,
controller_power_channel_turbo_name,
} controller_power_channel_name_t;

void controller_init(void);
void controller_power_channel_change(controller_power_channel_t *channel);
void controller_power_channel_increase(controller_power_channel_t *channel);
void controller_power_channel_decrease(controller_power_channel_t *channel);

uint8_t controller_power_channel_active_value(void);
uint8_t controller_power_channel_normal_value(void);
uint8_t controller_power_channel_turbo_value(void);
controller_power_channel_name_t controller_power_channel_active_channel_name(void);

#endif /* ifndef CONTROLLER_H */
4 changes: 2 additions & 2 deletions firmware/src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
static void (*callback_functions[10])(void *);
static void (*callback_arguments[10]);
static void callback_caller(input_names_t input);
static const uint8_t input_cooldown_time = 25;
static const uint8_t input_cooldown_time_first = 50;
static const uint8_t input_cooldown_time = 2;
static const uint8_t input_cooldown_time_first = 12;
static inline void input_update_sw0(void);
static inline void input_update_sw1(void);
static inline void input_update_sw2(void);
Expand Down
7 changes: 4 additions & 3 deletions firmware/src/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,15 @@ inline void task_initializing(void)
set_state_idle();

// CONFIGURE BUTTONS
chronometer_callback_test(chronometers.uptime);
input_assign_callback(sw1, chronometer_callback_test, chronometers.uptime);

input_assign_callback(sw5, chronometer_start, chronometers.uptime);
//input_assign_callback(sw0, chronometer_reset_delta, chronometers.uptime);

input_assign_callback(sw9, ui_screen_change, NULL);

input_assign_callback(sw1, controller_power_channel_increase, NULL);
input_assign_callback(sw8, controller_power_channel_decrease, NULL);
input_assign_callback(sw4, controller_power_channel_change, NULL);

}

//#define CHRONOMETER_DEBUG
Expand Down
3 changes: 3 additions & 0 deletions firmware/src/machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ extern const uint8_t can_filter[];
#ifdef INPUT_ON
#include "input.h"
#endif
#ifdef CONTROLLER_ON
#include "controller.h"
#endif

typedef enum state_machine{
STATE_INITIALIZING,
Expand Down
4 changes: 4 additions & 0 deletions firmware/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ void init(void)
chronometer_init();
#endif

#ifdef CONTROLLER_ON
controller_init();
#endif

#ifdef MACHINE_ON
VERBOSE_MSG_INIT(usart_send_string("MACHINE..."));
machine_init();
Expand Down
7 changes: 7 additions & 0 deletions firmware/src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@
#pragma message "CHRONOMETER: OFF!"
#endif /*ifdef CHRONOMETER_ON*/

#ifdef CONTROLLER_ON
#include "controller.h"
#pragma message "CONTROLLER: ON!"
#else
#pragma message "CONTROLLER: OFF!"
#endif /*ifdef CONTROLLER_ON*/

#ifdef LED_ON
#pragma message "LED: ON!"
#else
Expand Down
32 changes: 17 additions & 15 deletions firmware/src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,27 @@ void ui_screen_change(screen_t * screen)
void ui_screen_main(void)
{
char time_str[TIME_STRING_LEN];
static uint8_t a = 0;
if(a++ == 101) a = 0;

// LAP
display_send_string("LAP)", 2, 0, font_small);
display_send_uint8(2, 7, 0, font_small);

// total
display_send_string("TOTAL)", 0, 1, font_small);
// total time
chronometer_millis_to_time_string(chronometers.uptime->delta, time_str);
display_send_string(time_str, 7, 1, font_small);
display_send_string(time_str, 0, 0, font_big);

// max velocity setting
display_send_string(" MAX :", 0, 3, font_big);
display_send_uint8(a, 12, 3, font_big);
// power settings
controller_power_channel_t active_power_channel = controller_power_channel_active_channel_name();
if(active_power_channel == controller_power_channel_normal_name){
display_send_string("NORMAL:", 0, 3, font_big);
display_send_uint8(controller_power_channel_normal_value(), 13, 3, font_big);

display_send_string("TURBO: ", 0, 5, font_small);
display_send_uint8(controller_power_channel_turbo_value(), 13, 5, font_small);
}else{
display_send_string("TURBO: ", 0, 3, font_big);
display_send_uint8(controller_power_channel_turbo_value(), 13, 3, font_big);

display_send_string("NORMAL:", 0, 5, font_small);
display_send_uint8(controller_power_channel_normal_value(), 13, 5, font_small);
}

// current velocity setting
display_send_string(" VEL :", 0, 5, font_big);
display_send_uint8(a, 12, 5, font_big);
}

void ui_screen_laps(void)
Expand Down
2 changes: 2 additions & 0 deletions firmware/src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#define _UI_H_

#include <util/delay.h>
#include <stddef.h>
#include "conf.h"
#include "dbg_vrb.h"
#include "usart.h"
#include "display.h"
#include "chronometer.h"
#include "controller.h"

// NORMALSIZE -> 21x8
// DOUBLESIZE -> 10x4
Expand Down

0 comments on commit f736b2a

Please sign in to comment.