aboutsummaryrefslogtreecommitdiff
path: root/source/main.cpp
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2021-06-08 00:56:19 +0200
committerJakob Stendahl <jakob.stendahl@outlook.com>2021-06-08 00:56:19 +0200
commit820e89ead9577c7aa4b7ef10f363daf8a28247ac (patch)
tree8006e48de8129e836ee45ef4516a036625949062 /source/main.cpp
parente9a5544db7be5e461b92743b37adcc77162483b7 (diff)
downloadhoverbit-ble-820e89ead9577c7aa4b7ef10f363daf8a28247ac.tar.gz
hoverbit-ble-820e89ead9577c7aa4b7ef10f363daf8a28247ac.zip
:sparkles: Do lots of small tweaks
Diffstat (limited to 'source/main.cpp')
-rw-r--r--source/main.cpp35
1 files changed, 14 insertions, 21 deletions
diff --git a/source/main.cpp b/source/main.cpp
index 6f3332b..16e665a 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -52,6 +52,7 @@ void onDisconnected(MicroBitEvent) {
void onDelim(MicroBitEvent) {
ManagedString msg = uart->readUntil(BLE_UART_DELIM);
+ uBit.display.image.setPixelValue(1, 0, 255);
int length = msg.length();
const char* command = msg.toCharArray();
@@ -120,13 +121,6 @@ void onDelim(MicroBitEvent) {
uart->send(accString);
}
-void onButtonA_press(MicroBitEvent e) {
- hoverBitDisplay.nextMode();
-}
-
-void onButtonB_press(MicroBitEvent e) {
-}
-
void onButtonAB_press(MicroBitEvent e) {
hoverBitDisplay.pause();
uBit.display.scroll(VERSION);
@@ -135,14 +129,15 @@ void onButtonAB_press(MicroBitEvent e) {
int main() {
uBit.init();
- uBit.audio.setVolume(255);
// Setup serial for Spektsat communication with air:bit board
uBit.serial.setBaud(115200);
uBit.serial.redirect(uBit.io.P1, uBit.io.P2);
- /* Initialize hover:bit controller module
- * the init procedure have to be run within 100ms after air:bit power up */
+ /* Initialize hover:bit controller module, these timeouts are some voodo
+ magic I don't quite understand. But for the init method to function
+ as we want, there should be a relatively long delay here. */
+ uBit.sleep(3000);
controller.init();
// Setup listeners
@@ -150,8 +145,6 @@ int main() {
uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, onDisconnected);
uBit.messageBus.listen(MICROBIT_ID_BLE_UART, MICROBIT_UART_S_EVT_DELIM_MATCH, onDelim);
- uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA_press);
- uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB_press);
uBit.messageBus.listen(MICROBIT_ID_BUTTON_AB, MICROBIT_BUTTON_EVT_CLICK, onButtonAB_press);
// uartService
@@ -160,21 +153,21 @@ int main() {
uart = new MicroBitUARTService(*uBit.ble, 32, 32);
uart->eventOn(BLE_UART_DELIM);
+ uBit.audio.setVolume(20);
uBit.audio.soundExpressions.play(ManagedString("hello"));
+ hoverBitDisplay.mode(GRAPHS);
while (1) {
- if (uBit.logo.isPressed()) {
- if (!bCapLogoIsPressed) {
- bCapLogoIsPressed = true;
- hoverBitDisplay.nextMode();
- }
- } else if (bCapLogoIsPressed) {
- bCapLogoIsPressed = false;
- }
-
hoverBitDisplay.update();
controller.HoverControl();
+ if (uBit.systemTime() % 2000 > 1900) {
+ uart->send(
+ ManagedString("B:")
+ + ManagedString((int)controller.GetBatteryVoltage())
+ );
+ }
uBit.sleep(20);
+ schedule();
}
// If main exits, there may still be other fibers running or registered event handlers etc.