diff --git a/button.c b/button.c index fcda5c6..836b282 100644 --- a/button.c +++ b/button.c @@ -10,14 +10,6 @@ #include #include -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; void button_init(void) { @@ -27,7 +19,7 @@ void button_init(void) { } bool button_is_pressed(void) { - if (REG_BIT_VALUE(PIND, PD3)) { + if (!REG_BIT_VALUE(PIND, PD3)) { return true; } return false; @@ -36,8 +28,6 @@ bool button_is_pressed(void) { uint8_t button_get(void) { if (button.strokes_ended) { uint8_t counter = button.push_counter; - button.was_pressed = false; - button.time_counter = 0; button.push_counter = 0; button.strokes_ended = false; return counter; @@ -49,42 +39,44 @@ void button_reset(void) { button.was_pressed = false; button.time_counter = 0; button.push_counter = 0; + button.released_time = 0; button.strokes_ended = false; } -#define BUTTON_TIME_PRESSED 50 -#define BUTTON_TIME_RELEASED 50 -#define BUTTON_RELEASED_TIME 500 +#define BUTTON_TIME_PRESSED 20 +#define BUTTON_TIME_RELEASED 20 +#define BUTTON_RELEASED_TIME 300 void button_handle(void) { if (!button.strokes_ended) { if (!button.was_pressed) { if (button_is_pressed()) { button.time_counter++; - button.released_time++; } if (button.time_counter > BUTTON_TIME_PRESSED) { button.time_counter = 0; button.was_pressed = true; + button.released_time = 0; } } else { if (!button_is_pressed()) { button.time_counter++; } if (button.time_counter > BUTTON_TIME_RELEASED) { + button.push_counter++; button.time_counter = 0; button.was_pressed = false; - button.push_counter++; button.released_time = 0; } } - } - if (button.push_counter > 0) { - button.released_time++; - if (button.released_time > BUTTON_RELEASED_TIME) { - button.strokes_ended = true; - } - } else { + if (button.released_time++ > BUTTON_RELEASED_TIME) { + button.strokes_ended = true; + button.was_pressed = false; + button.time_counter = 0; button.released_time = 0; } + + + } } + diff --git a/button.h b/button.h index f3d2404..40f97f9 100644 --- a/button.h +++ b/button.h @@ -5,6 +5,17 @@ #ifndef 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_reset(void); bool button_is_pressed(void); diff --git a/contr.c b/contr.c index a576b88..737864d 100644 --- a/contr.c +++ b/contr.c @@ -211,18 +211,19 @@ void contr_tx_handle(void) { void contr_switch_delay(void) { switch (contr.tx_delay) { case CONTR_DELAY_100MS: - contr_set_band(CONTR_DELAY_200MS); + contr.tx_delay = CONTR_DELAY_200MS; break; case CONTR_DELAY_200MS: - contr_set_band(CONTR_DELAY_300MS); + contr.tx_delay = CONTR_DELAY_300MS; break; case CONTR_DELAY_300MS: - contr_set_band(CONTR_DELAY_500MS); + contr.tx_delay = CONTR_DELAY_500MS; break; case CONTR_DELAY_500MS: - contr_set_band(CONTR_DELAY_100MS); + contr.tx_delay = CONTR_DELAY_100MS; break; default: + contr.tx_delay = CONTR_DELAY_200MS; break; } } @@ -279,7 +280,11 @@ void contr_switch_band(void) { case CONTR_BAND_80M: contr_set_band(CONTR_BAND_10M); break; + case CONTR_BAND_OFF: + contr_set_band(CONTR_BAND_10M); + break; default: + contr_set_band(CONTR_BAND_OFF); break; } } @@ -327,7 +332,8 @@ void contr_set_band(uint8_t band) { #define CONTR_KEY_FUN 5 void contr_button_eval(void) { - switch (button_get()) { + uint8_t push_count = button_get(); + switch (push_count) { case CONTR_KEY_SWDELAY: contr_switch_delay(); 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) { uint16_t freq = contr_get_freq(); sprintf(contr.disp_str, "%2uM", freq); @@ -378,7 +397,6 @@ void contr_show_delay(void) { disp_string(0, 0, contr_get_delayname()); } - void contr_show_fwd(void) { sprintf(contr.disp_str, "F=%4.1f", (float)contr_get_fwd() / 100.0F); disp_string(1, 0, contr.disp_str); @@ -398,16 +416,17 @@ void contr_main(void) { contr_show_logo(); uint16_t counter = 0; while (true) { + contr_show_button(); contr_show_ptt(); contr_show_delay(); contr_button_eval(); contr_show_vcc(); - contr_show_fwd(); - contr_show_rev(); - contr_show_swr(); + //contr_show_fwd(); + //contr_show_rev(); + //contr_show_swr(); contr_show_band(); counter++; - _delay_ms(50); + _delay_ms(150); } } @@ -442,7 +461,6 @@ char* contr_get_bandname() { default: bandstr = "UNK"; break; - } return bandstr; } diff --git a/timer.h b/timer.h index 2c8ca4e..2d59457 100644 --- a/timer.h +++ b/timer.h @@ -1,7 +1,7 @@ #ifndef 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 timer1_init(void);