Loom 4
v4.5
Arduino library for Internet of Things Rapid Prototyping in environmental sensing
Loading...
Searching...
No Matches
src
Module.h
1
#pragma once
2
#include "Arduino.h"
3
#include <Wire.h>
4
#include <stdio.h>
5
#include <string.h>
6
#include <ArduinoJson.h>
7
#include <Adafruit_SleepyDog.h>
8
9
/* Watchdog Timer Setup */
10
#define WATCHDOG_TIMEOUT 8000
11
12
// Only allow the Timer to be used if WATCHDOG_ENABLE is set
13
#if defined(WATCHDOG_ENABLE)
14
#define TIMER_ENABLE Wathchdog.enable(WATCHDOG_TIMEOUT)
15
#define TIMER_DISABLE Wathchdog.disable()
16
#define TIMER_RESET Wathchdog.reset()
17
#else
18
#define TIMER_ENABLE
19
#define TIMER_DISABLE
20
#define TIMER_RESET
21
#endif
22
23
#define OUTPUT_SIZE 200
24
30
class
Module
{
31
public
:
32
Module
(
const
char
* modName) { strcpy(moduleName, modName); };
33
34
void
setModuleName(
const
char
* modName) { strcpy(moduleName, modName); };
35
36
virtual
const
char
* getModuleName() {
return
moduleName; };
// Return the name of the sensor
37
virtual
void
printModuleName(
const
char
* message) {
38
char
output[256];
39
snprintf_P(output, 256, PSTR(
"[%s] %s"
), getModuleName(), message);
40
Serial.println(output);
41
};
42
43
// Generic measure and package calls to unify some interaction with different sensor implementations
44
virtual
void
initialize() = 0;
// Initialize all functionality of the sensor
45
virtual
void
measure() = 0;
// Collect data from the sensor
46
virtual
void
package() = 0;
// Package collected data into JSON document
47
virtual
void
power_up() = 0;
// Power the sensor up and come out of sleep
48
virtual
void
power_down() = 0;
// Power the sensor down to prepare for sleep
49
50
// Not required overrides
51
virtual
void
display_data() {};
// Called by the manager to allow OLED to display data at the same time as manager.display_data
52
53
bool
moduleInitialized =
true
;
// Whether or not the module initialized successfully true until set otherwise
54
int
module_address = -1;
// Specifically for I2C addresses, -1 means the module doesn't have an address
55
private
:
56
char
moduleName[100];
57
58
};
Module
Definition:
Module.h:30
Generated by
1.9.6