commented out code that won't be used for hardware tests.

This commit is contained in:
Jake Goodwin 2025-02-12 14:53:26 -08:00
parent 98c9fde2b9
commit e50463ab2b
1 changed files with 35 additions and 36 deletions

View File

@ -1,7 +1,3 @@
#ifndef MCU
#define MCU atiny13a
#endif
#ifndef F_CPU
#define F_CPU 4800000UL
#endif
@ -12,7 +8,7 @@
#include <util/delay.h>
// These are only included during development for the LSP server.
#include "iotn13.h"
//#include "iotn13.h"
// #include "iotn13a.h"
// #############################
@ -37,7 +33,6 @@ volatile uint16_t tick_count;
static inline void InitTimer0(void);
static void InitBtn(btn_state *b, uint8_t input_pin, uint8_t output_pin);
static void ToggleOutput(btn_state *b);
static void ClearButtonTimer(btn_state *b);
static void StartButtonTimer(btn_state *b);
static void CheckButtonLongpress(btn_state *b);
@ -48,7 +43,7 @@ static void UpdateButtonOutput(btn_state *b);
// MAIN
// #############################
int main(int argc, char **argv) {
int main() {
InitProg();
while (1) {
@ -106,28 +101,43 @@ uint16_t ReadADC(void) {
* ############################
*/
void MotorSetSavePos()
{
uint8_t pos = (uint8_t)(ReadADC() >> 2);
eeprom_write_byte((uint8_t *)ROM_SS1_ADR, pos);
return;
void MotorSetSavePos() {
uint8_t pos = (uint8_t)(ReadADC() >> 2);
eeprom_write_byte((uint8_t *)ROM_SS1_ADR, pos);
return;
}
uint8_t MotorGetSavedPos(void)
{
return (uint8_t) eeprom_read_byte((uint8_t *)ROM_SS1_ADR);
uint8_t MotorGetSavedPos(void) {
return (uint8_t)eeprom_read_byte((uint8_t *)ROM_SS1_ADR);
}
void MotorMoveTo(uint8_t pos)
{
return;
void MotorMoveTo(uint8_t target) {
uint8_t pos = 0;
while (target != pos) {
pos = (uint8_t)(ReadADC() >> 2);
if (target > pos) {
MotorMove(1);
} else {
MotorMove(0);
}
// The delay ratio controlls the PWM waveforms.
_delay_ms(50);
MotorCoast();
_delay_ms(50);
}
return;
}
// Using the compatable bool type.
void MotorMove(uint8_t fwd)
{
return;
void MotorMove(uint8_t fwd) {
if (fwd) {
PORTB |= (1 << PWM_PIN1);
PORTB &= ~(1 << PWM_PIN2);
} else {
PORTB |= (1 << PWM_PIN2);
PORTB &= ~(1 << PWM_PIN1);
}
return;
}
void MotorCoast(void) {
@ -158,17 +168,6 @@ static void InitBtn(btn_state *b, uint8_t input_pin, uint8_t output_pin) {
PORTB &= ~(1 << b->output_pin);
}
/*This is the fancy function to toggle output pins*/
static void ToggleOutput(btn_state *b) {
if (!b->is_active) {
b->is_active = 1;
PORTB |= (1 << b->output_pin);
} else {
b->is_active = 0;
PORTB &= ~(1 << b->output_pin);
}
}
static void ClearButtonTimer(btn_state *b) {
b->timer_enabled = 0;
b->is_long_pressed = 0;
@ -207,7 +206,7 @@ static void UpdateButtonOutput(btn_state *b) {
/*If this is a new event.*/
if (!b->is_long_pressed && !b->timer_enabled) {
/*Then start the timer and update the output*/
//ToggleOutput(b);
// ToggleOutput(b);
StartButtonTimer(b);
return;
}
@ -231,7 +230,7 @@ static void UpdateButtonOutput(btn_state *b) {
MotorSetSavePos();
}
/*If the button pres was a short one.*/
else if(!b->is_long_pressed) {
else if (!b->is_long_pressed) {
MotorMoveTo(MotorGetSavedPos());
}
ClearButtonTimer(b);