From d25d0cc2430bac06c2ec4360fa9d048f8dcf4871 Mon Sep 17 00:00:00 2001 From: TheSomeMan Date: Mon, 15 Jul 2024 13:50:38 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20ruuvi/ru?= =?UTF-8?q?uvi.endpoints.c@360f4d73416f014d79aa9b3d8def0062793fa6fc=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruuvi__endpoint__3_8c_source.html | 264 +++++++++++++++--------------- ruuvi__endpoints_8c_source.html | 2 +- 2 files changed, 132 insertions(+), 134 deletions(-) diff --git a/ruuvi__endpoint__3_8c_source.html b/ruuvi__endpoint__3_8c_source.html index 505afed..c7e7cdf 100644 --- a/ruuvi__endpoint__3_8c_source.html +++ b/ruuvi__endpoint__3_8c_source.html @@ -97,11 +97,11 @@
9 #define RE_3_ENCODE_INVALID_PRECISION 0.00001f
10 #define RE_3_ENCODE_ACC_CONVERT_RATIO 1000
11 #define RE_3_ENCODE_HUMIDITY_CONVERT_RATIO 2
-
12 #define RE_3_ENCODE_HUMIDITY_CONVERT_OFFSET 0.5
+
12 #define RE_3_ENCODE_HUMIDITY_CONVERT_OFFSET 0.5f
13 #define RE_3_ENCODE_PRESSURE_INIT_OFFSET 50000
14 #define RE_3_ENCODE_BATTERY_CONVERT_RATIO 1000
15 #define RE_3_ENCODE_TEMP_CONVERT_RATIO 100
-
16 #define RE_3_ENCODE_TEMP_CONVERT_CAP 127.99
+
16 #define RE_3_ENCODE_TEMP_CONVERT_CAP 127.99f
17 
18 #define RE_3_BYTE_SIGN_OFFSET 7
19 #define RE_3_BYTE_OFFSET 8
@@ -145,139 +145,137 @@
57 {
58  if (!isnan (re_3_encode_check_invalid (acceleration, invalid)))
59  {
-
60  int16_t decimal = (int16_t) round ( (acceleration *
-
61  RE_3_ENCODE_ACC_CONVERT_RATIO));
-
62  buffer[0] = ( (uint16_t) decimal) >> RE_3_BYTE_OFFSET;
-
63  buffer[1] = ( (uint16_t) decimal) & RE_3_BYTE_MASK;
-
64  }
-
65  else
-
66  {
-
67  buffer[0] = RE_3_INVALID_DATA;
-
68  buffer[1] = RE_3_INVALID_DATA;
-
69  }
-
70 }
-
71 
-
72 static void re_3_encode_data (uint8_t * const buffer,
-
73  const re_3_data_t * data, const re_float invalid)
-
74 {
-
75  buffer[RE_3_OFFSET_HEADER] = RE_3_DESTINATION;
-
76 
-
77  // HUMIDITY
-
78  if (!isnan (re_3_encode_check_invalid (data->humidity_rh, invalid)))
-
79  {
-
80  //Humidity (one lsb is 0.5%, e.g. 128 is 64%). Round the value
-
81  buffer[RE_3_OFFSET_HUMIDITY] = (uint8_t) ( (re_float) ( (data->humidity_rh *
-
82  RE_3_ENCODE_HUMIDITY_CONVERT_RATIO) +
-
83  RE_3_ENCODE_HUMIDITY_CONVERT_OFFSET));
-
84  }
-
85  else
-
86  {
-
87  buffer[RE_3_OFFSET_HUMIDITY] = RE_3_INVALID_DATA;
-
88  }
+
60  int16_t decimal = (int16_t) roundf (acceleration * RE_3_ENCODE_ACC_CONVERT_RATIO);
+
61  buffer[0] = ( (uint16_t) decimal) >> RE_3_BYTE_OFFSET;
+
62  buffer[1] = ( (uint16_t) decimal) & RE_3_BYTE_MASK;
+
63  }
+
64  else
+
65  {
+
66  buffer[0] = RE_3_INVALID_DATA;
+
67  buffer[1] = RE_3_INVALID_DATA;
+
68  }
+
69 }
+
70 
+
71 static void re_3_encode_data (uint8_t * const buffer,
+
72  const re_3_data_t * data, const re_float invalid)
+
73 {
+
74  buffer[RE_3_OFFSET_HEADER] = RE_3_DESTINATION;
+
75 
+
76  // HUMIDITY
+
77  if (!isnan (re_3_encode_check_invalid (data->humidity_rh, invalid)))
+
78  {
+
79  //Humidity (one lsb is 0.5%, e.g. 128 is 64%). Round the value
+
80  buffer[RE_3_OFFSET_HUMIDITY] = (uint8_t) roundf (data->humidity_rh *
+
81  RE_3_ENCODE_HUMIDITY_CONVERT_RATIO);
+
82  }
+
83  else
+
84  {
+
85  buffer[RE_3_OFFSET_HUMIDITY] = RE_3_INVALID_DATA;
+
86  }
+
87 
+
88  // Temperature
89 
-
90  // Temperature
-
91 
-
92  if (!isnan (re_3_encode_check_invalid (data->temperature_c, invalid)))
-
93  {
-
94  //Temperature (MSB is sign, next 7 bits are decimal value)
-
95  re_float temperature = data->temperature_c;
-
96  uint8_t sign = 0;
-
97 
-
98  if (temperature < 0)
-
99  {
-
100  sign = 1;
-
101  }
-
102  else
-
103  {
-
104  sign = 0;
-
105  }
-
106 
-
107  // abs value
-
108  if (0 > temperature) { temperature = 0 - temperature; }
-
109 
-
110  // cap the temperature
-
111  if (RE_3_ENCODE_TEMP_CONVERT_CAP < temperature)
-
112  {
-
113  temperature = (re_float) RE_3_ENCODE_TEMP_CONVERT_CAP;
-
114  }
-
115 
-
116  buffer[RE_3_OFFSET_TEMPERATURE_DECIMAL] = (uint8_t) temperature | (uint8_t) (
-
117  sign << RE_3_BYTE_SIGN_OFFSET);
-
118  uint8_t temperature_fraction = (uint8_t) round ( (temperature - floor (
-
119  temperature)) *
-
120  RE_3_ENCODE_TEMP_CONVERT_RATIO);
-
121  buffer[RE_3_OFFSET_TEMPERATURE_FRACTION] = temperature_fraction;
-
122  }
-
123  else
-
124  {
-
125  buffer[RE_3_OFFSET_TEMPERATURE_DECIMAL] = RE_3_INVALID_DATA;
-
126  buffer[RE_3_OFFSET_TEMPERATURE_FRACTION] = RE_3_INVALID_DATA;
-
127  }
+
90  if (!isnan (re_3_encode_check_invalid (data->temperature_c, invalid)))
+
91  {
+
92  //Temperature (MSB is sign, next 7 bits are decimal value)
+
93  re_float temperature = data->temperature_c;
+
94  uint8_t sign = 0;
+
95 
+
96  if (temperature < 0)
+
97  {
+
98  sign = 1;
+
99  }
+
100  else
+
101  {
+
102  sign = 0;
+
103  }
+
104 
+
105  // abs value
+
106  if (0 > temperature) { temperature = 0 - temperature; }
+
107 
+
108  // cap the temperature
+
109  if (RE_3_ENCODE_TEMP_CONVERT_CAP < temperature)
+
110  {
+
111  temperature = RE_3_ENCODE_TEMP_CONVERT_CAP;
+
112  }
+
113 
+
114  buffer[RE_3_OFFSET_TEMPERATURE_DECIMAL] = (uint8_t) temperature | (uint8_t) (
+
115  sign << RE_3_BYTE_SIGN_OFFSET);
+
116  uint8_t temperature_fraction = (uint8_t) roundf ( (temperature - floorf (
+
117  temperature)) *
+
118  RE_3_ENCODE_TEMP_CONVERT_RATIO);
+
119  buffer[RE_3_OFFSET_TEMPERATURE_FRACTION] = temperature_fraction;
+
120  }
+
121  else
+
122  {
+
123  buffer[RE_3_OFFSET_TEMPERATURE_DECIMAL] = RE_3_INVALID_DATA;
+
124  buffer[RE_3_OFFSET_TEMPERATURE_FRACTION] = RE_3_INVALID_DATA;
+
125  }
+
126 
+
127  // Pressure
128 
-
129  // Pressure
-
130 
-
131  if (!isnan (re_3_encode_check_invalid (data->pressure_pa, invalid)))
-
132  {
-
133  uint32_t pressure = (uint32_t) data->pressure_pa;
-
134  pressure -= RE_3_ENCODE_PRESSURE_INIT_OFFSET;
-
135  buffer[RE_3_OFFSET_PRESSURE_MSB] = (uint8_t) (pressure >> RE_3_BYTE_OFFSET);
-
136  buffer[RE_3_OFFSET_PRESSURE_LSB] = (uint8_t) (pressure & RE_3_BYTE_MASK);
-
137  }
-
138  else
-
139  {
-
140  buffer[RE_3_OFFSET_PRESSURE_MSB] = RE_3_INVALID_DATA;
-
141  buffer[RE_3_OFFSET_PRESSURE_LSB] = RE_3_INVALID_DATA;
-
142  }
-
143 
-
144  // acceleration
-
145  re_3_encode_acceleration (&buffer[RE_3_OFFSET_ACCELERATIONX_MSB],
-
146  data->accelerationx_g, invalid);
-
147  re_3_encode_acceleration (&buffer[RE_3_OFFSET_ACCELERATIONY_MSB],
-
148  data->accelerationy_g, invalid);
-
149  re_3_encode_acceleration (&buffer[RE_3_OFFSET_ACCELERATIONZ_MSB],
-
150  data->accelerationz_g, invalid);
-
151  // voltage
-
152 
-
153  if (!isnan (re_3_encode_check_invalid (data->battery_v, invalid)))
-
154  {
-
155  uint32_t voltage = 0;
-
156  re_float voltage_in_mv = (data->battery_v *
-
157  RE_3_ENCODE_BATTERY_CONVERT_RATIO);
-
158 
-
159  if (voltage_in_mv > 0)
-
160  {
-
161  voltage = (uint32_t) (voltage_in_mv);
-
162  }
-
163 
-
164  buffer[RE_3_OFFSET_VOLTAGE_MSB] = (uint8_t) (voltage >> RE_3_BYTE_OFFSET);
-
165  buffer[RE_3_OFFSET_VOLTAGE_LSB] = (uint8_t) (voltage & RE_3_BYTE_MASK);
-
166  }
-
167  else
-
168  {
-
169  buffer[RE_3_OFFSET_VOLTAGE_MSB] = RE_3_INVALID_DATA;
-
170  buffer[RE_3_OFFSET_VOLTAGE_LSB] = RE_3_INVALID_DATA;
-
171  }
-
172 }
-
173 
-
174 re_status_t re_3_encode (uint8_t * const buffer,
-
175  const re_3_data_t * const data, const re_float invalid)
-
176 {
-
177  re_status_t result = RE_SUCCESS;
-
178 
-
179  if ( (NULL == buffer) ||
-
180  (NULL == data))
-
181  {
-
182  result = RE_ERROR_NULL;
-
183  }
-
184  else
-
185  {
-
186  re_3_encode_data (buffer, data, invalid);
-
187  }
-
188 
-
189  return result;
-
190 }
-
191 
-
192 #endif
+
129  if (!isnan (re_3_encode_check_invalid (data->pressure_pa, invalid)))
+
130  {
+
131  uint32_t pressure = (uint32_t) data->pressure_pa;
+
132  pressure -= RE_3_ENCODE_PRESSURE_INIT_OFFSET;
+
133  buffer[RE_3_OFFSET_PRESSURE_MSB] = (uint8_t) (pressure >> RE_3_BYTE_OFFSET);
+
134  buffer[RE_3_OFFSET_PRESSURE_LSB] = (uint8_t) (pressure & RE_3_BYTE_MASK);
+
135  }
+
136  else
+
137  {
+
138  buffer[RE_3_OFFSET_PRESSURE_MSB] = RE_3_INVALID_DATA;
+
139  buffer[RE_3_OFFSET_PRESSURE_LSB] = RE_3_INVALID_DATA;
+
140  }
+
141 
+
142  // acceleration
+
143  re_3_encode_acceleration (&buffer[RE_3_OFFSET_ACCELERATIONX_MSB],
+
144  data->accelerationx_g, invalid);
+
145  re_3_encode_acceleration (&buffer[RE_3_OFFSET_ACCELERATIONY_MSB],
+
146  data->accelerationy_g, invalid);
+
147  re_3_encode_acceleration (&buffer[RE_3_OFFSET_ACCELERATIONZ_MSB],
+
148  data->accelerationz_g, invalid);
+
149  // voltage
+
150 
+
151  if (!isnan (re_3_encode_check_invalid (data->battery_v, invalid)))
+
152  {
+
153  uint32_t voltage = 0;
+
154  re_float voltage_in_mv = (data->battery_v *
+
155  RE_3_ENCODE_BATTERY_CONVERT_RATIO);
+
156 
+
157  if (voltage_in_mv > 0)
+
158  {
+
159  voltage = (uint32_t) (voltage_in_mv);
+
160  }
+
161 
+
162  buffer[RE_3_OFFSET_VOLTAGE_MSB] = (uint8_t) (voltage >> RE_3_BYTE_OFFSET);
+
163  buffer[RE_3_OFFSET_VOLTAGE_LSB] = (uint8_t) (voltage & RE_3_BYTE_MASK);
+
164  }
+
165  else
+
166  {
+
167  buffer[RE_3_OFFSET_VOLTAGE_MSB] = RE_3_INVALID_DATA;
+
168  buffer[RE_3_OFFSET_VOLTAGE_LSB] = RE_3_INVALID_DATA;
+
169  }
+
170 }
+
171 
+
172 re_status_t re_3_encode (uint8_t * const buffer,
+
173  const re_3_data_t * const data, const re_float invalid)
+
174 {
+
175  re_status_t result = RE_SUCCESS;
+
176 
+
177  if ( (NULL == buffer) ||
+
178  (NULL == data))
+
179  {
+
180  result = RE_ERROR_NULL;
+
181  }
+
182  else
+
183  {
+
184  re_3_encode_data (buffer, data, invalid);
+
185  }
+
186 
+
187  return result;
+
188 }
+
189 
+
190 #endif
All data required for Ruuvi dataformat 3 package.
re_float temperature_c
Temperature in celcius.
re_float accelerationz_g
Acceleration along Z-axis, can be RMS over some period.
diff --git a/ruuvi__endpoints_8c_source.html b/ruuvi__endpoints_8c_source.html index 122c02e..1679f8d 100644 --- a/ruuvi__endpoints_8c_source.html +++ b/ruuvi__endpoints_8c_source.html @@ -217,7 +217,7 @@
150 static int32_t f2i (re_float value)
151 {
152  int32_t rvalue = 0x80000000;
-
153  value = (value) >= 0 ? (value) + 0.5 : (value) - 0.5;
+
153  value = (value) >= 0 ? (value) + 0.5f : (value) - 0.5f;
154 
155  if (value >= INT32_MAX)
156  {