Init
This commit is contained in:
85
contr.c
Normal file
85
contr.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2017-2024 Oleg Borodin <onborodin@gmail.com>
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#include <tool.h>
|
||||
#include <eeprom.h>
|
||||
#include <disp.h>
|
||||
#include <timer.h>
|
||||
#include <adc.h>
|
||||
#include <button.h>
|
||||
|
||||
#include <contr.h>
|
||||
|
||||
button_t volume_button;
|
||||
|
||||
typedef struct {
|
||||
uint8_t volume;
|
||||
bool volume_updated;
|
||||
} contr_t;
|
||||
|
||||
contr_t contr;
|
||||
|
||||
void contr_init(void) {
|
||||
contr.volume = 0;
|
||||
contr.volume_updated = false;
|
||||
}
|
||||
|
||||
void contr_setup(void) {
|
||||
}
|
||||
|
||||
ISR(TIMER0_OVF_vect) {
|
||||
button_handle(&volume_button);
|
||||
}
|
||||
|
||||
|
||||
void contr_show_logo(void) {
|
||||
disp_clear();
|
||||
char* dispstr = "Made by R2FDX";
|
||||
disp_string(1, 1, dispstr);
|
||||
_delay_ms(100);
|
||||
disp_clear();
|
||||
}
|
||||
|
||||
#define CONTR_DISPSTR_SIZE 16
|
||||
|
||||
void contr_show_volume(void) {
|
||||
char dispstr[CONTR_DISPSTR_SIZE];
|
||||
sprintf(dispstr, "%4d", contr.volume);
|
||||
disp_string(1, 1, dispstr);
|
||||
}
|
||||
|
||||
#define MAX_VOLUME 64
|
||||
|
||||
void contr_calc_volume(void) {
|
||||
if (button_was_pressed(&volume_button) == true) {
|
||||
contr.volume++;
|
||||
contr.volume_updated = true;
|
||||
}
|
||||
if (contr.volume > MAX_VOLUME) {
|
||||
contr.volume = 0;
|
||||
contr.volume_updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
void contr_main(void) {
|
||||
contr_show_logo();
|
||||
uint16_t counter = 0;
|
||||
while (true) {
|
||||
counter++;
|
||||
_delay_ms(10);
|
||||
contr_calc_volume();
|
||||
contr_show_volume();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user