-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: enviro_sensor: Initial commit
Signed-off-by: Alistair Francis <[email protected]>
- Loading branch information
1 parent
3ca808d
commit 22fd16f
Showing
3 changed files
with
81 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Makefile for user application | ||
|
||
# Specify this directory relative to the current application. | ||
TOCK_USERLAND_BASE_DIR = ../.. | ||
|
||
# Which files to compile. | ||
C_SRCS := $(wildcard *.c) | ||
|
||
# Include userland master makefile. Contains rules and flags for actually | ||
# building the application. | ||
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk |
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,5 @@ | ||
Environment Sensor | ||
================== | ||
|
||
A simple example application that reads sensor data from the kernel and | ||
prints it in a loop. |
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,65 @@ | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
|
||
#include <libtock-sync/sensors/ambient_light.h> | ||
#include <libtock-sync/sensors/humidity.h> | ||
#include <libtock-sync/sensors/moisture.h> | ||
#include <libtock-sync/sensors/temperature.h> | ||
#include <libtock-sync/services/alarm.h> | ||
|
||
int main(void) { | ||
bool temp_exists = false; | ||
bool humi_exists = false; | ||
bool lux_exists = false; | ||
bool mois_exists = false; | ||
int humi = 0; | ||
int temp = 0; | ||
int lux = 0; | ||
int mois = 0; | ||
|
||
printf("Probing data from sensors.\r\n"); | ||
|
||
if (libtock_temperature_exists()) { | ||
printf("Temperature sensor exists.\r\n"); | ||
temp_exists = true; | ||
} | ||
|
||
if (libtock_humidity_exists()) { | ||
printf("Humidity sensor exists.\r\n"); | ||
humi_exists = true; | ||
} | ||
|
||
if (libtock_ambient_light_exists()) { | ||
printf("Ambient Light sensor exists.\r\n"); | ||
lux_exists = true; | ||
} | ||
|
||
if (libtock_moisture_exists()) { | ||
printf("Moisture sensor exists.\r\n"); | ||
mois_exists = true; | ||
} | ||
|
||
while (1) { | ||
if (temp_exists) { | ||
libtocksync_temperature_read(&temp); | ||
printf("Temperature: %dmC\r\n", temp); | ||
} | ||
|
||
if (humi_exists) { | ||
libtocksync_humidity_read(&humi); | ||
printf("Humidity: %dm%%\r\n", humi); | ||
} | ||
|
||
if (lux_exists) { | ||
libtocksync_ambient_light_read_intensity(&lux); | ||
printf("Ambient Light Intensity: %dlx\r\n", lux); | ||
} | ||
|
||
if (mois_exists) { | ||
libtocksync_moisture_read(&mois); | ||
printf("Moisture: %dm%% \r\n", mois); | ||
} | ||
|
||
libtocksync_alarm_delay_ms(4000); | ||
} | ||
} |