Remove MotorController, use nrf_gpio Motor pin, apptimer repeat (#34)
Remove the custom MotorController class and use the upstream MotorController instead. To enable this move add custom code in nrf_gpio to handle the Motor pin instead of the custom motor_is_running member variable. Also implement the repeating app_timer type used in the upstream MotorController.
This commit is contained in:
@@ -57,8 +57,12 @@ ret_code_t app_timer_init(void) {
|
||||
ret_code_t app_timer_create(app_timer_t *p_timer_id,
|
||||
app_timer_mode_t mode,
|
||||
app_timer_timeout_handler_t timeout_handler) {
|
||||
if (mode != APP_TIMER_MODE_SINGLE_SHOT) {
|
||||
throw std::runtime_error("only mode 'APP_TIMER_MODE_SINGLE_SHOT' implemented");
|
||||
if (mode == APP_TIMER_MODE_SINGLE_SHOT) {
|
||||
p_timer_id->repeating = false;
|
||||
} else if (mode == APP_TIMER_MODE_REPEATED) {
|
||||
p_timer_id->repeating = true;
|
||||
} else {
|
||||
throw std::runtime_error("only mode 'APP_TIMER_MODE_SINGLE_SHOT' or 'APP_TIMER_MODE_REPEATED' implemented");
|
||||
}
|
||||
p_timer_id->handler = timeout_handler;
|
||||
return 0;
|
||||
@@ -67,10 +71,15 @@ Uint32 timeout_callback_wrapper(Uint32 interval, void *param)
|
||||
{
|
||||
auto* timer_id = static_cast<app_timer_t*>(param);
|
||||
timer_id->handler(timer_id->p_context);
|
||||
return 0; // cancel timer
|
||||
if (timer_id->repeating) {
|
||||
return timer_id->repeat_period;
|
||||
} else {
|
||||
return 0; // cancel timer
|
||||
}
|
||||
}
|
||||
ret_code_t app_timer_start(app_timer_t &timer_id, uint32_t timeout_ticks, void * p_context) {
|
||||
timer_id.p_context = p_context;
|
||||
timer_id.repeat_period = timeout_ticks;
|
||||
timer_id.sdl_timer_id = SDL_AddTimer(timeout_ticks, timeout_callback_wrapper, (void*)(&timer_id));
|
||||
return 0;
|
||||
}
|
||||
|
@@ -88,6 +88,13 @@ typedef uint32_t ret_code_t;
|
||||
/**@brief Application time-out handler type. */
|
||||
typedef void (*app_timer_timeout_handler_t)(void * p_context);
|
||||
|
||||
/**@brief Timer modes. */
|
||||
typedef enum
|
||||
{
|
||||
APP_TIMER_MODE_SINGLE_SHOT, /**< The timer will expire only once. */
|
||||
APP_TIMER_MODE_REPEATED /**< The timer will restart each time it expires. */
|
||||
} app_timer_mode_t;
|
||||
|
||||
struct app_timer_t
|
||||
{
|
||||
//nrf_sortlist_item_t list_item; /**< Token used by sortlist. */
|
||||
@@ -96,6 +103,7 @@ struct app_timer_t
|
||||
uint32_t repeat_period; /**< Repeat period (0 if single shot mode). */
|
||||
app_timer_timeout_handler_t handler; /**< User handler. */
|
||||
void * p_context; /**< User context. */
|
||||
bool repeating;
|
||||
//NRF_LOG_INSTANCE_PTR_DECLARE(p_log) /**< Pointer to instance of the logger object (Conditionally compiled). */
|
||||
//volatile bool active; /**< Flag indicating that timer is active. */
|
||||
};
|
||||
@@ -127,13 +135,6 @@ uint32_t constexpr APP_TIMER_TICKS(uint32_t ms) {
|
||||
);
|
||||
}
|
||||
|
||||
/**@brief Timer modes. */
|
||||
typedef enum
|
||||
{
|
||||
APP_TIMER_MODE_SINGLE_SHOT, /**< The timer will expire only once. */
|
||||
APP_TIMER_MODE_REPEATED /**< The timer will restart each time it expires. */
|
||||
} app_timer_mode_t;
|
||||
|
||||
/**@brief Function for initializing the timer module.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the module was initialized successfully.
|
||||
|
Reference in New Issue
Block a user