generated from TDD-Templates/cmake_cpputest_template_avr
Added logic to only call the motor move to when needed.
This commit is contained in:
parent
a170ceae96
commit
059a75dc6a
24
src/main.c
24
src/main.c
|
@ -73,8 +73,7 @@ void InitProg(void) {
|
||||||
|
|
||||||
// Checks against a bit pattern we defined to represent the start of data.
|
// Checks against a bit pattern we defined to represent the start of data.
|
||||||
if (eeprom_read_byte((uint8_t *)ROM_SP_ADR) == START_PATTERN) {
|
if (eeprom_read_byte((uint8_t *)ROM_SP_ADR) == START_PATTERN) {
|
||||||
// Reads the two bytes representing the two states.
|
MotorMoveTo(eeprom_read_byte((uint8_t *)ROM_SS1_ADR));
|
||||||
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.
|
// 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_SP_ADR, START_PATTERN);
|
||||||
|
@ -119,23 +118,23 @@ uint8_t MotorGetSavedPos(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotorMoveTo(uint8_t target) {
|
void MotorMoveTo(uint8_t target) {
|
||||||
uint8_t pos = 0;
|
|
||||||
while (target != pos) {
|
uint8_t pos = (uint8_t)(ReadADC() >> 2);
|
||||||
|
|
||||||
|
while (diff(target, pos) > 8) {
|
||||||
pos = (uint8_t)(ReadADC() >> 2);
|
pos = (uint8_t)(ReadADC() >> 2);
|
||||||
if (diff(target, pos) < 8){
|
if (target > pos) {
|
||||||
MotorCoast();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (target > pos) {
|
|
||||||
MotorMove(1);
|
MotorMove(1);
|
||||||
} else {
|
} else {
|
||||||
MotorMove(0);
|
MotorMove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The delay ratio controlls the PWM waveforms.
|
// The delay ratio controlls the PWM waveforms.
|
||||||
_delay_ms(5);
|
_delay_ms(5);
|
||||||
MotorCoast();
|
MotorCoast();
|
||||||
_delay_ms(5);
|
_delay_ms(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,6 +212,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 the button is actually pressed.*/
|
||||||
if (b->is_pressed) {
|
if (b->is_pressed) {
|
||||||
|
b->is_active = 1;
|
||||||
|
|
||||||
/*If this is a new event.*/
|
/*If this is a new event.*/
|
||||||
if (!b->is_long_pressed && !b->timer_enabled) {
|
if (!b->is_long_pressed && !b->timer_enabled) {
|
||||||
|
@ -242,8 +242,14 @@ static void UpdateButtonOutput(btn_state *b) {
|
||||||
}
|
}
|
||||||
/*If the button pres was a short one.*/
|
/*If the button pres was a short one.*/
|
||||||
else if (!b->is_long_pressed) {
|
else if (!b->is_long_pressed) {
|
||||||
|
if(b->is_active) {
|
||||||
MotorMoveTo(MotorGetSavedPos());
|
MotorMoveTo(MotorGetSavedPos());
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
MotorCoast();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b->is_active = 0;
|
||||||
ClearButtonTimer(b);
|
ClearButtonTimer(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue