summaryrefslogtreecommitdiff
path: root/peripheral/libupm/src/otp538u/otp538u.h
blob: cc817197b45eea217aa8367df4a0f854a5292953 (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * Author: Jon Trulson <jtrulson@ics.com>
 * Copyright (c) 2015 Intel Corporation.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#pragma once

#include <string>
#include <mraa/aio.h>

namespace upm {

  /**
   * @brief OTP538U IR Temperature Sensor library
   * @defgroup otp538u libupm-otp538u
   * @ingroup seeed analog light hak
   */
  /**
   * @library otp538u
   * @sensor otp538u
   * @comname OTP538U IR Temperature Sensor
   * @altname Grove IR Temperature Sensor
   * @type light
   * @man generic
   * @con analog
   * @kit hak
   *
   * @brief API for the OTP538U IR Temperature Sensor
   *
   * UPM module for the OTP538U IR temperature sensor
   *
   * This module was tested with the Grove IR non-contact temperature
   * sensor.
   *
   * The sensor provides 2 analog outputs: one for the thermistor
   * that measures the ambient temperature, and the other for the thermopile
   * that measures the object temperature.
   *
   * Much of the code depends on analyzing Seeed Studio* examples
   * and the circuit design. As a result, there are several 'magic'
   * numbers derived from their circuit design. These values are used
   * by default.
   *
   * The tables used came from the "538U VT
   * Table__20_200(v1.3).pdf" and "538RT_table.pdf" datasheets.
   *
   * These tables assume the object to be measured is 9 cm (3.54
   * inches) from the sensor.
   *
   * @image html otp538u.jpg
   * @snippet otp538u.cxx Interesting
   */
  class OTP538U {
  public:
    /**
     * OTP538U constructor
     *
     * @param pinA Analog pin to use for the ambient temperature
     * @param pinO Analog pin to use for the object temperature
     * @param aref Analog reference voltage; default is 5.0 V
     */
    OTP538U(int pinA, int pinO, float aref = 5.0);

    /**
     * OTP538U destructor
     */
    ~OTP538U();

    /**
     * Gets the ambient temperature in Celsius
     *
     * @return Ambient temperature
     */
    float ambientTemperature();

    /**
     * Gets the object temperature in Celsius
     *
     * @return Object temperature
     */
    float objectTemperature();

    /**
     * Sets the offset voltage
     *
     * The Seeed Studio wiki gives an example of calibrating the sensor
     * and calculating the offset voltage to apply. Currently, the
     * default value is set, but you can use the function to set one
     * of your own.
     *
     * @param vOffset Desired offset voltage
     */
    void setVoltageOffset(float vOffset) { m_offsetVoltage = vOffset; };

    /**
     * Sets the output resistance value
     *
     * The Seeed Studio wiki example uses a value of 2,000,000 in one of
     * the equations used to calculate voltage. The value is the
     * resistance of a resistor they use in the output stage of their
     * SIG2 output. This was 'decoded' by looking at the EAGLE* files
     * containing their schematics for this device.
     *
     * @param outResistance Value of the output resistor; default is 2M Ohm
     */
    void setOutputResistence(int outResistance) { 
      m_vResistance = outResistance; };

    /**
     * Sets the reference voltage of the internal Seeed Studio voltage
     * regulator on the sensor board.
     *
     * The Seeed Studio wiki example uses a value of 2.5 in one of the
     * equations used to calculate the resistance of the ambient
     * thermistor. The value is the voltage of an internal voltage
     * regulator used on the sensor board. This was 'decoded' by
     * looking at the EAGLE files containing their schematics for this
     * device.
     *
     * @param vref Reference voltage of the internal sensor; default is 2.5 V
     */
    void setVRef(float vref) { m_vref = vref; };


  private:
    float m_vref;
    float m_aref;
    int m_vResistance;
    float m_offsetVoltage;
    int m_adcResolution;
    mraa_aio_context m_aioA;
    mraa_aio_context m_aioO;
  };
}