From 346ab77c274d8ea2ab5c24453587a6fc24b84330 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Mon, 19 Oct 2015 12:25:59 -0200 Subject: [PATCH] AP_HAL_Empty: implement HAL::run() --- libraries/AP_HAL_Empty/AP_HAL_Empty_Main.h | 8 +++----- libraries/AP_HAL_Empty/HAL_Empty_Class.cpp | 16 ++++++++++++++++ libraries/AP_HAL_Empty/HAL_Empty_Class.h | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/libraries/AP_HAL_Empty/AP_HAL_Empty_Main.h b/libraries/AP_HAL_Empty/AP_HAL_Empty_Main.h index 0bdf5c3aa7..2154645b36 100644 --- a/libraries/AP_HAL_Empty/AP_HAL_Empty_Main.h +++ b/libraries/AP_HAL_Empty/AP_HAL_Empty_Main.h @@ -6,11 +6,9 @@ #if CONFIG_HAL_BOARD == HAL_BOARD_EMPTY #define AP_HAL_MAIN() extern "C" {\ int main (void) {\ - hal.init(0, NULL); \ - setup();\ - hal.scheduler->system_initialized(); \ - for(;;) loop();\ - return 0;\ + AP_HAL::HAL::FunCallbacks callbacks(setup, loop); \ + hal.run(0, NULL, &callbacks); \ + return 0; \ }\ } #endif // HAL_BOARD_EMPTY diff --git a/libraries/AP_HAL_Empty/HAL_Empty_Class.cpp b/libraries/AP_HAL_Empty/HAL_Empty_Class.cpp index c55a2d4599..abe8349aa7 100644 --- a/libraries/AP_HAL_Empty/HAL_Empty_Class.cpp +++ b/libraries/AP_HAL_Empty/HAL_Empty_Class.cpp @@ -2,6 +2,8 @@ #include #if CONFIG_HAL_BOARD == HAL_BOARD_EMPTY +#include + #include "HAL_Empty_Class.h" #include "AP_HAL_Empty_Private.h" @@ -52,6 +54,20 @@ void HAL_Empty::init(int argc,char* const argv[]) const { _member->init(); } +void HAL_Empty::run(int argc, char* const argv[], Callbacks* callbacks) const +{ + assert(callbacks); + + init(argc, argv); + + callbacks->setup(); + scheduler->system_initialized(); + + for (;;) { + callbacks->loop(); + } +} + const AP_HAL::HAL& AP_HAL::get_HAL() { static const HAL_Empty hal; return hal; diff --git a/libraries/AP_HAL_Empty/HAL_Empty_Class.h b/libraries/AP_HAL_Empty/HAL_Empty_Class.h index 29abb45e61..5e6ad927ff 100644 --- a/libraries/AP_HAL_Empty/HAL_Empty_Class.h +++ b/libraries/AP_HAL_Empty/HAL_Empty_Class.h @@ -11,6 +11,7 @@ class HAL_Empty : public AP_HAL::HAL { public: HAL_Empty(); void init(int argc, char * const * argv) const; + void run(int argc, char* const* argv, Callbacks* callbacks) const override; private: Empty::EmptyPrivateMember *_member; };