|
@ -38,10 +38,20 @@ namespace simon { |
|
|
std::this_thread::sleep_for(std::chrono::microseconds(t_sleep)); |
|
|
std::this_thread::sleep_for(std::chrono::microseconds(t_sleep)); |
|
|
gpioHardwarePWM(m_pset->gpio_step, m_pwm_freq, 0); |
|
|
gpioHardwarePWM(m_pset->gpio_step, m_pwm_freq, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
else if (*cmd == "enable") { |
|
|
|
|
|
auto enable = std::static_pointer_cast<c_enable>(cmd); |
|
|
|
|
|
gpioWrite(m_pset->gpio_en, enable->enabled); |
|
|
|
|
|
} |
|
|
|
|
|
else if (*cmd == "kill") { |
|
|
|
|
|
m_alive = false; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
// TODO: Throw an exception here
|
|
|
|
|
|
} |
|
|
m_queue.pop(); |
|
|
m_queue.pop(); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
m_alive = false; |
|
|
// Idle
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -49,6 +59,14 @@ namespace simon { |
|
|
{ |
|
|
{ |
|
|
m_queue.push(cmd); |
|
|
m_queue.push(cmd); |
|
|
} |
|
|
} |
|
|
|
|
|
void c_allegro_4988::post_move(const unsigned steps, const bool dir, |
|
|
|
|
|
const unsigned period_us) |
|
|
|
|
|
{ |
|
|
|
|
|
auto move(std::make_shared<c_move>(steps, dir, period_us)); |
|
|
|
|
|
auto cmd = std::static_pointer_cast<c_cmd>(move); |
|
|
|
|
|
m_queue.push(cmd); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void c_allegro_4988::initialize(void) |
|
|
void c_allegro_4988::initialize(void) |
|
|
{ |
|
|
{ |
|
|
// TODO: proper error management throwing exceptions
|
|
|
// TODO: proper error management throwing exceptions
|
|
@ -73,15 +91,26 @@ namespace simon { |
|
|
int c_allegro_4988::enable(void) |
|
|
int c_allegro_4988::enable(void) |
|
|
{ |
|
|
{ |
|
|
// TODO: proper error handling
|
|
|
// TODO: proper error handling
|
|
|
gpioWrite(m_pset->gpio_en, 0); |
|
|
auto enable(std::make_shared<c_enable>(true)); |
|
|
|
|
|
auto cmd = std::static_pointer_cast<c_cmd>(enable); |
|
|
|
|
|
m_queue.push(cmd); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
int c_allegro_4988::disable(void) |
|
|
int c_allegro_4988::disable(void) |
|
|
{ |
|
|
{ |
|
|
// TODO: proper error handling
|
|
|
// TODO: proper error handling
|
|
|
gpioWrite(m_pset->gpio_en, 1); |
|
|
auto enable(std::make_shared<c_enable>(false)); |
|
|
|
|
|
auto cmd = std::static_pointer_cast<c_cmd>(enable); |
|
|
|
|
|
m_queue.push(cmd); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
void c_allegro_4988::kill(void) |
|
|
|
|
|
{ |
|
|
|
|
|
// TODO: proper error handling
|
|
|
|
|
|
auto kill(std::make_shared<c_kill>()); |
|
|
|
|
|
auto cmd = std::static_pointer_cast<c_cmd>(kill); |
|
|
|
|
|
m_queue.push(cmd); |
|
|
|
|
|
} |
|
|
int c_allegro_4988::set_pwm_freq(const unsigned pwm_freq) |
|
|
int c_allegro_4988::set_pwm_freq(const unsigned pwm_freq) |
|
|
{ |
|
|
{ |
|
|
if (pwm_freq > PI_HW_PWM_MAX_FREQ) { |
|
|
if (pwm_freq > PI_HW_PWM_MAX_FREQ) { |
|
|