Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API nRF51822 mbed
Fork of KS7 by
Diff: main.cpp
- Revision:
- 9:a7bd5ae66d6d
- Parent:
- 8:32be16b1eaf2
- Child:
- 10:95c1e5a218d5
--- a/main.cpp Tue Nov 24 03:46:06 2015 +0000
+++ b/main.cpp Tue Nov 24 09:57:19 2015 +0000
@@ -1,6 +1,7 @@
#include "mbed.h"
#include "io.h"
#include "BLEDevice.h"
+#include "common.h"
// BLE
#define INTERVAL_500MSEC (500UL)
@@ -14,7 +15,7 @@
#define MANUFACTURER_NAME_STRING "Hacarus" // Manufacturer Name String - shall represent the name of the manufacturer of the device.
#define MODEL_NUMBER_STRING "0001" // Model Number String - shall represent the model number that is assigned by the device vendor.
#define SERIAL_NUMBER_STRING "000780c0ffeef00d" // Serial Number String - shall represent the serial number for a particular instance of the device.
-#define FIRMWARE_REVISION_STRING "v1.00.002@rev0008" // Firmware Revision String - shall represent the firmware revision for the firmware within the device.
+#define FIRMWARE_REVISION_STRING "v1.00.002@rev0009" // Firmware Revision String - shall represent the firmware revision for the firmware within the device.
// Weight Scale Service (Original)
#define UUID_WEIGHT_SCALE_SERVICE (0x181D)
@@ -45,7 +46,8 @@
// Properties
io io;
Ticker tk;
-float weight = 0;
+uint32_t weight_data;
+float32_t weight = 0.0;
uint32_t scale = 0;
int update_counter = 0;
int push_counter = 0;
@@ -61,7 +63,7 @@
/* Weight Scale Service */
static const uint8_t UUID_HACARUS_WEIGHT_CHAR[] = {0x00, 0x00, 0x2A, 0x9D, 0x00, 0x01, 0x00, 0x01, 0x00, 'H','a', 'c', 'a', 'r','u', 's'};
-GattCharacteristic WeightMeasurement (UUID(UUID_HACARUS_WEIGHT_CHAR), (uint8_t *)&weight, sizeof(weight), sizeof(weight),
+GattCharacteristic WeightMeasurement (UUID(UUID_HACARUS_WEIGHT_CHAR), (uint8_t *)&weight_data, sizeof(weight_data), sizeof(weight_data),
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE);
static const uint8_t UUID_HACARUS_SCALE_CHAR[] = {0x00, 0x00, 0x2A, 0x9E, 0x00, 0x01, 0x00, 0x01, 0x00, 'H','a', 'c', 'a', 'r','u', 's'};
GattCharacteristic WeightScale (UUID(UUID_HACARUS_SCALE_CHAR), (uint8_t *)&scale, sizeof(scale), sizeof(scale),
@@ -109,6 +111,14 @@
return false;
}
+uint32_t quick_ieee11073_from_float(float data)
+{
+ uint8_t exponent = 0xFE; //exponent is -2
+ uint32_t mantissa = (uint32_t)(data*100);
+
+ return ( ((uint32_t)exponent) << 24) | mantissa;
+}
+
void ticker_callback()
{
switch(led_mode){
@@ -128,16 +138,17 @@
break;
case MODE_ON:
if(!check_joystick()){
- io.display_value = (uint16_t)(io.get_weight() * 9999.0); // dummy display
+ io.analog_pow(1); // turn analog power on
+ weight = io.get_weight() * 9999.0;
+ io.display_value = (uint16_t)weight; // dummy display
if(++update_counter >= 5){
- io.analog_pow(1); // turn analog power on
- weight = io.get_weight() * 9999.0;
+ weight_data = quick_ieee11073_from_float(weight);
ble.updateCharacteristicValue(WeightMeasurement.getValueAttribute().getHandle(),
- (uint8_t *)&weight,
- sizeof(weight));
- io.analog_pow(0); // turn analog power off
+ (uint8_t *)&weight_data,
+ sizeof(weight_data));
update_counter = 0;
- }
+ }
+ io.analog_pow(0); // turn analog power off
}else{
led_mode = MODE_END;
if(ble.getGapState().connected){
