Bugfixes
[rtl-433.git] / src / devices / generic_temperature_sensor.c
1 /* Generic temperature sensor 1
2  *
3  * Copyright (C) 2015 Alexandre Coffignal
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  */
10 #include "data.h"
11 #include "rtl_433.h"
12 #include "util.h"
13
14
15 static int generic_temperature_sensor_callback(bitbuffer_t *bitbuffer) {
16         bitrow_t *bb = bitbuffer->bb;
17         data_t *data;
18         char time_str[LOCAL_TIME_BUFLEN];
19     local_time_str(0, time_str);
20         int i,device,battery;
21         float fTemp;
22
23
24         for(i=1;i<10;i++){
25                 if(bitbuffer->bits_per_row[i]!=24){
26                         /*10 24 bits frame*/
27                         return 0;
28                 }
29         }
30
31         //AAAAAAAA BBCCCCCC CCCCCCCC
32         //AAAAAAAA     : ID
33         //BBBB         : battery ?
34         //CCCCCCCCCCCC : Temp
35
36         device=(bb[1][0]);
37         battery=(bb[1][1]&0xF0)>>4;
38         fTemp=(float)((signed short)(((bb[1][1]&0x3f)*256+bb[1][2])<<2))/160.0;
39
40         data = data_make("time",        "",                     DATA_STRING,                                    time_str,
41                      "model",           "",                     DATA_STRING,    "Generic temperature sensor 1",
42                      "id",              "Id",                   DATA_FORMAT,    "\t %d",        DATA_INT,       device,
43                      "temperature_C",   "Temperature",          DATA_FORMAT,    "%.02f C",      DATA_DOUBLE,    fTemp,
44                      "battery",         "Battery?",             DATA_INT,                                       battery,
45                      NULL);
46     data_acquired_handler(data);
47         
48     return 1; 
49         
50 }
51
52 static char *output_fields[] = {
53         "time",
54         "model",
55         "id",
56         "temperature_C",
57         "battery",
58         NULL
59 };
60
61 r_device generic_temperature_sensor = {
62
63   .name          = "Generic temperature sensor 1",
64   .modulation    = OOK_PULSE_PPM_RAW,
65   .short_limit   = 3500,
66   .long_limit    = 4800,
67   .reset_limit   = 10000,
68   .json_callback = &generic_temperature_sensor_callback,
69   .disabled      = 0,
70   .demod_arg     = 0,
71   .fields        = output_fields,
72 };
73