Skip to content

Commit

Permalink
examples: enviro_sensor: Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Alistair Francis <[email protected]>
  • Loading branch information
alistair23 committed Nov 12, 2024
1 parent 3ca808d commit 22fd16f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/enviro_sensor/Makefile
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
5 changes: 5 additions & 0 deletions examples/enviro_sensor/README.md
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.
65 changes: 65 additions & 0 deletions examples/enviro_sensor/main.c
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);
}
}

0 comments on commit 22fd16f

Please sign in to comment.