Got th UI to work as intended

* fixed global variable not being initialized
* fixed fan control formulas
* inverted encoder counting
+ added 3D support for adapter
This commit is contained in:
Steins7 2020-02-21 17:50:45 +01:00
parent c7af2f2b59
commit 9ee81f0024
7 changed files with 91 additions and 63 deletions

View File

@ -1,37 +1,41 @@
$fn = 100;
// element dimensions
w = 59;
d = 28;
w = 60;
d = 30;
h = 4;
// aditionnal parameters
e = 3;
e = 5;
// internal values
we = w + e;
de = d + e;
translate([0,0,e/2]);
cube([w,d,e/2], true);
cube([we,de,e/3], true);
module tab() {
translate([-e/4,0,(e/2+h)/2]) {
translate([-e/4,0,(e/3+h)/2]) {
cube([e/2,2*e,h], true);
translate([-1.75*e,-e,h/2])
rotate([0,-90,-90])
linear_extrude(height = 2*e)
polygon([[0,e],[e/4,e],[0,2*e],[e/2,2*e]],
polygon([[0,1.2*e],[e/4,1.2*e],[0,2*e],[e/2,2*e]],
[[0,1,3,2]]);
}
}
translate([w/2,-0.35*d,0])
translate([we/2,-de/2+e,0])
tab();
translate([-w/2,0,0])
translate([-we/2,0,0])
rotate([0,0,180])
tab();
translate([8,d/2,0])
translate([8,de/2,0])
rotate([0,0,90])
tab();
translate([0,-d/2,0])
translate([0,-de/2,0])
rotate([0,0,-90])
tab();

Binary file not shown.

View File

@ -300,9 +300,9 @@ int timer_enc_init(TIM_TypeDef* tmr) {
tmr->CCMR1 |= 0x9;
tmr->CCMR1 |= 0x9 << 8;
// enable input channels
tmr->CCER |= 0x1;
tmr->CCER |= 0x1 << 4;
// enable input channels and invert them //TODO add an otpion for that
tmr->CCER |= 0x3;
tmr->CCER |= 0x3 << 4;
tmr->CR1 |= 0x1; //enable timer

View File

@ -32,7 +32,7 @@ uint8_t channels[3][2] = {
vars_t vars = {
{},
2,
5,
2,
{},
1,
@ -42,7 +42,7 @@ vars_t vars = {
//------------------------------------------------------------------------------
/* Timer IRQ */
static void timeout_cb(void) {
//io_write(GPIOC, val, PIN_13);
io_write(GPIOC, val, PIN_13);
val = !val;
// set temp read flag
@ -64,16 +64,22 @@ int16_t read_temp(uint8_t id) {
/* main function */
int main(void) {
//initialize variables
val = 0; //debug led
read_flag = 0;
sensor_id = 0;
// configure clocks (necessary before using timers)
rcc_config_clock(CLOCK_CONFIG_PERFORMANCE, &sysclks);
// configure GPIO for LED
if(io_configure(GPIOC, PIN_13, IO_MODE_OUTPUT | IO_OUT_PUSH_PULL, 0))
return -1;
io_write(GPIOC, 1, PIN_13);
// configure GPIO for relay
if(io_configure(GPIOB, PIN_12, IO_MODE_OUTPUT | IO_OUT_PUSH_PULL, 0))
return -1;
io_write(GPIOC, 1, PIN_13);
io_write(GPIOB, 1, PIN_12);
// configure GPIOS for temperature sensors
@ -98,14 +104,16 @@ int main(void) {
// main loop
while(1){
// process sensor values
if(read_flag) {
// clear flag
read_flag = 0;
// shift filter queue
int32_t sum = 0;
for(int i=0; i<(FILTER_LENGTH-1); ++i) {
for(int i=0; i<(FILTER_LENGTH-2); i++) {
temp_filter[sensor_id][i] = temp_filter[sensor_id][i+1];
sum += temp_filter[sensor_id][i];
}
@ -129,12 +137,10 @@ int main(void) {
vars.start_treshold) {
vars.fan = 1;
io_set(GPIOB, PIN_12);
io_clear(GPIOC, PIN_13);
} else if((vars.temps[T_EXT] - vars.temps[vars.silo]) >=
} else if((vars.temps[vars.silo] - vars.temps[T_EXT]) <=
vars.stop_treshold) {
vars.fan = 0;
io_clear(GPIOB, PIN_12);
io_set(GPIOC, PIN_13);
}
}

View File

@ -14,18 +14,24 @@ static const char* ui_default[] = {
"SILO: Te: ""\xDF""C",
"1: ""\xDF""C 2: ""\xDF""C"
};
static const char* ui_menu[] = {
" 1-Retour",
" 2-Silo:",
" 3-Start:",
" 4-Stop:",
" 5-Calibrer Te",
" 6-Calibrer T1",
" 7-Calibrer T2",
" 8-Test ventil",
// " 5-Calibrer Te",
// " 6-Calibrer T1",
// " 7-Calibrer T2",
// " 8-Test ventil",
" 1-Retour"
};
static const char* ui_interact[] = {
" lue: ""\xDF""C",
" reelle: ""\xDF""C"
};
//------------------------------------------------------------------------------
/* internal functions */
void show_bg(const char** bg) {
@ -36,6 +42,42 @@ void show_bg(const char** bg) {
lcd_print(bg[1]);
}
void update_entry(uint8_t prev_entry, uint8_t value) {
// get vlaue in str form
char str[8]; //too long to be sure
num2str(str, value, 10);
// print value in the correct position
if(sel == prev_entry) lcd_set_cursor(14, 1);
else lcd_set_cursor(14, 0);
lcd_print(str);
}
void change_value(uint8_t entry, uint8_t* entry_val, int max) {
int local_val = *entry_val;
lcd_set_cursor(14,0);
while(!button_update) {
local_val = ((enc->CNT/2)%max) + 1;
char str[8];
num2str(str, local_val, 10);
lcd_print(str);
lcd_set_cursor(14,0);
timer_wait_ms(TIM1, 200, 0);
}
*entry_val = local_val;
}
void interact(uint8_t entry, uint8_t* entry_val) {
while(!button_update) {
lcd_set_cursor(10,0);
lcd_print(" ");
lcd_set_cursor(10,0);
lcd_set_cursor(10,0);
lcd_print(" ");
}
}
//------------------------------------------------------------------------------
/* timeout timer cb */
static void ui_sleep(void) {
@ -44,7 +86,7 @@ static void ui_sleep(void) {
/* encoder button gpio cb */
static void ui_button_cb(void) {
for(int i=0; i<10000; ++i); //avoid double trigger
for(int i=0; i<1000000; ++i); //avoid double trigger
timer_start(tim);
button_update = 1;
}
@ -81,34 +123,6 @@ int ui_init(TIM_TypeDef* encoder, TIM_TypeDef* timeout, vars_t* vars_p) {
return 0;
}
void ui_update_entry(uint8_t prev_entry, uint8_t value) {
// get vlaue in str form
char str[8]; //too long to be sure
num2str(str, value, 10);
// print value in the correct position
if(sel == prev_entry) lcd_set_cursor(14, 1);
else lcd_set_cursor(14, 0);
lcd_print(str);
}
void ui_change_value(uint8_t entry, uint8_t* entry_val, int max) {
int local_val = *entry_val;
lcd_set_cursor(14,0);
while(!button_update) {
local_val = ((enc->CNT/2)%max) + 1;
char str[8];
num2str(str, local_val, 10);
lcd_print(str);
lcd_set_cursor(14,0);
timer_wait_ms(TIM1, 200, 0);
}
*entry_val = local_val;
}
void ui_update(void) {
// manage button press
if(button_update) {
@ -141,6 +155,10 @@ void ui_update(void) {
}
// otherwise interact with option
if(sel == UI_CAL_T_EXT || sel == UI_CAL_T1
|| sel == UI_CAL_T2) {
show_bg(ui_interact);
}
lcd_send_cmd(LCD_DISP_CTRL | LCD_CTRL_DISP_ON |
LCD_CTRL_CUR_ON | LCD_CTRL_BLINK_OFF);
timer_start(enc);
@ -192,15 +210,15 @@ void ui_update(void) {
// show silo value if needed
if(sel == UI_RETURN || sel == UI_SILO) {
ui_update_entry(UI_RETURN, vars->silo);
update_entry(UI_RETURN, vars->silo);
}
// show start value if needed
if(sel == UI_SILO || sel == UI_START) {
ui_update_entry(UI_SILO, vars->start_treshold);
update_entry(UI_SILO, vars->start_treshold);
}
// show start value if needed
if(sel == UI_START || sel == UI_STOP) {
ui_update_entry(UI_START, vars->stop_treshold);
update_entry(UI_START, vars->stop_treshold);
}
}
break;
@ -208,16 +226,14 @@ void ui_update(void) {
case UI_INTERACT:
switch(sel) {
case UI_SILO:
ui_change_value(UI_SILO, &vars->silo, 2);
change_value(UI_SILO, &vars->silo, 2);
break;
case UI_START:
ui_change_value(UI_START, &vars->start_treshold, 9);
change_value(UI_START, &vars->start_treshold, 9);
break;
case UI_STOP:
ui_change_value(UI_STOP, &vars->stop_treshold, 9);
change_value(UI_STOP, &vars->stop_treshold, 9);
break;
}
//---------------------
case UI_DEFAULT:

View File

@ -53,7 +53,7 @@ enum ui_menu {
UI_TEST = 7
};
#define MENU_LENGHT 7
#define MENU_LENGHT 3
//------------------------------------------------------------------------------
/** ui_init

View File

@ -6,5 +6,7 @@
uint32_t num2str(char *s, int number, uint8_t base);
//void print_num(int number,
#endif