|
|
@ -10,8 +10,8 @@ |
|
|
|
|
|
|
|
namespace simon { |
|
|
|
namespace a4988 { |
|
|
|
c_allegro_4988::c_allegro_4988(a4988_settings_t* pset) |
|
|
|
: m_pset(pset), m_initialized(false), m_alive(true) |
|
|
|
c_allegro_4988::c_allegro_4988(std::unique_ptr<a4988_settings_t> ptr_set) |
|
|
|
: m_ptr_set(std::move(ptr_set)), m_initialized(false), m_alive(true) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
@ -31,16 +31,16 @@ namespace simon { |
|
|
|
if (!set_pwm_freq(std::round(1e6/move->period_us))) { |
|
|
|
// TODO: proper error handling
|
|
|
|
} |
|
|
|
gpioHardwarePWM(m_pset->gpio_step, m_pwm_freq, PI_HW_PWM_RANGE/2); |
|
|
|
gpioWrite(m_pset->gpio_dir, move->dir); |
|
|
|
gpioHardwarePWM(m_ptr_set->gpio_step, m_pwm_freq, PI_HW_PWM_RANGE/2); |
|
|
|
gpioWrite(m_ptr_set->gpio_dir, move->dir); |
|
|
|
std::cout << move->period_us << " - " << move->steps << std::endl; |
|
|
|
auto t_sleep = move->period_us*move->steps; |
|
|
|
std::this_thread::sleep_for(std::chrono::microseconds(t_sleep)); |
|
|
|
gpioHardwarePWM(m_pset->gpio_step, m_pwm_freq, 0); |
|
|
|
gpioHardwarePWM(m_ptr_set->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); |
|
|
|
gpioWrite(m_ptr_set->gpio_en, enable->enabled); |
|
|
|
} |
|
|
|
else if (*cmd == "kill") { |
|
|
|
m_alive = false; |
|
|
@ -70,7 +70,7 @@ namespace simon { |
|
|
|
void c_allegro_4988::initialize(void) |
|
|
|
{ |
|
|
|
// TODO: proper error management throwing exceptions
|
|
|
|
if(m_pset == nullptr) { |
|
|
|
if(m_ptr_set == nullptr) { |
|
|
|
return; |
|
|
|
} |
|
|
|
// Configure clock source for PWM
|
|
|
@ -78,14 +78,14 @@ namespace simon { |
|
|
|
// Initialize pigpio library
|
|
|
|
gpioInitialise(); |
|
|
|
// Configure as outputs
|
|
|
|
gpioSetMode(m_pset->gpio_en, PI_OUTPUT); |
|
|
|
gpioSetMode(m_pset->gpio_dir, PI_OUTPUT); |
|
|
|
gpioSetMode(m_ptr_set->gpio_en, PI_OUTPUT); |
|
|
|
gpioSetMode(m_ptr_set->gpio_dir, PI_OUTPUT); |
|
|
|
// Initialize outputs
|
|
|
|
enable(); |
|
|
|
gpioWrite(m_pset->gpio_dir, 0); |
|
|
|
gpioWrite(m_ptr_set->gpio_dir, 0); |
|
|
|
// Set PWM to 0
|
|
|
|
m_pwm_freq = 1000; |
|
|
|
gpioHardwarePWM(m_pset->gpio_step, m_pwm_freq, 0); |
|
|
|
gpioHardwarePWM(m_ptr_set->gpio_step, m_pwm_freq, 0); |
|
|
|
m_initialized = true; |
|
|
|
} |
|
|
|
int c_allegro_4988::enable(void) |
|
|
|