void loop() { // listen for BLE peripherals to connect: BLECentral central = blePeripheral.central(); // if a central is connected to peripheral: if (central) { Serial.print("Connected to central: "); // print the central's MAC address: Serial.println(central.address()); // turn on the LED to indicate the connection: digitalWrite(13, HIGH); // check the heart rate measurement every 200ms // as long as the central is still connected: while (central.connected()) { long currentMillis = millis(); // if 200ms have passed, check the heart rate measurement: if (currentMillis - previousMillis >= 200) { previousMillis = currentMillis; updateHeartRate(); } } // when the central disconnects, turn off the LED: digitalWrite(13, LOW); Serial.print("Disconnected from central: "); Serial.println(central.address()); } }
static uint32_t updateBaseData(uint8_t datatype, uint32_t value) { if (datatype >= SPORTS_DATA_MAX) return 0; // if (datatype != 0) // printf("updateBaseData(%u, %lu)\n", datatype, value); uint32_t grids_mask = 0; switch (datatype) { case SPORTS_TIME: grids_mask |= (shiftval << GRID_WORKOUT); base_data[datatype] = value; //the raw value must be updated at last break; case SPORTS_DISTANCE: updateDistance(value, &grids_mask); grids_mask |= (shiftval << GRID_DISTANCE); base_data[SPORTS_TIME_LAST_GPS] = workout_time; base_data[datatype] += value; //the raw value must be updated at last break; case SPORTS_HEARTRATE: updateHeartRate(value, &grids_mask); grids_mask |= (shiftval << GRID_HEARTRATE); base_data[datatype] = value; //the raw value must be updated at last break; case SPORTS_SPEED: if (value != 0xffffffff) { updateSpeed(value, &grids_mask); grids_mask |= (shiftval << GRID_SPEED); base_data[SPORTS_TIME_LAST_GPS] = workout_time; base_data[datatype] = value; //the raw value must be updated at last } break; case SPORTS_ALT: if (value != 0xffffffff) { updateAlt(value, &grids_mask); grids_mask |= (shiftval << GRID_ALTITUTE); base_data[SPORTS_TIME_LAST_GPS] = workout_time; base_data[datatype] = value; //the raw value must be updated at last } break; case SPORTS_STEPS: if (base_data[datatype] == 0) { base_data[SPORTS_PED_STEPS_START] = value; base_data[datatype] = 1; //the raw value must be updated at last } else { base_data[datatype] = value - base_data[SPORTS_PED_STEPS_START]; //the raw value must be updated at last } grids_mask |= (shiftval << GRID_STEPS); break; case SPORTS_PED_SPEED: updatePedSpeed(value, &grids_mask); base_data[datatype] = value; //the raw value must be updated at last break; case SPORTS_PED_DISTANCE: updatePedDist(value, &grids_mask); base_data[datatype] = value; //the raw value must be updated at last break; case SPORTS_PED_CALORIES: if (base_data[datatype] != 0) { if (value > base_data[datatype]) base_data[SPORTS_CALS] += (value - base_data[datatype]); else base_data[SPORTS_CALS] += value; base_data[datatype] = value; } grids_mask |= (shiftval << GRID_CALS); break; default: base_data[datatype] = value; //the raw value must be updated at last break; } return grids_mask; }