180 lines
3.3 KiB
C
180 lines
3.3 KiB
C
/*
|
|
* Copyright 2017-2024 Oleg Borodin <onborodin@gmail.com>
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <avr/interrupt.h>
|
|
#include <util/delay.h>
|
|
|
|
#include <tool.h>
|
|
#include <eeprom.h>
|
|
#include <disp.h>
|
|
#include <uart.h>
|
|
#include <temp.h>
|
|
#include <relay.h>
|
|
#include <timer.h>
|
|
#include <adc.h>
|
|
#include <button.h>
|
|
|
|
#include <contr.h>
|
|
|
|
#define CONTR_BAND_OFF 0x01
|
|
#define CONTR_BAND_10M 0x02
|
|
#define CONTR_BAND_20M 0x03
|
|
#define CONTR_BAND_40M 0x04
|
|
#define CONTR_BAND_80M 0x05
|
|
|
|
typedef struct {
|
|
uint8_t band;
|
|
bool button_was_pressed;
|
|
uint16_t button_time_counter;
|
|
uint16_t button_time_untap;
|
|
uint16_t button_tap_counter;
|
|
bool button_strokes_ended;
|
|
} contr_t;
|
|
|
|
contr_t contr;
|
|
|
|
void contr_switch_band(void);
|
|
void contr_set_band(uint8_t band);
|
|
void contr_write_band(void);
|
|
void contr_read_band(void);
|
|
|
|
ISR(TIMER0_OVF_vect) {
|
|
button_handle();
|
|
uart_handle();
|
|
}
|
|
|
|
void contr_init(void) {
|
|
contr.band = CONTR_BAND_OFF;
|
|
}
|
|
void contr_setup(void) {
|
|
contr_read_band();
|
|
}
|
|
|
|
void contr_switch_band(void) {
|
|
switch (contr.band) {
|
|
case CONTR_BAND_10M:
|
|
contr_set_band(CONTR_BAND_20M);
|
|
break;
|
|
case CONTR_BAND_20M:
|
|
contr_set_band(CONTR_BAND_40M);
|
|
break;
|
|
case CONTR_BAND_40M:
|
|
contr_set_band(CONTR_BAND_80M);
|
|
break;
|
|
case CONTR_BAND_80M:
|
|
contr_set_band(CONTR_BAND_10M);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void contr_set_band(uint8_t band) {
|
|
relaytx_off();
|
|
contr.band = band;
|
|
|
|
relay80m_off();
|
|
relay40m_off();
|
|
relay20m_off();
|
|
relay10m_off();
|
|
|
|
switch (contr.band) {
|
|
case CONTR_BAND_10M:
|
|
relay10m_on();
|
|
break;
|
|
case CONTR_BAND_20M:
|
|
relay20m_on();
|
|
break;
|
|
case CONTR_BAND_40M:
|
|
relay40m_on();
|
|
break;
|
|
case CONTR_BAND_80M:
|
|
relay80m_on();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
contr_write_band();
|
|
atten_on();
|
|
}
|
|
|
|
char* contr_get_bandname() {
|
|
char* bandstr = NULL;
|
|
switch (contr.band) {
|
|
case CONTR_BAND_10M:
|
|
bandstr = "10m";
|
|
break;
|
|
case CONTR_BAND_20M:
|
|
bandstr = "20m";
|
|
break;
|
|
case CONTR_BAND_40M:
|
|
bandstr = "40m";
|
|
break;
|
|
case CONTR_BAND_80M:
|
|
bandstr = "80m";
|
|
break;
|
|
case CONTR_BAND_OFF:
|
|
bandstr = "OFF";
|
|
break;
|
|
}
|
|
return bandstr;
|
|
}
|
|
|
|
#define CONTR_KEY_SWBAND 3
|
|
#define CONTR_KEY_BUZZER 4
|
|
#define CONTR_KEY_FUN 5
|
|
|
|
void contr_button_eval(void) {
|
|
switch (button_get()) {
|
|
case CONTR_KEY_SWBAND:
|
|
contr_switch_band();
|
|
break;
|
|
case CONTR_KEY_BUZZER:
|
|
buzzer_onoff();
|
|
break;
|
|
case CONTR_KEY_FUN:
|
|
fan_onoff();
|
|
break;
|
|
}
|
|
}
|
|
|
|
void contr_show_logo(void) {
|
|
disp_clear();
|
|
char* dispstr = "Made by R2FDX";
|
|
disp_string(1, 1, dispstr);
|
|
_delay_ms(200);
|
|
disp_clear();
|
|
}
|
|
|
|
void contr_show_band(void) {
|
|
disp_string(0, 12, contr_get_bandname(contr.band));
|
|
}
|
|
|
|
void contr_main(void) {
|
|
contr_show_logo();
|
|
|
|
uint16_t counter = 0;
|
|
while (true) {
|
|
contr_button_eval();
|
|
contr_show_band();
|
|
counter++;
|
|
_delay_ms(100);
|
|
}
|
|
}
|
|
|
|
void contr_write_band(void) {
|
|
eeprom_write_bytes(0x00, &contr.band, sizeof(contr.band));
|
|
}
|
|
|
|
void contr_read_band(void) {
|
|
eeprom_read_bytes(0x00, &contr.band, sizeof(contr.band));
|
|
}
|
|
|