diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2021-02-24 13:37:24 +0100 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2021-02-24 13:37:24 +0100 |
commit | 7989505bf43c6dd0ea846f075337261f52e7bd5f (patch) | |
tree | eb5257eca5e798e63f48dfb39fb81fc20ed50d50 | |
parent | dfabc6f837023ac4aaade2fddaa98a3a6777391e (diff) | |
download | hoverbit-ble-7989505bf43c6dd0ea846f075337261f52e7bd5f.tar.gz hoverbit-ble-7989505bf43c6dd0ea846f075337261f52e7bd5f.zip |
:art: Use extern MicroBit instead of sending pointer to classes
-rw-r--r-- | inc/HoverBitController.h | 6 | ||||
-rw-r--r-- | source/HoverBitController.cpp | 21 | ||||
-rw-r--r-- | source/main.cpp | 2 |
3 files changed, 14 insertions, 15 deletions
diff --git a/inc/HoverBitController.h b/inc/HoverBitController.h index 0c2960a..80ad173 100644 --- a/inc/HoverBitController.h +++ b/inc/HoverBitController.h @@ -31,6 +31,8 @@ DEALINGS IN THE SOFTWARE. #define FSAFE_TLIM_THROTTLE 1000 // When to cut the throttle #define FSAFE_TLIM_ARM 5000 // When to disarm +extern MicroBit uBit; + /** * This class can be used to interface with a AirBit card for controlling a HOVER:BIT kit. * @@ -39,8 +41,6 @@ DEALINGS IN THE SOFTWARE. */ class HoverBitController { private: - MicroBit* uBit; - int buzzer; int servo_1; int arm; @@ -59,7 +59,7 @@ class HoverBitController { void AirBit(int Pitch,int Arm,int Roll,int Throttle,int Yaw,int Aux1,int Aux2); public: - void init(MicroBit* _uBit); + void init(); unsigned int GetBatteryVoltage(void); void HoverControl(); diff --git a/source/HoverBitController.cpp b/source/HoverBitController.cpp index fc4c51b..2e908c3 100644 --- a/source/HoverBitController.cpp +++ b/source/HoverBitController.cpp @@ -31,8 +31,7 @@ DEALINGS IN THE SOFTWARE. * * @param _uBit the MicroBit instance */ -void HoverBitController::init(MicroBit* _uBit) { - uBit = _uBit; +void HoverBitController::init() { mainController = false; batteryEmpty = false; batteryMilliVolt = 3700; @@ -44,16 +43,16 @@ void HoverBitController::init(MicroBit* _uBit) { roll = 0; yaw = 0; throttle = 0; - lastReceiveTime = uBit->systemTime(); + lastReceiveTime = uBit.systemTime(); /* I am not completly sure what this does, but it seems to me like this is putting the air:bit board in some kind of "bind-mode", on the spec-sheet there isn't any documentation for what 20 pulses means tho... */ - uBit->sleep(100); + uBit.sleep(100); int o; for (o = 0; o < 20; o++) { AirBit(-90, 0, 90, 0, 90, 0, 0); - uBit->sleep(20); + uBit.sleep(20); } } @@ -61,7 +60,7 @@ void HoverBitController::init(MicroBit* _uBit) { * This is not implemented yet. */ bool HoverBitController::failSafe(void) { - unsigned long deltaReceiveTime = uBit->systemTime() - lastReceiveTime; + unsigned long deltaReceiveTime = uBit.systemTime() - lastReceiveTime; if (deltaReceiveTime > FSAFE_TLIM_THROTTLE) { Throttle(0); Rudder(0); @@ -80,7 +79,7 @@ bool HoverBitController::failSafe(void) { unsigned int HoverBitController::GetBatteryVoltage() { float batteryFactor = 4.42; int batteryMilliVolt = 3700; - return ((float)((&uBit->io.P0)->getAnalogValue()) * batteryFactor * 0.05) + ((float)batteryMilliVolt * 0.95); + return ((float)((&uBit.io.P0)->getAnalogValue()) * batteryFactor * 0.05) + ((float)batteryMilliVolt * 0.95); } /** @@ -143,7 +142,7 @@ void HoverBitController::AirBit(int Pitch,int Arm,int Roll,int Throttle,int Yaw, buf[13] = aux1S & 255; buf[14] = (6 << 2) | ((aux2S >> 8) & 3); buf[15] = aux2S & 255; - uBit->serial.send(buf, 16, SYNC_SPINWAIT); + uBit.serial.send(buf, 16, SYNC_SPINWAIT); } /** @@ -162,7 +161,7 @@ void HoverBitController::Throttle(int _throttle) { if (_throttle > 99) { throttle = 100; } else if (_throttle < 0) { throttle = 0; } else { throttle = _throttle; } - lastReceiveTime = uBit->systemTime(); + lastReceiveTime = uBit.systemTime(); } int HoverBitController::Rudder() { // The AirBit uses the roll parameter to control the hoverbit's rudder. @@ -173,14 +172,14 @@ void HoverBitController::Rudder(int _rudder) { if (_rudder > 90) { roll = 90; } else if (_rudder < -90) { roll = -90; } else { roll = _rudder; } - lastReceiveTime = uBit->systemTime(); + lastReceiveTime = uBit.systemTime(); } bool HoverBitController::Arm() { return (arm == 1); } void HoverBitController::Arm(bool _arm) { arm = (int)_arm; - lastReceiveTime = uBit->systemTime(); + lastReceiveTime = uBit.systemTime(); } bool HoverBitController::BatteryEmpty() { return batteryEmpty; diff --git a/source/main.cpp b/source/main.cpp index 8d5e837..de11801 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -258,7 +258,7 @@ int main() { /* Initialize hover:bit controller module * the init procedure have to be run within 100ms after air:bit power up */ - controller.init(&uBit); + controller.init(); // Setup listeners uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, onConnected); |