uses BBC micro:bit to measure and display indoor air quality using Bosch BME680 and/or Sensirion SGP30

Dependencies:   microbit

uses Bosch BME680 and/or Sensirion SGP30 sensors to measure indor air quality

sensors should be connected to BBC micro:bit using i2c

commands are received and data is being sent using uBit / nordic radio protocol

display ---

last line always indicates: - first dot: bme680 detected - second dot: sgp30 detected - third dot: sgp 30 setting humidity/temperature - fourth dor: sgp30 measuring - fith dot: bme680 measuring

the detect dots should be in a stable state (not blinking) the measuring dots should be blinking (constant light means: measurement failed)

if only one bme680 is present: - first 3 lines indicate gas resistence (air quality / more dots == worse quality) - fourth line indicates humidity level

if only sgp30 is present: - first two lines indicate SGP30 VOC level - third and fourth line indicate sgp30 CO2 level

if both sensors are present: - first line indicates SGP30 VOC level - second line line indicates sgp30 CO2 level - third line indicates bme680 gas resistence (air quality) - fourth line indicates bme 680 humidity level

buttons - B display state, switches betweeen - full bright - low light - display off

AB reset sgp30 baseline in non volatile storage

data logging -- during measurements the minimum and mximum values for each measured value (temperature, air pressure, humidity,gas resistance, VOC, CO2) are being stored in non volatile storage those (and the last measurement results) are being shown when btn A has been pressed

