Skip to content

Commit 30f854f

Browse files
committed
Merge branch '0.8.x'
2 parents cffa645 + 84a4200 commit 30f854f

File tree

6 files changed

+425
-3
lines changed

6 files changed

+425
-3
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Fixed burning bootloader issue with MacOS
66
- Added gpstest_swuart example sketch
77
- Added indicate API for BLECharacteristic
8+
- Added custom_htm as usage example for indicate API.
89
- BLEClientCharacteristic
910
- Added setIndicateCallback(), issue #113
1011
- Added useAdaCallback option to setNotifyCallback(), setIndicateCallback()

libraries/Bluefruit52Lib/examples/Peripheral/custom_hrm/custom_hrm.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void setupHRM(void)
121121

122122
// Configure the Heart Rate Measurement characteristic
123123
// See: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.heart_rate_measurement.xml
124-
// Permission = Notify
124+
// Properties = Notify
125125
// Min Len = 1
126126
// Max Len = 8
127127
// B0 = UINT8 - Flag (MANDATORY)
@@ -144,7 +144,7 @@ void setupHRM(void)
144144

145145
// Configure the Body Sensor Location characteristic
146146
// See: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.body_sensor_location.xml
147-
// Permission = Read
147+
// Properties = Read
148148
// Min Len = 1
149149
// Max Len = 1
150150
// B0 = UINT8 - Body Sensor Location
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**************************************************************************/
2+
/*!
3+
@file IEEE11073float.h
4+
*/
5+
/**************************************************************************/
6+
7+
/**
8+
* \file bytelib.c
9+
* \brief Byte manipulation module implementation.
10+
* Copyright (C) 2010 Signove Tecnologia Corporation.
11+
* All rights reserved.
12+
* Contact: Signove Tecnologia Corporation ([email protected])
13+
*
14+
* $LICENSE_TEXT:BEGIN$
15+
* This library is free software; you can redistribute it and/or
16+
* modify it under the terms of the GNU Lesser General Public
17+
* License as published by the Free Software Foundation and appearing
18+
* in the file LICENSE included in the packaging of this file; either
19+
* version 2.1 of the License, or (at your option) any later version.
20+
*
21+
* This library is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24+
* Lesser General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Lesser General Public
27+
* License along with this library; if not, write to the Free Software
28+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29+
* $LICENSE_TEXT:END$
30+
*
31+
* \author Walter Guerra, Mateus Lima
32+
* \date Jun 14, 2010
33+
*/
34+
35+
#include <Arduino.h>
36+
#include "IEEE11073float.h"
37+
38+
uint32_t float2IEEE11073(double data, uint8_t output[4])
39+
{
40+
uint32_t result = MDER_NaN;
41+
42+
43+
if (isnan(data)) {
44+
goto finally;
45+
}/* else if (data > MDER_FLOAT_MAX) {
46+
result = MDER_POSITIVE_INFINITY;
47+
goto finally;
48+
} else if (data < MDER_FLOAT_MIN) {
49+
result = MDER_NEGATIVE_INFINITY;
50+
goto finally;
51+
} else if (data >= -MDER_FLOAT_EPSILON &&
52+
data <= MDER_FLOAT_EPSILON) {
53+
result = 0;
54+
goto finally;
55+
}*/
56+
57+
double sgn; sgn = data > 0 ? +1 : -1;
58+
double mantissa; mantissa = fabs(data);
59+
int32_t exponent; exponent = 0; // Note: 10**x exponent, not 2**x
60+
61+
// scale up if number is too big
62+
while (mantissa > MDER_FLOAT_MANTISSA_MAX) {
63+
mantissa /= 10.0;
64+
++exponent;
65+
if (exponent > MDER_FLOAT_EXPONENT_MAX) {
66+
// argh, should not happen
67+
if (sgn > 0) {
68+
result = MDER_POSITIVE_INFINITY;
69+
} else {
70+
result = MDER_NEGATIVE_INFINITY;
71+
}
72+
goto finally;
73+
}
74+
}
75+
76+
// scale down if number is too small
77+
while (mantissa < 1) {
78+
mantissa *= 10;
79+
--exponent;
80+
if (exponent < MDER_FLOAT_EXPONENT_MIN) {
81+
// argh, should not happen
82+
result = 0;
83+
goto finally;
84+
}
85+
}
86+
87+
// scale down if number needs more precision
88+
double smantissa; smantissa = round(mantissa * MDER_FLOAT_PRECISION);
89+
double rmantissa; rmantissa = round(mantissa) * MDER_FLOAT_PRECISION;
90+
double mdiff; mdiff = abs(smantissa - rmantissa);
91+
while (mdiff > 0.5 && exponent > MDER_FLOAT_EXPONENT_MIN &&
92+
(mantissa * 10) <= MDER_FLOAT_MANTISSA_MAX) {
93+
mantissa *= 10;
94+
--exponent;
95+
smantissa = round(mantissa * MDER_FLOAT_PRECISION);
96+
rmantissa = round(mantissa) * MDER_FLOAT_PRECISION;
97+
mdiff = abs(smantissa - rmantissa);
98+
}
99+
100+
uint32_t int_mantissa; int_mantissa = (int) round(sgn * mantissa);
101+
result = (exponent << 24) | (int_mantissa & 0xFFFFFF);
102+
103+
finally:
104+
if ( output ) memcpy(output, &result, 4);
105+
return result;
106+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**************************************************************************/
2+
/*!
3+
@file IEEE11073float.h
4+
*/
5+
/**************************************************************************/
6+
7+
/**
8+
* \file bytelib.c
9+
* \brief Byte manipulation module implementation.
10+
* Copyright (C) 2010 Signove Tecnologia Corporation.
11+
* All rights reserved.
12+
* Contact: Signove Tecnologia Corporation ([email protected])
13+
*
14+
* $LICENSE_TEXT:BEGIN$
15+
* This library is free software; you can redistribute it and/or
16+
* modify it under the terms of the GNU Lesser General Public
17+
* License as published by the Free Software Foundation and appearing
18+
* in the file LICENSE included in the packaging of this file; either
19+
* version 2.1 of the License, or (at your option) any later version.
20+
*
21+
* This library is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24+
* Lesser General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Lesser General Public
27+
* License along with this library; if not, write to the Free Software
28+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29+
* $LICENSE_TEXT:END$
30+
*
31+
* \author Walter Guerra, Mateus Lima
32+
* \date Jun 14, 2010
33+
*/
34+
35+
#ifndef _IEEE11073FLOAT_H_
36+
#define _IEEE11073FLOAT_H_
37+
38+
#include <stdint.h>
39+
40+
typedef enum {
41+
MDER_POSITIVE_INFINITY = 0x007FFFFE,
42+
MDER_NaN = 0x007FFFFF,
43+
MDER_NRes = 0x00800000,
44+
MDER_RESERVED_VALUE = 0x00800001,
45+
MDER_NEGATIVE_INFINITY = 0x00800002
46+
} ReservedFloatValues;
47+
static const int32_t FIRST_RESERVED_VALUE = MDER_POSITIVE_INFINITY;
48+
49+
// (2 ** 23 - 3)
50+
#define MDER_FLOAT_MANTISSA_MAX 0x007FFFFD
51+
// 2 ** 7 - 1
52+
#define MDER_FLOAT_EXPONENT_MAX 127
53+
#define MDER_FLOAT_EXPONENT_MIN -128
54+
// (2 ** 23 - 3) * 10 ** 127
55+
#define MDER_FLOAT_MAX 8.388604999999999e+133
56+
// -(2 ** 23 - 3) * 10 ** 127
57+
#define MDER_FLOAT_MIN (-MDER_FLOAT_MAX)
58+
// 10 ** -128
59+
#define MDER_FLOAT_EPSILON 1e-128
60+
// 10 ** upper(23 * log(2) / log(10))
61+
// precision for a number 1.0000xxx
62+
#define MDER_FLOAT_PRECISION 10000000
63+
64+
typedef enum {
65+
MDER_S_POSITIVE_INFINITY = 0x07FE,
66+
MDER_S_NaN = 0x07FF,
67+
MDER_S_NRes = 0x0800,
68+
MDER_S_RESERVED_VALUE = 0x0801,
69+
MDER_S_NEGATIVE_INFINITY = 0x0802
70+
} ReservedSFloatValues;
71+
static const uint32_t FIRST_S_RESERVED_VALUE = MDER_S_POSITIVE_INFINITY;
72+
73+
// (2 ** 11 - 3)
74+
#define MDER_SFLOAT_MANTISSA_MAX 0x07FD
75+
// 2 ** 3 - 1
76+
#define MDER_SFLOAT_EXPONENT_MAX 7
77+
#define MDER_SFLOAT_EXPONENT_MIN -8
78+
// (2 ** 11 - 3) * 10 ** 7
79+
#define MDER_SFLOAT_MAX 20450000000.0
80+
// -(2 ** 11 - 3) * 10 ** 7
81+
#define MDER_SFLOAT_MIN (-MDER_SFLOAT_MAX)
82+
// 10 ** -8
83+
#define MDER_SFLOAT_EPSILON 1e-8
84+
// 10 ** upper(11 * log(2) / log(10))
85+
#define MDER_SFLOAT_PRECISION 10000
86+
87+
uint32_t float2IEEE11073(double data, uint8_t output[4]);
88+
89+
#endif /* _IEEE11073FLOAT_H_ */

0 commit comments

Comments
 (0)