-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c19a9b
commit a6e253e
Showing
9 changed files
with
239 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* @file | ||
* @brief BMP280 and BME280 command handlers. | ||
* @copyright 2016 [DeviceHive](http://devicehive.com) | ||
* @author Nikolay Khabarov | ||
*/ | ||
#include "commands/i2c_cmd.h" | ||
#include "DH/i2c.h" | ||
#include "DH/adc.h" | ||
|
||
#include "dhcommand_parser.h" | ||
#include <user_interface.h> | ||
#include "../devices/bmx280.h" | ||
#include "bmx280_cmd.h" | ||
|
||
#if defined(DH_COMMANDS_BMX280) && defined(DH_DEVICE_BMX280) | ||
|
||
/* | ||
* Sensor initialization | ||
*/ | ||
LOCAL int ICACHE_FLASH_ATTR dh_handle_devices_bmx280_prepare(COMMAND_RESULT *cmd_res, const char *command, | ||
const char *params, unsigned int params_len) | ||
{ | ||
gpio_command_params info; | ||
ALLOWED_FIELDS fields = 0; | ||
if (params_len) { | ||
const char *err_msg = parse_params_pins_set(params, params_len, | ||
&info, DH_ADC_SUITABLE_PINS, 0, | ||
AF_SDA | AF_SCL | AF_ADDRESS, &fields); | ||
if (err_msg != 0) { | ||
dh_command_fail(cmd_res, err_msg); | ||
return 0; // FAILED | ||
} | ||
if (fields & AF_ADDRESS) | ||
bmx280_set_address(info.address); | ||
} | ||
|
||
fields |= AF_ADDRESS; | ||
if (dh_i2c_init_helper(cmd_res, fields, &info)) | ||
return 0; // FAILED | ||
return 1; | ||
} | ||
|
||
|
||
/* | ||
* dh_handle_devices_bmp280_read() implementation. | ||
*/ | ||
void ICACHE_FLASH_ATTR dh_handle_devices_bmp280_read(COMMAND_RESULT *cmd_res, const char *command, | ||
const char *params, unsigned int params_len) | ||
{ | ||
if(!dh_handle_devices_bmx280_prepare(cmd_res, command, params, params_len)) | ||
return; | ||
float temperature; | ||
float pressure; | ||
const int status = bmx280_read(DH_I2C_NO_PIN, DH_I2C_NO_PIN, &pressure, &temperature, 0); | ||
const char *err_msg = dh_i2c_error_string(status); | ||
if (err_msg != 0) { | ||
dh_command_fail(cmd_res, err_msg); | ||
} else { | ||
cmd_res->callback(cmd_res->data, DHSTATUS_OK, RDT_FORMAT_JSON, | ||
"{\"temperature\":%f, \"pressure\":%f}", temperature, pressure); | ||
} | ||
} | ||
|
||
/* | ||
* dh_handle_devices_bme280_read() implementation. | ||
*/ | ||
void ICACHE_FLASH_ATTR dh_handle_devices_bme280_read(COMMAND_RESULT *cmd_res, const char *command, | ||
const char *params, unsigned int params_len) | ||
{ | ||
if(!dh_handle_devices_bmx280_prepare(cmd_res, command, params, params_len)) | ||
return; | ||
float temperature; | ||
float pressure; | ||
float humidity; | ||
const int status = bmx280_read(DH_I2C_NO_PIN, DH_I2C_NO_PIN, &pressure, &temperature, &humidity); | ||
const char *err_msg = dh_i2c_error_string(status); | ||
if (err_msg != 0) { | ||
dh_command_fail(cmd_res, err_msg); | ||
} else { | ||
cmd_res->callback(cmd_res->data, DHSTATUS_OK, RDT_FORMAT_JSON, | ||
"{\"temperature\":%f, \"pressure\":%f, \"humidity\":%f}", temperature, pressure, humidity); | ||
} | ||
} | ||
|
||
#endif /* DH_COMMANDS_BMX280 && DH_DEVICE_BMX280 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @file | ||
* @brief BMP280 and BME280 command handlers. | ||
* @copyright 2016 [DeviceHive](http://devicehive.com) | ||
* @author Nikolay Khabarov | ||
*/ | ||
#ifndef _COMMANDS_BMX280_CMD_H_ | ||
#define _COMMANDS_BMX280_CMD_H_ | ||
|
||
#include "user_config.h" | ||
#if defined(DH_COMMANDS_BMX280) && defined(DH_DEVICE_BMX280) | ||
#include "dhsender_data.h" | ||
|
||
/** | ||
* @brief Handle "devices/bmp280/read" command. | ||
*/ | ||
void dh_handle_devices_bmp280_read(COMMAND_RESULT *cmd_res, const char *command, | ||
const char *params, unsigned int params_len); | ||
|
||
/** | ||
* @brief Handle "devices/bme280/read" command. | ||
*/ | ||
void dh_handle_devices_bme280_read(COMMAND_RESULT *cmd_res, const char *command, | ||
const char *params, unsigned int params_len); | ||
|
||
#endif /* DH_COMMANDS_BMX280 && DH_DEVICE_BMX280 */ | ||
#endif /* _COMMANDS_BMX280_CMD_H_ */ |
Oops, something went wrong.