Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
driver/pir: add pir-based occupancy sensing
- Loading branch information
Hyungsin
committed
Jun 26, 2018
1 parent
9c612d4
commit 0c5c3d9
Showing
13 changed files
with
345 additions
and
30 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 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 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 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 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,71 @@ | ||
/* | ||
* Copyright (C) 2018 UC Berkeley | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup drivers_pir | ||
* | ||
* @{ | ||
* @file | ||
* @brief Default configuration for PIR devices | ||
* | ||
* @author Hyung-Sin Kim <hs.kim@cs.berkeley.edu> | ||
*/ | ||
|
||
#ifndef PIR_PARAMS_H | ||
#define PIR_PARAMS_H | ||
|
||
#include "board.h" | ||
#include "pir.h" | ||
#include "saul_reg.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief Set default configuration parameters for the PIR driver | ||
* @{ | ||
*/ | ||
#ifndef PIR_PARAM_GPIO | ||
#define PIR_PARAM_GPIO GPIO_PIN(0, 6) | ||
#endif | ||
#ifndef PIR_PARAM_ACTIVE_HIGH | ||
#define PIR_PARAM_ACTIVE_HIGH 1 | ||
#endif | ||
|
||
#ifndef PIR_PARAMS | ||
#define PIR_PARAMS { .gpio = PIR_PARAM_GPIO, \ | ||
.active_high = PIR_PARAM_ACTIVE_HIGH } | ||
#endif | ||
#ifndef PIR_SAUL_INFO | ||
#define PIR_SAUL_INFO { .name = "pir" } | ||
#endif | ||
/**@}*/ | ||
|
||
/** | ||
* @brief PIR configuration | ||
*/ | ||
static const pir_params_t pir_params[] = | ||
{ | ||
PIR_PARAMS | ||
}; | ||
|
||
/** | ||
* @brief Additional meta information to keep in the SAUL registry | ||
*/ | ||
static const saul_reg_info_t pir_saul_info[] = | ||
{ | ||
PIR_SAUL_INFO | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* PIR_PARAMS_H */ | ||
/** @} */ |
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 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,42 @@ | ||
/* | ||
* Copyright (C) 2018 UC Berkeley | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup drivers_pir | ||
* @{ | ||
* | ||
* @file | ||
* @brief PIR adaption to the RIOT actuator/sensor interface | ||
* | ||
* @author Hyung-Sin Kim <hs.kim@cs.berkeley.edu> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <string.h> | ||
|
||
#include "saul.h" | ||
#include "pir.h" | ||
|
||
static int read_occup(const void *dev, phydat_t *res) { | ||
pir_t *d = (pir_t *)dev; | ||
if (pir_get_occupancy(d, &(res->val[0]))) { | ||
/* Read failure */ | ||
return -ECANCELED; | ||
} | ||
memset(&(res->val[1]), 0, 2 * sizeof(int16_t)); | ||
res->unit = UNIT_PERCENT; | ||
res->scale = -2; | ||
return 1; | ||
} | ||
|
||
const saul_driver_t pir_saul_occup_driver = { | ||
.read = read_occup, | ||
.write = saul_notsup, | ||
.type = SAUL_SENSE_OCCUP, | ||
}; |
Oops, something went wrong.