removed uneeded lines

This commit is contained in:
Jake Goodwin 2025-02-12 11:09:55 -08:00
parent ce3e50a3cb
commit 079305033a
1 changed files with 201 additions and 237 deletions

View File

@ -7,11 +7,10 @@
#endif
#include "main.h"
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <util/delay.h>
// #############################
// Globals
// #############################
@ -32,13 +31,6 @@ volatile uint16_t tick_count;
// Prototypes
// #############################
void led_blink(void);
uint16_t readADC(void);
void motorCoast(void);
void motorMove(int direction);
uint8_t readButton(void);
static void InitBtn(btn_state *b, uint8_t input_pin, uint8_t output_pin);
static void ToggleOutput(btn_state *b);
@ -48,21 +40,16 @@ static void CheckButtonLongpress(btn_state *b);
static void UpdateButtonInput(btn_state *b);
static void UpdateButtonOutput(btn_state *b);
// #############################
// MAIN
// #############################
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
InitProg();
uint16_t fader_pos = ReadADC() >> 2; // Scale 10-bit ADC to 8-bit (0-255)
while(1)
{
while (1) {
fader_pos = ReadADC() >> 2;
/*
@ -71,7 +58,6 @@ int main(int argc, char **argv)
*/
}
/*
while(1) {
uint16_t fader_pos = readADC() >> 2; // Scale 10-bit ADC to 8-bit (0-255)
@ -98,14 +84,11 @@ int main(int argc, char **argv)
return 0;
}
// #############################
// FUNCTIONS
// #############################
void InitProg(void)
{
void InitProg(void) {
/*Set the debounced state to all high*/
debounced_state = 0xFF;
@ -115,14 +98,14 @@ void InitProg(void)
_delay_ms(5);
/*check if the eeprom has info. */
while(! eeprom_is_ready()) {} //Blocks until eeprom is ready.
while (!eeprom_is_ready()) {
} // Blocks until eeprom is ready.
// Checks against a bit pattern we defined to represent the start of data.
if (eeprom_read_byte((uint8_t *)ROM_SP_ADR) == START_PATTERN) {
// Reads the two bytes representing the two states.
btn1.is_active = eeprom_read_byte((uint8_t *)ROM_SS1_ADR);
}
else {
} else {
// otherwise we write the init values for the start pattern and states.
eeprom_write_byte((uint8_t *)ROM_SP_ADR, START_PATTERN);
eeprom_write_byte((uint8_t *)ROM_SS1_ADR, 0x0);
@ -133,7 +116,6 @@ void InitProg(void)
InitTimer0();
}
uint16_t ReadADC(void);
{
// Initialize ADC
@ -141,23 +123,21 @@ uint16_t ReadADC(void);
ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS0); // Enable ADC, prescaler 8
ADCSRA |= (1 << ADSC); // Start conversion
while (ADCSRA & (1 << ADSC)); // Wait for conversion to finish
while (ADCSRA & (1 << ADSC))
; // Wait for conversion to finish
return ADC;
}
/*
* ############################
* Motor methods
* ############################
*/
void MotorCoast(void)
{
void MotorCoast(void) {
PORTB &= ~((1 << PWM_PIN1) | (1 << PWM_PIN2)); // Disable motor drive
}
/*
* ############################
* BUTTON methods
@ -165,8 +145,7 @@ void MotorCoast(void)
*/
/*This is kinda like our button constructor*/
static void InitBtn(btn_state *b, uint8_t input_pin, uint8_t output_pin)
{
static void InitBtn(btn_state *b, uint8_t input_pin, uint8_t output_pin) {
b->is_long_pressed = 0;
b->is_pressed = 0;
b->is_bypassed = 0;
@ -184,41 +163,35 @@ static void InitBtn(btn_state *b, uint8_t input_pin, uint8_t output_pin)
}
/*This is the fancy function to toggle output pins*/
static void ToggleOutput(btn_state *b)
{
static void ToggleOutput(btn_state *b) {
if (!b->is_bypassed) {
b->is_bypassed = 1;
PORTB |= (1 << b->output_pin);
}
else{
} else {
b->is_bypassed = 0;
PORTB &= ~(1 << b->output_pin);
}
}
static void ClearButtonTimer(btn_state *b)
{
static void ClearButtonTimer(btn_state *b) {
b->timer_enabled = 0;
b->is_long_pressed = 0;
b->pressed_ticks = 0;
}
static void StartButtonTimer(btn_state *b)
{
static void StartButtonTimer(btn_state *b) {
ClearButtonTimer(b);
b->timer_enabled = 1;
}
static void CheckButtonLongpress(btn_state *b)
{
static void CheckButtonLongpress(btn_state *b) {
if (b->pressed_ticks >= LONG_PRESS_TICKS) {
b->is_long_pressed = 1;
b->timer_enabled = 0;
}
}
static void UpdateButtonInput(btn_state *b)
{
static void UpdateButtonInput(btn_state *b) {
/*Check from the global debounced port input*/
/*check for pin HIGH*/
@ -231,8 +204,7 @@ static void UpdateButtonInput(btn_state *b)
}
}
static void UpdateButtonOutput(btn_state *b)
{
static void UpdateButtonOutput(btn_state *b) {
/*If the button is actually pressed.*/
if (b->is_pressed) {
@ -266,7 +238,6 @@ static void UpdateButtonOutput(btn_state *b)
}
}
/*
* ############################
* DEBOUNCING CODE
@ -279,8 +250,7 @@ static void UpdateButtonOutput(btn_state *b)
* DESCRIPTION: Updates the global debounced state. This function
* should be called in a ISR a set rate using the hardware timer.
*/
static inline void DebounceSwitch()
{
static inline void DebounceSwitch() {
uint8_t i, j;
db_state[idx] = PINB & 0xFF;
idx += 1;
@ -296,11 +266,8 @@ static inline void DebounceSwitch()
}
}
/*Setup the timer0 on the AVR*/
static inline void InitTimer0()
{
static inline void InitTimer0() {
/*Zero out the tick_count var*/
tick_count = 0;
@ -312,7 +279,6 @@ static inline void InitTimer0()
// Set to div64
TCCR0B |= (1 << CS01) | (1 << CS00);
/*Enable global interrupts*/
sei();
@ -321,12 +287,10 @@ static inline void InitTimer0()
TIMSK0 |= (1 << TOIE0);
}
// ISR(TIMER0_OVF_vect)
/*The interrupt service routine for the timer0*/
ISR(TIM0_OVF_vect)
{
ISR(TIM0_OVF_vect) {
/*Disable global interrupts*/
cli();