|
@ -12,7 +12,6 @@ Input::Input(void) { |
|
|
this->curr = &(this->input[0]); |
|
|
this->curr = &(this->input[0]); |
|
|
this->old = &(this->input[1]); |
|
|
this->old = &(this->input[1]); |
|
|
memset(this->input,0, sizeof(this->input)); |
|
|
memset(this->input,0, sizeof(this->input)); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
void Input::mark_processed(void) { |
|
|
void Input::mark_processed(void) { |
|
|
struct data* temp = this->old; |
|
|
struct data* temp = this->old; |
|
@ -27,6 +26,7 @@ struct Input::data* Input::get_curr_input(void) { |
|
|
struct Input::data* Input::get_old_input(void) { |
|
|
struct Input::data* Input::get_old_input(void) { |
|
|
return this->old; |
|
|
return this->old; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Input::init() { |
|
|
void Input::init() { |
|
|
analogReadResolution(16); |
|
|
analogReadResolution(16); |
|
|
|
|
|
|
|
@ -57,6 +57,7 @@ void Input::init() { |
|
|
this->yaw.min = 500; |
|
|
this->yaw.min = 500; |
|
|
this->roll.min = 500; |
|
|
this->roll.min = 500; |
|
|
this->pitch.min = 500; |
|
|
this->pitch.min = 500; |
|
|
|
|
|
|
|
|
this->throttle.max = 500; |
|
|
this->throttle.max = 500; |
|
|
this->yaw.max = 500; |
|
|
this->yaw.max = 500; |
|
|
this->roll.max = 500; |
|
|
this->roll.max = 500; |
|
@ -64,8 +65,10 @@ void Input::init() { |
|
|
} |
|
|
} |
|
|
void Input::do_calibration(void) { |
|
|
void Input::do_calibration(void) { |
|
|
int8_t turns = 50; |
|
|
int8_t turns = 50; |
|
|
int8_t i = turns; |
|
|
|
|
|
|
|
|
int8_t i; |
|
|
|
|
|
|
|
|
|
|
|
// min max calibration
|
|
|
|
|
|
i = turns; |
|
|
while(i > 0) { |
|
|
while(i > 0) { |
|
|
this->update(); |
|
|
this->update(); |
|
|
if (true == this->save_calibration()) { |
|
|
if (true == this->save_calibration()) { |
|
@ -87,6 +90,220 @@ void Input::do_calibration(void) { |
|
|
this->pitch.min, this->pitch.max, |
|
|
this->pitch.min, this->pitch.max, |
|
|
this->yaw.min, this->yaw.max); |
|
|
this->yaw.min, this->yaw.max); |
|
|
|
|
|
|
|
|
|
|
|
// center
|
|
|
|
|
|
debugln("now center all sticks"); |
|
|
|
|
|
i = turns; |
|
|
|
|
|
while(i > 0) { |
|
|
|
|
|
delay(100); |
|
|
|
|
|
this->update(); |
|
|
|
|
|
if (false == this->is_centered()) { |
|
|
|
|
|
i = turns; |
|
|
|
|
|
}else { |
|
|
|
|
|
i -= 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
debugln("now Move throttle to max"); |
|
|
|
|
|
i = turns; |
|
|
|
|
|
while(i>0) { |
|
|
|
|
|
delay(100); |
|
|
|
|
|
this->update(); |
|
|
|
|
|
|
|
|
|
|
|
if (true == this->is_throttle_up()) { |
|
|
|
|
|
i--; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (true == this->is_throttle_down()) { |
|
|
|
|
|
this->throttle.inverted = ! this->throttle.inverted; |
|
|
|
|
|
i = turns; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
debugln("throttle invert is %d", this->throttle.inverted); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debugln("now Move yaw to max"); |
|
|
|
|
|
i = turns; |
|
|
|
|
|
while(i>0) { |
|
|
|
|
|
delay(100); |
|
|
|
|
|
this->update(); |
|
|
|
|
|
|
|
|
|
|
|
if (true == this->is_yaw_up()) { |
|
|
|
|
|
i--; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (true == this->is_yaw_down()) { |
|
|
|
|
|
this->yaw.inverted = ! this->yaw.inverted; |
|
|
|
|
|
i = turns; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
debugln("yaw invert is %d", this->yaw.inverted); |
|
|
|
|
|
|
|
|
|
|
|
debugln("now Move pitch to max"); |
|
|
|
|
|
i = turns; |
|
|
|
|
|
while(i>0) { |
|
|
|
|
|
delay(100); |
|
|
|
|
|
this->update(); |
|
|
|
|
|
|
|
|
|
|
|
if (true == this->is_pitch_up()) { |
|
|
|
|
|
i--; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (true == this->is_pitch_down()) { |
|
|
|
|
|
this->pitch.inverted = ! this->pitch.inverted; |
|
|
|
|
|
i = turns; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
debugln("pitch invert is %d", this->pitch.inverted); |
|
|
|
|
|
|
|
|
|
|
|
debugln("now Move roll to max"); |
|
|
|
|
|
i = turns; |
|
|
|
|
|
while(i>0) { |
|
|
|
|
|
delay(100); |
|
|
|
|
|
this->update(); |
|
|
|
|
|
|
|
|
|
|
|
if (true == this->is_roll_up()) { |
|
|
|
|
|
i--; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (true == this->is_roll_down()) { |
|
|
|
|
|
this->roll.inverted = ! this->roll.inverted; |
|
|
|
|
|
i = turns; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
debugln("roll invert is %d", this->roll.inverted); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
bool Input::is_centered(void) { |
|
|
|
|
|
return this->is_centered_left() && this->is_centered_right(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Input::is_centered_left(void) { |
|
|
|
|
|
uint16_t range; |
|
|
|
|
|
uint16_t delta; |
|
|
|
|
|
|
|
|
|
|
|
range = this->throttle.max - this->throttle.min; |
|
|
|
|
|
delta = range >>4; |
|
|
|
|
|
if ( this->curr->throttle < this->throttle.min + range/2 - delta || |
|
|
|
|
|
this->curr->throttle > this->throttle.min + range/2 + delta |
|
|
|
|
|
) { |
|
|
|
|
|
// throttle is not centered
|
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
range = this->yaw.max - this->yaw.min; |
|
|
|
|
|
delta = range >>4; |
|
|
|
|
|
if ( this->curr->yaw < this->yaw.min + range/2 - delta || |
|
|
|
|
|
this->curr->yaw > this->yaw.min + range/2 + delta |
|
|
|
|
|
) { |
|
|
|
|
|
// yaw is not centered
|
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
bool Input::is_centered_right(void) { |
|
|
|
|
|
uint16_t range; |
|
|
|
|
|
uint16_t delta; |
|
|
|
|
|
|
|
|
|
|
|
range = this->pitch.max - this->pitch.min; |
|
|
|
|
|
delta = range >>4; |
|
|
|
|
|
if ( this->curr->pitch < this->pitch.min + range/2 - delta || |
|
|
|
|
|
this->curr->pitch > this->pitch.min + range/2 + delta |
|
|
|
|
|
) { |
|
|
|
|
|
// pitch is not centered
|
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
range = this->roll.max - this->roll.min; |
|
|
|
|
|
delta = range >>4; |
|
|
|
|
|
if ( this->curr->roll < this->roll.min + range/2 - delta || |
|
|
|
|
|
this->curr->roll > this->roll.min + range/2 + delta |
|
|
|
|
|
) { |
|
|
|
|
|
// roll is not centered
|
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Input::is_menu_left(void) { |
|
|
|
|
|
return this->is_roll_down(); |
|
|
|
|
|
} |
|
|
|
|
|
bool Input::is_menu_right(void) { |
|
|
|
|
|
return this->is_roll_up(); |
|
|
|
|
|
} |
|
|
|
|
|
bool Input::is_menu_down(void) { |
|
|
|
|
|
return this->is_pitch_down(); |
|
|
|
|
|
} |
|
|
|
|
|
bool Input::is_menu_up(void) { |
|
|
|
|
|
return this->is_pitch_up(); |
|
|
|
|
|
} |
|
|
|
|
|
bool Input::is_throttle_down(void) { |
|
|
|
|
|
uint16_t delta = (this->throttle.max - this->throttle.min)/3; |
|
|
|
|
|
if ( this->curr->throttle < this->throttle.min + delta) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
bool Input::is_throttle_up(void) { |
|
|
|
|
|
uint16_t delta = (this->throttle.max - this->throttle.min)/3; |
|
|
|
|
|
if ( this->curr->throttle > this->throttle.max - delta) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
bool Input::is_yaw_up(void) { |
|
|
|
|
|
uint16_t delta = (this->yaw.max - this->yaw.min)/3; |
|
|
|
|
|
if ( this->curr->yaw > this->yaw.max - delta) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
bool Input::is_yaw_down(void) { |
|
|
|
|
|
uint16_t delta = (this->yaw.max - this->yaw.min)/3; |
|
|
|
|
|
if ( this->curr->yaw > this->yaw.min + delta) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Input::is_roll_down(void) { |
|
|
|
|
|
uint16_t delta = (this->roll.max - this->roll.min)/3; |
|
|
|
|
|
if ( this->curr->roll < this->roll.min + delta) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
bool Input::is_roll_up(void) { |
|
|
|
|
|
uint16_t delta = (this->roll.max - this->roll.min)/3; |
|
|
|
|
|
if ( this->curr->roll > this->roll.max - delta) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
bool Input::is_pitch_up(void) { |
|
|
|
|
|
uint16_t delta = (this->pitch.max - this->pitch.min)/3; |
|
|
|
|
|
if ( this->curr->pitch > this->pitch.max - delta) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
bool Input::is_pitch_down(void) { |
|
|
|
|
|
uint16_t delta = (this->pitch.max - this->pitch.min)/3; |
|
|
|
|
|
if ( this->curr->pitch > this->pitch.min + delta) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Input::is_menu_triggered(void) { |
|
|
|
|
|
return this->curr->menu; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool Input::save_calibration(void) { |
|
|
bool Input::save_calibration(void) { |
|
@ -180,20 +397,3 @@ void Input::update(void) { |
|
|
Channel_data[CH5+i] = (this->curr->aux[i]) ? CHANNEL_MAX_100 : CHANNEL_MIN_100; |
|
|
Channel_data[CH5+i] = (this->curr->aux[i]) ? CHANNEL_MAX_100 : CHANNEL_MIN_100; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool Input::menu_triggered(void) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Input::left_triggered(void) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
bool Input::right_triggered(void) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
bool Input::down_triggered(void) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
bool Input::up_triggered(void) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|