diff --git a/inc/MicroBit.h b/inc/MicroBit.h index 53f063b..8e19620 100644 --- a/inc/MicroBit.h +++ b/inc/MicroBit.h @@ -5,8 +5,8 @@ Copyright (c) 2016 British Broadcasting Corporation. This software is provided by Lancaster University by arrangement with the BBC. Modifications Copyright (c) 2016 Calliope GbR -Modifications are provided by DELTA Systems (Georg Sommer) - Thomas Kern -und Björn Eberhardt GbR by arrangement with Calliope GbR. +Modifications are provided by DELTA Systems (Georg Sommer) - Thomas Kern +und Björn Eberhardt GbR by arrangement with Calliope GbR. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -37,7 +37,6 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitDevice.h" #include "ErrorNo.h" #include "MicroBitSystemTimer.h" -#include "Matrix4.h" #include "MicroBitCompat.h" #include "MicroBitComponent.h" #include "ManagedType.h" @@ -52,9 +51,8 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitButton.h" #include "MicroBitPin.h" #include "MicroBitCompass.h" -#include "MicroBitCompass-bmx.h" #include "MicroBitCompassCalibrator.h" -#include "MicroBitAccelerometer-bmx.h" +#include "MicroBitAccelerometer.h" #include "MicroBitThermometer.h" #include "MicroBitLightSensor.h" #include "MicroBitMultiButton.h" @@ -99,19 +97,21 @@ class MicroBit uint8_t status; public: - + // Serial Interface MicroBitSerial serial; +#ifndef TARGET_NRF51_CALLIOPE // Reset Button InterruptIn resetButton; - +#endif + // Persistent key value store MicroBitStorage storage; - + // I2C Interface MicroBitI2C i2c; - + // Device level Message Bus abstraction MicroBitMessageBus messageBus; @@ -120,23 +120,23 @@ class MicroBit MicroBitButton buttonA; MicroBitButton buttonB; MicroBitMultiButton buttonAB; - MicroBitAccelerometer accelerometer; - MicroBitCompass compass; + MicroBitAccelerometer &accelerometer; + MicroBitCompass &compass; MicroBitCompassCalibrator compassCalibrator; MicroBitThermometer thermometer; - + //An object of available IO pins on the device MicroBitIO io; - + // Bluetooth related member variables. MicroBitBLEManager bleManager; MicroBitRadio radio; BLEDevice *ble; - + //Calliope MINI specific devices CalliopeRGB rgb; CalliopeSoundMotor soundmotor; - + /** * Constructor. * @@ -197,7 +197,7 @@ class MicroBit * Delay execution for the given amount of time. * * If the scheduler is running, this will deschedule the current fiber and perform - * a power efficent, concurrent sleep operation. + * a power efficient, concurrent sleep operation. * * If the scheduler is disabled or we're running in an interrupt context, this * will revert to a busy wait. @@ -247,7 +247,7 @@ class MicroBit * than the hardware random number generator built int the processor, which takes * a long time and uses a lot of energy. * - * KIDS: You shouldn't use this is the real world to generte cryptographic keys though... + * KIDS: You shouldn't use this in the real world to generate cryptographic keys though... * have a think why not. :-) * * @param max the upper range to generate a number for. This number cannot be negative. @@ -437,6 +437,7 @@ inline void MicroBit::reset() // Wait a little while for the connection to drop. wait_ms(100); } + microbit_reset(); } @@ -444,7 +445,7 @@ inline void MicroBit::reset() * Delay execution for the given amount of time. * * If the scheduler is running, this will deschedule the current fiber and perform - * a power efficent, concurrent sleep operation. + * a power efficient, concurrent sleep operation. * * If the scheduler is disabled or we're running in an interrupt context, this * will revert to a busy wait. @@ -476,7 +477,7 @@ inline void MicroBit::sleep(uint32_t milliseconds) * than the hardware random number generator built int the processor, which takes * a long time and uses a lot of energy. * - * KIDS: You shouldn't use this is the real world to generte cryptographic keys though... + * KIDS: You shouldn't use this is the real world to generate cryptographic keys though... * have a think why not. :-) * * @param max the upper range to generate a number for. This number cannot be negative. diff --git a/module.json b/module.json index 6083eef..57fab42 100644 --- a/module.json +++ b/module.json @@ -1,10 +1,10 @@ { "name": "microbit", - "version": "2.0.0-calliope-1.0.5", + "version": "2.1.1-calliope", "description": "A simple to use collection of the most commonly used components in the micro:bit runtime", "license": "MIT", "dependencies": { - "microbit-dal": "calliope-mini/microbit-dal#v2.0.0-calliope-1.0.5" + "microbit-dal": "calliope-mini/microbit-dal#pxtgc-radio0" }, "extraIncludes": [ "inc" diff --git a/source/MicroBit.cpp b/source/MicroBit.cpp index 86cdef3..8974372 100644 --- a/source/MicroBit.cpp +++ b/source/MicroBit.cpp @@ -28,7 +28,6 @@ Modifications are provided by DELTA Systems (Georg Sommer) - Thomas Kern und Björn Eberhardt GbR by arrangement with Calliope GbR. */ -#include #include "MicroBitConfig.h" /* * The underlying Nordic libraries that support BLE do not compile cleanly with the stringent GCC settings we employ @@ -66,7 +65,9 @@ RawSerial* SERIAL_DEBUG = NULL; */ MicroBit::MicroBit() : serial(USBTX, USBRX), +#ifndef TARGET_NRF51_CALLIOPE resetButton(MICROBIT_PIN_BUTTON_RESET), +#endif storage(), i2c(I2C_SDA0, I2C_SCL0), messageBus(), @@ -74,9 +75,9 @@ MicroBit::MicroBit() : buttonA(MICROBIT_PIN_BUTTON_A, MICROBIT_ID_BUTTON_A), buttonB(MICROBIT_PIN_BUTTON_B, MICROBIT_ID_BUTTON_B), buttonAB(MICROBIT_ID_BUTTON_A,MICROBIT_ID_BUTTON_B, MICROBIT_ID_BUTTON_AB), - accelerometer(i2c), - compass(i2c, accelerometer, storage), - compassCalibrator(compass, accelerometer, display), + accelerometer(MicroBitAccelerometer::autoDetect(i2c)), + compass(MicroBitCompass::autoDetect(i2c)), + compassCalibrator(compass, accelerometer, display, storage), thermometer(storage), io(MICROBIT_ID_IO_P0,MICROBIT_ID_IO_P1,MICROBIT_ID_IO_P2, MICROBIT_ID_IO_P3,MICROBIT_ID_IO_P4,MICROBIT_ID_IO_P5, @@ -99,9 +100,12 @@ MicroBit::MicroBit() : // Clear our status status = 0; +// there is no soft reset pin available on the Callipo mini, it is resetted via the KL26z SWD +#ifndef TARGET_NRF51_CALLIOPE // Bring up soft reset functionality as soon as possible. resetButton.mode(PullUp); resetButton.fall(this, &MicroBit::reset); +#endif } /** @@ -124,14 +128,6 @@ void MicroBit::init() if (status & MICROBIT_INITIALIZED) return; - // configure the accelerometer - accelerometer.configure(); - -#if CONFIG_ENABLED(MICROBIT_HEAP_ALLOCATOR) - // Bring up a nested heap allocator. - microbit_create_nested_heap(MICROBIT_NESTED_HEAP_SIZE); -#endif - // Bring up fiber scheduler. scheduler_init(messageBus); @@ -146,17 +142,35 @@ void MicroBit::init() status |= MICROBIT_INITIALIZED; #if CONFIG_ENABLED(MICROBIT_BLE_PAIRING_MODE) - // Test if we need to enter BLE pairing mode... int i=0; + // Test if we need to enter BLE pairing mode + // If a RebootMode Key has been set boot straight into BLE mode + KeyValuePair* RebootMode = storage.get("RebootMode"); + KeyValuePair* flashIncomplete = storage.get("flashIncomplete"); sleep(100); - while (buttonA.isPressed() && buttonB.isPressed() && i<10) + // Animation + uint8_t x = 0; uint8_t y = 0; + while ((buttonA.isPressed() && buttonB.isPressed() && i<25) || RebootMode != NULL || flashIncomplete != NULL) { - sleep(100); - i++; + display.image.setPixelValue(x,y,255); + sleep(50); + i++; x++; - if (i == 10) + // Gradually fill screen + if(x == 5){ + y++; x = 0; + } + + if (i == 25 || RebootMode != NULL) { -#if CONFIG_ENABLED(MICROBIT_HEAP_ALLOCATOR) && CONFIG_ENABLED(MICROBIT_HEAP_REUSE_SD) + // Remove KV if it exists + if(RebootMode != NULL){ + storage.remove("RebootMode"); + } + delete RebootMode; + delete flashIncomplete; + +#if CONFIG_ENABLED(MICROBIT_HEAP_REUSE_SD) microbit_create_heap(MICROBIT_SD_GATT_TABLE_START + MICROBIT_SD_GATT_TABLE_SIZE, MICROBIT_SD_LIMIT); #endif // Start the BLE stack, if it isn't already running. @@ -173,7 +187,7 @@ void MicroBit::init() #endif // Attempt to bring up a second heap region, using unused memory normally reserved for Soft Device. -#if CONFIG_ENABLED(MICROBIT_HEAP_ALLOCATOR) && CONFIG_ENABLED(MICROBIT_HEAP_REUSE_SD) +#if CONFIG_ENABLED(MICROBIT_HEAP_REUSE_SD) #if CONFIG_ENABLED(MICROBIT_BLE_ENABLED) microbit_create_heap(MICROBIT_SD_GATT_TABLE_START + MICROBIT_SD_GATT_TABLE_SIZE, MICROBIT_SD_LIMIT); #else @@ -218,8 +232,7 @@ void MicroBit::onListenerRegisteredEvent(MicroBitEvent evt) case MICROBIT_ID_COMPASS: // A listener has been registered for the compass. // The compass uses lazy instantiation, we just need to read the data once to start it running. - // Touch the compass through the heading() function to ensure it is calibrated. if it isn't this will launch any associated calibration algorithms. - compass.heading(); + compass.getSample(); break; @@ -227,7 +240,7 @@ void MicroBit::onListenerRegisteredEvent(MicroBitEvent evt) case MICROBIT_ID_GESTURE: // A listener has been registered for the accelerometer. // The accelerometer uses lazy instantiation, we just need to read the data once to start it running. - accelerometer.updateSample(); + accelerometer.getSample(); break; case MICROBIT_ID_THERMOMETER: