-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGsr.ino
executable file
·110 lines (97 loc) · 2.78 KB
/
Gsr.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* @file Gsr.ino
* @author ubdussamad ([email protected])
* @brief Suite for Handling Groove GSR Sensor.
* Part of Project Umbrella
* @version V-1.0 REF 20JUN2020
* @date 2020-06-20
* @license This piece of firmware is in public domian.
* @copyright Copyright (c) 2020, [email protected]
*/
#if !defined(GSR_H)
#define GSR_H
#include "Gsr.hpp"
#endif // GSR_H
#define GSR_LOG_LEVEL 0
// 0: No logging
// 1: Basic Info logging.
// 2: All Info logging.
// 3: Verbose Logging
/**
* @brief Get GSR value.
* @return [float] Gsr value in millivolts.
*/
double gsr::get_value ( void ) {
double rtn_value = 0;
if (enable_pin_defined) {
digitalWrite( gsr_module_power , HIGH );
#if (GSR_LOG_LEVEL)
Serial.println("Turning GSR on.");
#endif
}
for ( short i = 0; i < sample_width ; i++ ) {
delay(sample_delay);
rtn_value += ( (v_adc*1000) / adc_resolution ) * analogRead( adc_channel );
}
if (enable_pin_defined) {
digitalWrite( gsr_module_power , LOW );
#if (GSR_LOG_LEVEL)
Serial.println("Turning GSR off.");
#endif
}
return (rtn_value/sample_width);
}
/**
* @brief Set the time delay between consecutive samples in milliseconds.
* @param [in] Delay Value in Milliseconds.
*/
void gsr::set_sample_delay ( const short& value ){
sample_delay = value > 0 ? value : 10;
}
/**
* @brief Construct a new gsr::gsr object \n
* Initialize the GSR Sensor Class
*
* @param channel Channel Pin Number
* @param adc_voltage ADC refernce voltage
* @param module_en_pin Enable Pin Number (if -1 then no enable pin available).
*/
gsr::gsr( const short int& channel, const double& adc_voltage, const short int& module_en_pin ) {
pinMode( channel, INPUT);
if (module_en_pin != -1) {
pinMode( module_en_pin , OUTPUT);
digitalWrite( module_en_pin , LOW );
enable_pin_defined = 1;
gsr_module_power = module_en_pin;
}
else {
enable_pin_defined = 0;
}
adc_channel = channel;
v_adc = adc_voltage;
}
/* Set the resolution of the ADC in use.
Parms: 2^Resolution ( 1024 for 10Bit ADC )
Return: void
*/
void gsr::set_adc_resolution ( const int& value ) {
adc_resolution = (double) (1<<value);
#if (DEBUG)
Serial.print("The adc resolution is set to: ");
Serial.println(adc_resolution);
#endif
}
/* Set the Voltage of the ADC in use.
Parms: Voltage (Volts > 0)
Return: void
*/
void gsr::set_adc_voltage ( const double& value ) {
v_adc = value <= 0 ? 1: value ;
}
/* Set the number of samples to take for each measure.
Parms: Number of samples.
Return: void
*/
void gsr::set_averaging_samples( const short& samples ) {
sample_width = samples < MAXIMUM_BUFFER_SIZE ? samples : MAXIMUM_BUFFER_SIZE;
}