Committer:
jsa1969
Date:
Wed Feb 13 18:18:25 2019 +0000
Revision:
43:f968ca84d4ed
Parent:
42:ce269f988ac8
Child:
44:67a19da5f269
seems the stray values resulting from delay problems have finally been solved

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jsa1969 0:cef60cc92da0 1 /*
jsa1969 0:cef60cc92da0 2 The MIT License (MIT)
jsa1969 0:cef60cc92da0 3
jsa1969 0:cef60cc92da0 4 Copyright (c) 2016 British Broadcasting Corporation.
jsa1969 0:cef60cc92da0 5 This software is provided by Lancaster University by arrangement with the BBC.
jsa1969 0:cef60cc92da0 6
jsa1969 0:cef60cc92da0 7 Permission is hereby granted, free of charge, to any person obtaining a
jsa1969 0:cef60cc92da0 8 copy of this software and associated documentation files (the "Software"),
jsa1969 0:cef60cc92da0 9 to deal in the Software without restriction, including without limitation
jsa1969 0:cef60cc92da0 10 the rights to use, copy, modify, merge, publish, distribute, sublicense,
jsa1969 0:cef60cc92da0 11 and/or sell copies of the Software, and to permit persons to whom the
jsa1969 0:cef60cc92da0 12 Software is furnished to do so, subject to the following conditions:
jsa1969 0:cef60cc92da0 13
jsa1969 0:cef60cc92da0 14 The above copyright notice and this permission notice shall be included in
jsa1969 0:cef60cc92da0 15 all copies or substantial portions of the Software.
jsa1969 0:cef60cc92da0 16
jsa1969 0:cef60cc92da0 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jsa1969 0:cef60cc92da0 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jsa1969 0:cef60cc92da0 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
jsa1969 0:cef60cc92da0 20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jsa1969 0:cef60cc92da0 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
jsa1969 0:cef60cc92da0 22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
jsa1969 0:cef60cc92da0 23 DEALINGS IN THE SOFTWARE.
jsa1969 0:cef60cc92da0 24 */
jsa1969 0:cef60cc92da0 25
jsa1969 0:cef60cc92da0 26 #include "MicroBit.h"
jsa1969 0:cef60cc92da0 27
jsa1969 0:cef60cc92da0 28 #include "bme680.h"
jsa1969 2:544117df8c65 29 #include "sgp30.h"
jsa1969 2:544117df8c65 30 #include "dotmath.h"
jsa1969 11:6844a5578b4f 31 #include "nvstore.h"
jsa1969 2:544117df8c65 32
jsa1969 1:f9245fb53737 33 #include "physics.h"
jsa1969 0:cef60cc92da0 34
jsa1969 33:af2dfab24ca9 35 #include "AppSpecificTestrunner.h"
jsa1969 33:af2dfab24ca9 36
jsa1969 0:cef60cc92da0 37 MicroBit uBit;
jsa1969 2:544117df8c65 38 Bme680* bme680 = NULL;
jsa1969 2:544117df8c65 39 struct bme680_field_data* bme680Data = NULL;
jsa1969 2:544117df8c65 40 Sgp30* sgp30 = NULL;
jsa1969 12:96eb06e837f4 41 I2cCallbacks* callbacks = NULL;
jsa1969 43:f968ca84d4ed 42 //I2cCallbacks* sgp30Callbacks = NULL;
jsa1969 12:96eb06e837f4 43 NvStore* nvStore = NULL;
jsa1969 12:96eb06e837f4 44
jsa1969 12:96eb06e837f4 45 bool cancelMeasureLoops = false;
jsa1969 12:96eb06e837f4 46 int runningLoops = 0;
jsa1969 20:2f11b93f4cbf 47 int displayState = 0;
jsa1969 0:cef60cc92da0 48
jsa1969 12:96eb06e837f4 49 void waitForLooppsToFinish() {
jsa1969 12:96eb06e837f4 50 cancelMeasureLoops=true;
jsa1969 12:96eb06e837f4 51 while (runningLoops>0) {
jsa1969 12:96eb06e837f4 52 uBit.sleep(10);
jsa1969 12:96eb06e837f4 53 }
jsa1969 12:96eb06e837f4 54 cancelMeasureLoops = false;
jsa1969 12:96eb06e837f4 55 }
jsa1969 0:cef60cc92da0 56
jsa1969 11:6844a5578b4f 57 void displayPixels(int ystart, int pixels, int maxpixels) {
jsa1969 11:6844a5578b4f 58 int y = ystart;
jsa1969 11:6844a5578b4f 59 for (int i=0; i+((y-ystart)*5)<maxpixels; ++i) {
jsa1969 11:6844a5578b4f 60 if (i==5) {
jsa1969 11:6844a5578b4f 61 ++y;
jsa1969 11:6844a5578b4f 62 i=0;
jsa1969 11:6844a5578b4f 63 }
jsa1969 11:6844a5578b4f 64 int pixelsused = i+((y-ystart)*5);
jsa1969 11:6844a5578b4f 65 uBit.display.image.setPixelValue(i, y, pixelsused<pixels? 255 : 0);
jsa1969 10:8e6b71a46871 66 }
jsa1969 10:8e6b71a46871 67 }
jsa1969 10:8e6b71a46871 68
jsa1969 1:f9245fb53737 69 int measureBme680(){
jsa1969 38:0f29a0ea64ca 70 int result = BME680_E_DEV_NOT_FOUND;
jsa1969 1:f9245fb53737 71 if (bme680!=NULL && bme680Data!=NULL) {
jsa1969 38:0f29a0ea64ca 72 result = bme680->measure(
jsa1969 1:f9245fb53737 73 bme680Data,
jsa1969 2:544117df8c65 74 bme680Data->temperature==0 ?
jsa1969 2:544117df8c65 75 uBit.thermometer.getTemperature()
jsa1969 2:544117df8c65 76 :bme680Data->temperature,
jsa1969 38:0f29a0ea64ca 77 2000, 350);
jsa1969 1:f9245fb53737 78 }
jsa1969 38:0f29a0ea64ca 79 return result;
jsa1969 0:cef60cc92da0 80 }
jsa1969 0:cef60cc92da0 81
jsa1969 11:6844a5578b4f 82 void measureAndDisplayBme680() {
jsa1969 11:6844a5578b4f 83 if (bme680!=NULL) {
jsa1969 11:6844a5578b4f 84 uBit.display.image.setPixelValue(4, 4, 255);
jsa1969 11:6844a5578b4f 85 if (measureBme680()==MICROBIT_OK) {
jsa1969 27:cb75a0c5c52a 86 nvStore->updateGas(bme680Data->gas_resistance, bme680Data->humidity);
jsa1969 17:a2c4dd192146 87 nvStore->updateTemp(bme680Data->temperature);
jsa1969 17:a2c4dd192146 88 nvStore->updatePress(bme680Data->pressure);
jsa1969 17:a2c4dd192146 89 nvStore->updateHumidity(bme680Data->humidity);
jsa1969 17:a2c4dd192146 90
jsa1969 14:71060505061e 91 uBit.display.image.setPixelValue(0, 4, 255);
jsa1969 11:6844a5578b4f 92 uBit.display.image.setPixelValue(4, 4, 0);
jsa1969 11:6844a5578b4f 93 int bmeY = sgp30!=NULL ? 2 : 0;
jsa1969 11:6844a5578b4f 94 int bmeMaxPixels = sgp30!=NULL ? 5 : 15;
jsa1969 27:cb75a0c5c52a 95 displayPixels(bmeY, DotMath::pixels(bme680Data->gas_resistance, nvStore->getGasMax(bme680Data->humidity), bmeMaxPixels),
jsa1969 11:6844a5578b4f 96 bmeMaxPixels);
jsa1969 11:6844a5578b4f 97 displayPixels(3, 5*bme680Data->humidity/100000, 5);
jsa1969 43:f968ca84d4ed 98 uBit.display.image.setPixelValue(2, 4, nvStore->strayData() ? 255 : 0);
jsa1969 14:71060505061e 99 } else {
jsa1969 14:71060505061e 100 uBit.display.image.setPixelValue(0, 4, 0);
jsa1969 2:544117df8c65 101 }
jsa1969 12:96eb06e837f4 102 uBit.display.image.setPixelValue(4, 4, 0);
jsa1969 11:6844a5578b4f 103 }
jsa1969 11:6844a5578b4f 104 }
jsa1969 11:6844a5578b4f 105
jsa1969 11:6844a5578b4f 106 void measureAndDisplaySgp30() {
jsa1969 11:6844a5578b4f 107 if (sgp30!=NULL) {
jsa1969 11:6844a5578b4f 108 int sgpMaxPixels = 10;
jsa1969 11:6844a5578b4f 109 int secondLineStart = 2;
jsa1969 11:6844a5578b4f 110 if (bme680!=NULL) {
jsa1969 11:6844a5578b4f 111 sgpMaxPixels = 5;
jsa1969 11:6844a5578b4f 112 secondLineStart = 1;
jsa1969 11:6844a5578b4f 113 uBit.display.image.setPixelValue(2, 4, 255);
jsa1969 11:6844a5578b4f 114 if (sgp30->setHumidity(bme680Data->humidity, bme680Data->temperature)) {
jsa1969 11:6844a5578b4f 115 uBit.display.image.setPixelValue(2, 4, 0);
jsa1969 11:6844a5578b4f 116 }
jsa1969 11:6844a5578b4f 117 uBit.sleep(10);
jsa1969 11:6844a5578b4f 118 }
jsa1969 11:6844a5578b4f 119 uBit.display.image.setPixelValue(3, 4, 255);
jsa1969 38:0f29a0ea64ca 120 bool measureOK = sgp30->IAQmeasure();
jsa1969 38:0f29a0ea64ca 121 if (measureOK) {
jsa1969 13:996026828be7 122 uBit.display.image.setPixelValue(1, 4, 255);
jsa1969 11:6844a5578b4f 123 uBit.display.image.setPixelValue(3, 4, 0);
jsa1969 18:c4ac93e01027 124
jsa1969 18:c4ac93e01027 125 nvStore->updateVoc(sgp30->TVOC);
jsa1969 18:c4ac93e01027 126 nvStore->updateCo(sgp30->eCO2);
jsa1969 18:c4ac93e01027 127
jsa1969 12:96eb06e837f4 128 int co2Dots = min (5, sgp30->eCO2 /1500);
jsa1969 11:6844a5578b4f 129 displayPixels(0, 5 - DotMath::pixels(sgp30->TVOC, 20000, sgpMaxPixels), sgpMaxPixels);
jsa1969 11:6844a5578b4f 130 displayPixels(secondLineStart, co2Dots, sgpMaxPixels);
jsa1969 13:996026828be7 131 } else {
jsa1969 13:996026828be7 132 uBit.display.image.setPixelValue(1, 4, 0);
jsa1969 11:6844a5578b4f 133 }
jsa1969 2:544117df8c65 134 }
jsa1969 2:544117df8c65 135 }
jsa1969 2:544117df8c65 136
jsa1969 12:96eb06e837f4 137 void bmeMeasureLoop() {
jsa1969 12:96eb06e837f4 138 if (bme680!=NULL) {
jsa1969 12:96eb06e837f4 139 ++runningLoops;
jsa1969 12:96eb06e837f4 140 while (!cancelMeasureLoops){
jsa1969 11:6844a5578b4f 141 measureAndDisplayBme680();
jsa1969 13:996026828be7 142 uBit.sleep(500);
jsa1969 12:96eb06e837f4 143 }
jsa1969 12:96eb06e837f4 144 --runningLoops;
jsa1969 12:96eb06e837f4 145 }
jsa1969 24:07a1d2e6914e 146 release_fiber();
jsa1969 12:96eb06e837f4 147 }
jsa1969 12:96eb06e837f4 148
jsa1969 12:96eb06e837f4 149 void sgpMeasureLoop() {
jsa1969 12:96eb06e837f4 150 if (sgp30!=NULL) {
jsa1969 12:96eb06e837f4 151 ++runningLoops;
jsa1969 12:96eb06e837f4 152 while (!cancelMeasureLoops){
jsa1969 11:6844a5578b4f 153 measureAndDisplaySgp30();
jsa1969 12:96eb06e837f4 154 uBit.sleep(950);
jsa1969 2:544117df8c65 155 }
jsa1969 12:96eb06e837f4 156 --runningLoops;
jsa1969 2:544117df8c65 157 }
jsa1969 24:07a1d2e6914e 158 release_fiber();
jsa1969 12:96eb06e837f4 159 }
jsa1969 12:96eb06e837f4 160
jsa1969 34:069c4f6d5b2c 161 void startMeasureLoops() {
jsa1969 12:96eb06e837f4 162 if (runningLoops>0) {
jsa1969 12:96eb06e837f4 163 uBit.display.scroll("already running");
jsa1969 12:96eb06e837f4 164 return;
jsa1969 12:96eb06e837f4 165 }
jsa1969 14:71060505061e 166 create_fiber(sgpMeasureLoop);
jsa1969 12:96eb06e837f4 167 create_fiber(bmeMeasureLoop);
jsa1969 2:544117df8c65 168 }
jsa1969 2:544117df8c65 169
jsa1969 11:6844a5578b4f 170 void init680(){
jsa1969 9:5150afa50eb6 171 if (bme680!=NULL){
jsa1969 9:5150afa50eb6 172 delete bme680;
jsa1969 9:5150afa50eb6 173 }
jsa1969 10:8e6b71a46871 174
jsa1969 27:cb75a0c5c52a 175 uint32_t gasMax = nvStore->getGasMax(0);
jsa1969 11:6844a5578b4f 176 if (gasMax>0) {
jsa1969 11:6844a5578b4f 177 uBit.display.scroll((int)gasMax);
jsa1969 11:6844a5578b4f 178 }
jsa1969 10:8e6b71a46871 179
jsa1969 14:71060505061e 180 bme680 = new Bme680(callbacks);
jsa1969 9:5150afa50eb6 181 int code = bme680->init();
jsa1969 9:5150afa50eb6 182 if (code == MICROBIT_OK){
jsa1969 9:5150afa50eb6 183 if (bme680Data==NULL) {
jsa1969 9:5150afa50eb6 184 bme680Data = new struct bme680_field_data;
jsa1969 9:5150afa50eb6 185 }
jsa1969 9:5150afa50eb6 186 code = bme680->measure(
jsa1969 9:5150afa50eb6 187 bme680Data,
jsa1969 9:5150afa50eb6 188 uBit.thermometer.getTemperature(),
jsa1969 9:5150afa50eb6 189 100, 100);
jsa1969 9:5150afa50eb6 190 }
jsa1969 9:5150afa50eb6 191 if (code != MICROBIT_OK){
jsa1969 9:5150afa50eb6 192 delete bme680;
jsa1969 9:5150afa50eb6 193 bme680 = NULL;
jsa1969 9:5150afa50eb6 194 delete bme680Data;
jsa1969 9:5150afa50eb6 195 bme680Data = NULL;
jsa1969 9:5150afa50eb6 196 uBit.display.scroll(code);
jsa1969 9:5150afa50eb6 197 } else {
jsa1969 9:5150afa50eb6 198 uBit.display.image.setPixelValue(0, 4, 255);
jsa1969 9:5150afa50eb6 199 }
jsa1969 11:6844a5578b4f 200 }
jsa1969 9:5150afa50eb6 201
jsa1969 11:6844a5578b4f 202 void initSgp30(){
jsa1969 9:5150afa50eb6 203 if (sgp30!=NULL){
jsa1969 9:5150afa50eb6 204 delete sgp30;
jsa1969 9:5150afa50eb6 205 }
jsa1969 43:f968ca84d4ed 206 sgp30 = new Sgp30(callbacks);
jsa1969 9:5150afa50eb6 207 if (sgp30->test() && sgp30->begin()) {
jsa1969 9:5150afa50eb6 208 uBit.display.image.setPixelValue(1, 4, 255);
jsa1969 9:5150afa50eb6 209 } else {
jsa1969 9:5150afa50eb6 210 delete sgp30;
jsa1969 43:f968ca84d4ed 211 //if (sgp30Callbacks != callbacks) delete sgp30Callbacks;
jsa1969 9:5150afa50eb6 212 sgp30 = NULL;
jsa1969 43:f968ca84d4ed 213 //sgp30Callbacks = NULL;
jsa1969 40:a67a880cb538 214 }
jsa1969 40:a67a880cb538 215 }
jsa1969 11:6844a5578b4f 216
jsa1969 11:6844a5578b4f 217 void initSensors() {
jsa1969 12:96eb06e837f4 218 waitForLooppsToFinish();
jsa1969 11:6844a5578b4f 219 init680();
jsa1969 11:6844a5578b4f 220 initSgp30();
jsa1969 9:5150afa50eb6 221 }
jsa1969 9:5150afa50eb6 222
jsa1969 12:96eb06e837f4 223 void displayValuesTxt() {
jsa1969 12:96eb06e837f4 224 waitForLooppsToFinish();
jsa1969 8:1bdb50e03d39 225 if (bme680Data!=NULL) {
jsa1969 8:1bdb50e03d39 226 uBit.display.scroll("g");
jsa1969 39:efe22f143e47 227 const int currentGas = (int)bme680Data->gas_resistance;
jsa1969 39:efe22f143e47 228 uBit.display.scroll(currentGas);
jsa1969 8:1bdb50e03d39 229 uBit.display.scroll("+");
jsa1969 38:0f29a0ea64ca 230 const int highGas = (int)nvStore->getGasMax(bme680Data->humidity);
jsa1969 38:0f29a0ea64ca 231 uBit.display.scroll(highGas);
jsa1969 39:efe22f143e47 232 if (highGas < currentGas) {
jsa1969 39:efe22f143e47 233 for (int i=0; i<NvStore::AVERAGE_BUFFER_SIZE; ++i) {
jsa1969 38:0f29a0ea64ca 234 uBit.display.scroll(":");
jsa1969 38:0f29a0ea64ca 235 uBit.display.scroll((int)nvStore->debugInfo()[i]);
jsa1969 38:0f29a0ea64ca 236 }
jsa1969 38:0f29a0ea64ca 237 }
jsa1969 14:71060505061e 238 uBit.display.scroll("-");
jsa1969 14:71060505061e 239 uBit.display.scroll((int)nvStore->getGasMin());
jsa1969 17:a2c4dd192146 240 uBit.display.scroll("t");
jsa1969 17:a2c4dd192146 241 uBit.display.scroll((int)bme680Data->temperature);
jsa1969 17:a2c4dd192146 242 uBit.display.scroll("+");
jsa1969 17:a2c4dd192146 243 uBit.display.scroll((int)nvStore->getTempMax());
jsa1969 17:a2c4dd192146 244 uBit.display.scroll("-");
jsa1969 17:a2c4dd192146 245 uBit.display.scroll((int)nvStore->getTempMin());
jsa1969 17:a2c4dd192146 246 uBit.display.scroll("p");
jsa1969 17:a2c4dd192146 247 uBit.display.scroll((int)bme680Data->pressure);
jsa1969 17:a2c4dd192146 248 uBit.display.scroll("+");
jsa1969 17:a2c4dd192146 249 uBit.display.scroll((int)nvStore->getPressMax());
jsa1969 17:a2c4dd192146 250 uBit.display.scroll("-");
jsa1969 17:a2c4dd192146 251 uBit.display.scroll((int)nvStore->getPressMin());
jsa1969 17:a2c4dd192146 252 uBit.display.scroll("h");
jsa1969 17:a2c4dd192146 253 uBit.display.scroll((int)bme680Data->humidity);
jsa1969 17:a2c4dd192146 254 uBit.display.scroll("+");
jsa1969 17:a2c4dd192146 255 uBit.display.scroll((int)nvStore->getHumMax());
jsa1969 17:a2c4dd192146 256 uBit.display.scroll("-");
jsa1969 17:a2c4dd192146 257 uBit.display.scroll((int)nvStore->getHumMin());
jsa1969 8:1bdb50e03d39 258 }
jsa1969 17:a2c4dd192146 259
jsa1969 8:1bdb50e03d39 260 if (sgp30!=NULL) {
jsa1969 8:1bdb50e03d39 261 uBit.display.scroll("v");
jsa1969 8:1bdb50e03d39 262 uBit.display.scroll((int)sgp30->TVOC);
jsa1969 18:c4ac93e01027 263 uBit.display.scroll("+");
jsa1969 18:c4ac93e01027 264 uBit.display.scroll((int)nvStore->getVocMax());
jsa1969 8:1bdb50e03d39 265 uBit.display.scroll("c");
jsa1969 8:1bdb50e03d39 266 uBit.display.scroll((int)sgp30->eCO2);
jsa1969 18:c4ac93e01027 267 uBit.display.scroll("+");
jsa1969 18:c4ac93e01027 268 uBit.display.scroll((int)nvStore->getCoMax());
jsa1969 8:1bdb50e03d39 269 }
jsa1969 0:cef60cc92da0 270 }
jsa1969 0:cef60cc92da0 271
jsa1969 12:96eb06e837f4 272 void onButtonA(MicroBitEvent evt)
jsa1969 12:96eb06e837f4 273 {
jsa1969 12:96eb06e837f4 274 if (runningLoops>0) {
jsa1969 12:96eb06e837f4 275 displayValuesTxt();
jsa1969 12:96eb06e837f4 276 } else {
jsa1969 34:069c4f6d5b2c 277 startMeasureLoops();
jsa1969 12:96eb06e837f4 278 }
jsa1969 12:96eb06e837f4 279 }
jsa1969 12:96eb06e837f4 280
jsa1969 12:96eb06e837f4 281 void onButtonB(MicroBitEvent evt)
jsa1969 12:96eb06e837f4 282 {
jsa1969 20:2f11b93f4cbf 283 //initSensors();
jsa1969 20:2f11b93f4cbf 284 switch (++displayState) {
jsa1969 20:2f11b93f4cbf 285 case 1:
jsa1969 20:2f11b93f4cbf 286 uBit.display.setBrightness(5);
jsa1969 20:2f11b93f4cbf 287 break;
jsa1969 20:2f11b93f4cbf 288 case 2:
jsa1969 20:2f11b93f4cbf 289 uBit.display.disable();
jsa1969 20:2f11b93f4cbf 290 break;
jsa1969 20:2f11b93f4cbf 291 default:
jsa1969 20:2f11b93f4cbf 292 uBit.display.setBrightness(255);
jsa1969 20:2f11b93f4cbf 293 uBit.display.enable();
jsa1969 20:2f11b93f4cbf 294 displayState = 0;
jsa1969 20:2f11b93f4cbf 295 }
jsa1969 12:96eb06e837f4 296 }
jsa1969 12:96eb06e837f4 297
jsa1969 9:5150afa50eb6 298 void onButtonAB(MicroBitEvent evt)
jsa1969 9:5150afa50eb6 299 {
jsa1969 19:52e19461e867 300 waitForLooppsToFinish();
jsa1969 12:96eb06e837f4 301 nvStore->resetNvStore();
jsa1969 19:52e19461e867 302 uBit.display.scroll("clear");
jsa1969 9:5150afa50eb6 303 }
jsa1969 9:5150afa50eb6 304
jsa1969 34:069c4f6d5b2c 305 const char* runSofwareModuleTests() {
jsa1969 34:069c4f6d5b2c 306 // heap we've got planty, stack is rare
jsa1969 33:af2dfab24ca9 307 AppSpecificTestrunner* runner = new AppSpecificTestrunner();
jsa1969 33:af2dfab24ca9 308 const char* result = runner->runAll();
jsa1969 33:af2dfab24ca9 309 delete runner;
jsa1969 33:af2dfab24ca9 310 return result;
jsa1969 33:af2dfab24ca9 311 }
jsa1969 33:af2dfab24ca9 312
jsa1969 0:cef60cc92da0 313 int main()
jsa1969 0:cef60cc92da0 314 {
jsa1969 0:cef60cc92da0 315 uBit.init();
jsa1969 0:cef60cc92da0 316
jsa1969 0:cef60cc92da0 317 uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA);
jsa1969 0:cef60cc92da0 318 uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB);
jsa1969 9:5150afa50eb6 319 uBit.messageBus.listen(MICROBIT_ID_BUTTON_AB, MICROBIT_BUTTON_EVT_CLICK, onButtonAB);
jsa1969 2:544117df8c65 320
jsa1969 40:a67a880cb538 321 callbacks = new I2cCallbacks(&uBit, NULL);
jsa1969 43:f968ca84d4ed 322 //sgp30Callbacks = callbacks;////new MicroBitI2C(MICROBIT_PIN_P0,MICROBIT_PIN_P1));
jsa1969 12:96eb06e837f4 323 nvStore = new NvStore(&uBit);
jsa1969 33:af2dfab24ca9 324
jsa1969 34:069c4f6d5b2c 325 const char* testResults = runSofwareModuleTests();
jsa1969 33:af2dfab24ca9 326 if (! Testrunner::messageOK(testResults)) {
jsa1969 33:af2dfab24ca9 327 uBit.display.scroll(testResults);
jsa1969 33:af2dfab24ca9 328 return -1;
jsa1969 33:af2dfab24ca9 329 }
jsa1969 33:af2dfab24ca9 330
jsa1969 34:069c4f6d5b2c 331 // includes hardware tests
jsa1969 9:5150afa50eb6 332 initSensors();
jsa1969 9:5150afa50eb6 333
jsa1969 34:069c4f6d5b2c 334 startMeasureLoops();
jsa1969 2:544117df8c65 335
jsa1969 0:cef60cc92da0 336 release_fiber();
jsa1969 0:cef60cc92da0 337 }
jsa1969 0:cef60cc92da0 338