Skip to content
This repository was archived by the owner on Sep 23, 2021. It is now read-only.

Commit aec57fb

Browse files
committed
Fix #158
1 parent 3c47437 commit aec57fb

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

libraries/ruuvi_sensor_formats/sensortag.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,30 @@ void encodeToRawFormat3(uint8_t* data_buffer, const ruuvi_sensor_t* data)
8282
{
8383
//serialize values into a string
8484
data_buffer[0] = SENSOR_TAG_DATA_FORMAT;
85-
data_buffer[1] = data->humidity /512;
86-
data_buffer[2] = (data->temperature)/100;
87-
data_buffer[3] = (data->temperature)%100;
85+
uint32_t humidity = data->humidity;
86+
if(data->humidity == HUMIDITY_INVALID) { humidity = 0; }
87+
data_buffer[1] = humidity / 512;
88+
int32_t temperature = data->temperature;
89+
if(data->temperature == TEMPERATURE_INVALID) { temperature = 0; }
90+
data_buffer[2] = temperature / 100;
91+
data_buffer[3] = temperature % 100;
8892
uint32_t pressure = data->pressure;
93+
if(data->pressure == PRESSURE_INVALID) { pressure = 50000<<8; }
8994
pressure = (uint16_t)((pressure >> 8) - 50000); //Scale into pa, Shift by -50000 pa as per Ruu.vi interface.
9095
data_buffer[4] = (pressure)>>8;
9196
data_buffer[5] = (pressure)&0xFF;
92-
data_buffer[6] = (data->accX)>>8;
93-
data_buffer[7] = (data->accX)&0xFF;
94-
data_buffer[8] = (data->accY)>>8;
95-
data_buffer[9] = (data->accY)&0xFF;
96-
data_buffer[10] = (data->accZ)>>8;
97-
data_buffer[11] = (data->accZ)&0xFF;
97+
int32_t accX = data->accX;
98+
if(data->accX == ACCELERATION_INVALID) { accX = 0; }
99+
data_buffer[6] = (accX)>>8;
100+
data_buffer[7] = (accX)&0xFF;
101+
int32_t accY = data->accY;
102+
if(data->accY == ACCELERATION_INVALID) { accY = 0; }
103+
data_buffer[8] = (accY)>>8;
104+
data_buffer[9] = (accY)&0xFF;
105+
int32_t accZ = data->accZ;
106+
if(data->accZ == ACCELERATION_INVALID) { accZ = 0; }
107+
data_buffer[10] = (accZ)>>8;
108+
data_buffer[11] = (accZ)&0xFF;
98109
data_buffer[12] = (data->vbat)>>8;
99110
data_buffer[13] = (data->vbat)&0xFF;
100111
}

ruuvi_examples/ruuvi_firmware/bluetooth_application_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define APP_DEVICE_NAME APPLICATION_DEVICE_NAME /**< TODO: Refactoring **/
66
#define APP_DEVICE_NAME_LENGTH APPLICATION_DEVICE_NAME_LENGTH
77
#define APP_TX_POWER 4 /**< dBm **/
8-
#define INIT_FWREV "2.5.5" /**< Github tag. Do not include specifiers such as "alpha" so you can accept ready binaries as they are **/
8+
#define INIT_FWREV "2.5.6" /**< Github tag. Do not include specifiers such as "alpha" so you can accept ready binaries as they are **/
99
#define INIT_SWREV INIT_FWREV /**< FW and SW are same thing in this context **/
1010

1111
// milliseconds until main loop timer function is called. Other timers can bring

ruuvi_examples/ruuvi_firmware/main.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,7 @@ static void main_sensor_task(void* p_data, uint16_t length)
354354
.pressure = PRESSURE_INVALID,
355355
.temperature = TEMPERATURE_INVALID
356356
};
357-
int32_t raw_t = 0;
358-
uint32_t raw_p = 0;
359-
uint32_t raw_h = 0;
360357
lis2dh12_sensor_buffer_t buffer;
361-
int32_t acc[3] = {0};
362358

363359
if (fast_advertising && ((millis() - fast_advertising_start) > ADVERTISING_STARTUP_PERIOD))
364360
{
@@ -383,7 +379,7 @@ static void main_sensor_task(void* p_data, uint16_t length)
383379
int32_t temp; // variable to hold temp reading
384380
(void)sd_temp_get(&temp); // get new temperature
385381
temp *= 25; // SD returns temp * 4. Ruuvi format expects temp * 100. 4*25 = 100.
386-
raw_t = (int32_t) temp;
382+
data.temperature = temp;
387383
}
388384

389385
if(lis2dh12_available)
@@ -395,9 +391,6 @@ static void main_sensor_task(void* p_data, uint16_t length)
395391
data.accZ = buffer.sensor.z;
396392
}
397393

398-
NRF_LOG_DEBUG("temperature: %d, pressure: %d, humidity: %d x: %d y: %d z: %d\r\n", raw_t, raw_p, raw_h, acc[0], acc[1], acc[2]);
399-
NRF_LOG_DEBUG("VBAT: %d send %d \r\n", vbat, data.vbat);
400-
401394
switch(tag_mode)
402395
{
403396
case RAWv2_FAST:

0 commit comments

Comments
 (0)