update
This commit is contained in:
36
button.c
36
button.c
@@ -10,14 +10,6 @@
|
|||||||
#include <button.h>
|
#include <button.h>
|
||||||
#include <tool.h>
|
#include <tool.h>
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool was_pressed;
|
|
||||||
bool strokes_ended;
|
|
||||||
uint16_t time_counter;
|
|
||||||
uint16_t released_time;
|
|
||||||
uint16_t push_counter;
|
|
||||||
} button_t;
|
|
||||||
|
|
||||||
button_t button;
|
button_t button;
|
||||||
|
|
||||||
void button_init(void) {
|
void button_init(void) {
|
||||||
@@ -27,7 +19,7 @@ void button_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool button_is_pressed(void) {
|
bool button_is_pressed(void) {
|
||||||
if (REG_BIT_VALUE(PIND, PD3)) {
|
if (!REG_BIT_VALUE(PIND, PD3)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -36,8 +28,6 @@ bool button_is_pressed(void) {
|
|||||||
uint8_t button_get(void) {
|
uint8_t button_get(void) {
|
||||||
if (button.strokes_ended) {
|
if (button.strokes_ended) {
|
||||||
uint8_t counter = button.push_counter;
|
uint8_t counter = button.push_counter;
|
||||||
button.was_pressed = false;
|
|
||||||
button.time_counter = 0;
|
|
||||||
button.push_counter = 0;
|
button.push_counter = 0;
|
||||||
button.strokes_ended = false;
|
button.strokes_ended = false;
|
||||||
return counter;
|
return counter;
|
||||||
@@ -49,42 +39,44 @@ void button_reset(void) {
|
|||||||
button.was_pressed = false;
|
button.was_pressed = false;
|
||||||
button.time_counter = 0;
|
button.time_counter = 0;
|
||||||
button.push_counter = 0;
|
button.push_counter = 0;
|
||||||
|
button.released_time = 0;
|
||||||
button.strokes_ended = false;
|
button.strokes_ended = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BUTTON_TIME_PRESSED 50
|
#define BUTTON_TIME_PRESSED 20
|
||||||
#define BUTTON_TIME_RELEASED 50
|
#define BUTTON_TIME_RELEASED 20
|
||||||
#define BUTTON_RELEASED_TIME 500
|
#define BUTTON_RELEASED_TIME 300
|
||||||
|
|
||||||
void button_handle(void) {
|
void button_handle(void) {
|
||||||
if (!button.strokes_ended) {
|
if (!button.strokes_ended) {
|
||||||
if (!button.was_pressed) {
|
if (!button.was_pressed) {
|
||||||
if (button_is_pressed()) {
|
if (button_is_pressed()) {
|
||||||
button.time_counter++;
|
button.time_counter++;
|
||||||
button.released_time++;
|
|
||||||
}
|
}
|
||||||
if (button.time_counter > BUTTON_TIME_PRESSED) {
|
if (button.time_counter > BUTTON_TIME_PRESSED) {
|
||||||
button.time_counter = 0;
|
button.time_counter = 0;
|
||||||
button.was_pressed = true;
|
button.was_pressed = true;
|
||||||
|
button.released_time = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!button_is_pressed()) {
|
if (!button_is_pressed()) {
|
||||||
button.time_counter++;
|
button.time_counter++;
|
||||||
}
|
}
|
||||||
if (button.time_counter > BUTTON_TIME_RELEASED) {
|
if (button.time_counter > BUTTON_TIME_RELEASED) {
|
||||||
|
button.push_counter++;
|
||||||
button.time_counter = 0;
|
button.time_counter = 0;
|
||||||
button.was_pressed = false;
|
button.was_pressed = false;
|
||||||
button.push_counter++;
|
|
||||||
button.released_time = 0;
|
button.released_time = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (button.released_time++ > BUTTON_RELEASED_TIME) {
|
||||||
if (button.push_counter > 0) {
|
|
||||||
button.released_time++;
|
|
||||||
if (button.released_time > BUTTON_RELEASED_TIME) {
|
|
||||||
button.strokes_ended = true;
|
button.strokes_ended = true;
|
||||||
}
|
button.was_pressed = false;
|
||||||
} else {
|
button.time_counter = 0;
|
||||||
button.released_time = 0;
|
button.released_time = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
11
button.h
11
button.h
@@ -5,6 +5,17 @@
|
|||||||
#ifndef BUTTON_H_QWERTY
|
#ifndef BUTTON_H_QWERTY
|
||||||
#define BUTTON_H_QWERTY
|
#define BUTTON_H_QWERTY
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool was_pressed;
|
||||||
|
bool strokes_ended;
|
||||||
|
uint16_t time_counter;
|
||||||
|
uint16_t released_time;
|
||||||
|
uint8_t push_counter;
|
||||||
|
} button_t;
|
||||||
|
|
||||||
|
extern button_t button;
|
||||||
|
|
||||||
void button_init(void);
|
void button_init(void);
|
||||||
void button_reset(void);
|
void button_reset(void);
|
||||||
bool button_is_pressed(void);
|
bool button_is_pressed(void);
|
||||||
|
|||||||
40
contr.c
40
contr.c
@@ -211,18 +211,19 @@ void contr_tx_handle(void) {
|
|||||||
void contr_switch_delay(void) {
|
void contr_switch_delay(void) {
|
||||||
switch (contr.tx_delay) {
|
switch (contr.tx_delay) {
|
||||||
case CONTR_DELAY_100MS:
|
case CONTR_DELAY_100MS:
|
||||||
contr_set_band(CONTR_DELAY_200MS);
|
contr.tx_delay = CONTR_DELAY_200MS;
|
||||||
break;
|
break;
|
||||||
case CONTR_DELAY_200MS:
|
case CONTR_DELAY_200MS:
|
||||||
contr_set_band(CONTR_DELAY_300MS);
|
contr.tx_delay = CONTR_DELAY_300MS;
|
||||||
break;
|
break;
|
||||||
case CONTR_DELAY_300MS:
|
case CONTR_DELAY_300MS:
|
||||||
contr_set_band(CONTR_DELAY_500MS);
|
contr.tx_delay = CONTR_DELAY_500MS;
|
||||||
break;
|
break;
|
||||||
case CONTR_DELAY_500MS:
|
case CONTR_DELAY_500MS:
|
||||||
contr_set_band(CONTR_DELAY_100MS);
|
contr.tx_delay = CONTR_DELAY_100MS;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
contr.tx_delay = CONTR_DELAY_200MS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,7 +280,11 @@ void contr_switch_band(void) {
|
|||||||
case CONTR_BAND_80M:
|
case CONTR_BAND_80M:
|
||||||
contr_set_band(CONTR_BAND_10M);
|
contr_set_band(CONTR_BAND_10M);
|
||||||
break;
|
break;
|
||||||
|
case CONTR_BAND_OFF:
|
||||||
|
contr_set_band(CONTR_BAND_10M);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
contr_set_band(CONTR_BAND_OFF);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -327,7 +332,8 @@ void contr_set_band(uint8_t band) {
|
|||||||
#define CONTR_KEY_FUN 5
|
#define CONTR_KEY_FUN 5
|
||||||
|
|
||||||
void contr_button_eval(void) {
|
void contr_button_eval(void) {
|
||||||
switch (button_get()) {
|
uint8_t push_count = button_get();
|
||||||
|
switch (push_count) {
|
||||||
case CONTR_KEY_SWDELAY:
|
case CONTR_KEY_SWDELAY:
|
||||||
contr_switch_delay();
|
contr_switch_delay();
|
||||||
break;
|
break;
|
||||||
@@ -368,6 +374,19 @@ void contr_show_ptt(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void contr_show_button(void) {
|
||||||
|
if (button_is_pressed()) {
|
||||||
|
disp_string(3, 3, "BT");
|
||||||
|
} else {
|
||||||
|
disp_string(3, 3, " ");
|
||||||
|
}
|
||||||
|
//if (button.strokes_ended) {
|
||||||
|
sprintf(contr.disp_str, "%1u", button.push_counter);
|
||||||
|
disp_string(3, 5, contr.disp_str);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void contr_show_freq(void) {
|
void contr_show_freq(void) {
|
||||||
uint16_t freq = contr_get_freq();
|
uint16_t freq = contr_get_freq();
|
||||||
sprintf(contr.disp_str, "%2uM", freq);
|
sprintf(contr.disp_str, "%2uM", freq);
|
||||||
@@ -378,7 +397,6 @@ void contr_show_delay(void) {
|
|||||||
disp_string(0, 0, contr_get_delayname());
|
disp_string(0, 0, contr_get_delayname());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void contr_show_fwd(void) {
|
void contr_show_fwd(void) {
|
||||||
sprintf(contr.disp_str, "F=%4.1f", (float)contr_get_fwd() / 100.0F);
|
sprintf(contr.disp_str, "F=%4.1f", (float)contr_get_fwd() / 100.0F);
|
||||||
disp_string(1, 0, contr.disp_str);
|
disp_string(1, 0, contr.disp_str);
|
||||||
@@ -398,16 +416,17 @@ void contr_main(void) {
|
|||||||
contr_show_logo();
|
contr_show_logo();
|
||||||
uint16_t counter = 0;
|
uint16_t counter = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
contr_show_button();
|
||||||
contr_show_ptt();
|
contr_show_ptt();
|
||||||
contr_show_delay();
|
contr_show_delay();
|
||||||
contr_button_eval();
|
contr_button_eval();
|
||||||
contr_show_vcc();
|
contr_show_vcc();
|
||||||
contr_show_fwd();
|
//contr_show_fwd();
|
||||||
contr_show_rev();
|
//contr_show_rev();
|
||||||
contr_show_swr();
|
//contr_show_swr();
|
||||||
contr_show_band();
|
contr_show_band();
|
||||||
counter++;
|
counter++;
|
||||||
_delay_ms(50);
|
_delay_ms(150);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,7 +461,6 @@ char* contr_get_bandname() {
|
|||||||
default:
|
default:
|
||||||
bandstr = "UNK";
|
bandstr = "UNK";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
return bandstr;
|
return bandstr;
|
||||||
}
|
}
|
||||||
|
|||||||
2
timer.h
2
timer.h
@@ -1,7 +1,7 @@
|
|||||||
#ifndef CONTR_INIT_H_QWERTY
|
#ifndef CONTR_INIT_H_QWERTY
|
||||||
#define CONTR_INIT_H_QWERTY
|
#define CONTR_INIT_H_QWERTY
|
||||||
|
|
||||||
#define TIMER1_PRESIZE 65528 //65532 // 65536
|
#define TIMER1_PRESIZE 65528 // 65536
|
||||||
|
|
||||||
void timer0_init(void);
|
void timer0_init(void);
|
||||||
void timer1_init(void);
|
void timer1_init(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user