File: GUVAS12SD.m

package info (click to toggle)
octave-arduino 0.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,616 kB
  • sloc: cpp: 3,221; python: 438; makefile: 152; xml: 22; sh: 1
file content (138 lines) | stat: -rw-r--r-- 3,836 bytes parent folder | download
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
## Copyright (C) 2019-2020 John Donoghue <john.donoghue@ieee.org>
## 
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
## 
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see
## <https://www.gnu.org/licenses/>.

classdef GUVAS12SD < handle
  ## -*- texinfo -*- 
  ## @deftypefn {} {} arduinosensor.GUVAS12SD
  ## A thin wrapper for the GUVAS12SD analog UV-B sensor
  ## @end deftypefn
  ##
  ## @subheading Methods
  ## @deftypefn {} {@var{obj} =} GUVAS12SD(@var{arObj}, @var{pin})
  ## Constructor to create GUVAS12SD sensor
  ## @subsubheading Inputs
  ## @var{arObj} - the arduino parent object
  ##
  ## @var{pin} - the analog pin that the sensor is connected to
  ##
  ## @subsubheading Outputs
  ## @var{obj} - created GUVAS12SD object
  ##
  ## @subsubheading Example
  ## @example
  ## @code {
  ## a = arduino()
  ## # create sensor attached to pin a0.
  ## sensor = arduinosensor.GUVAS12SD(a, "a0")
  ## }
  ## @end example
  ## @end deftypefn
  ##
  ## @deftypefn {} {@var{V} =} read(@var{dsObj})
  ## Read the voltage of the sensor
  ##
  ## @subsubheading Inputs
  ## @var{dsObj} - the GUVAS12SD object
  ##
  ## @subsubheading Outputs
  ## @var{V} - read voltage - effectively equivalent to 
  ## readAnalogPin(arObj, pin).
  ##
  ## @subsubheading Example
  ## @example
  ## @code {
  ## a = arduino()
  ## s = arduinosensor.GUVAS12SD(a)
  ## # voltage
  ## volts = s.read
  ## }
  ## @end example
  ## @seealso{arduinosensor.GUVAS12SD}
  ## @end deftypefn
  ##
  ## @deftypefn {} {@var{Idx} =} readIndex(@var{dsObj})
  ## Read the UV index
  ##
  ## @subsubheading Inputs
  ## @var{dsObj} - the GUVAS12SD object
  ##
  ## @subsubheading Outputs
  ## @var{Idx} - the sensor reading as a UV index reading
  ## @end deftypefn
  ##
  ## @deftypefn {} {@var{uA} =} readuA(@var{dsObj})
  ## Read the uA of the sensor
  ##
  ## @subsubheading Inputs
  ## @var{dsObj} - the GUVAS12SD object
  ##
  ## @subsubheading Outputs
  ## @var{uA} - the sensor reading as a uAmp value
  ## @end deftypefn

  properties(Access = private, constant = true)
    SCALE_UAMPS = 4.1;
    SCALE_INDEX = 0.1;
  endproperties
  
  properties(GetAccess = public, SetAccess = private)
    Pin;
    Parent;
  endproperties

  methods
    # constructor
    function this = GUVAS12SD(parentObj, pin, varargin)

      if nargin < 2
        error('arduinosensor.GUVAS12SD: expected arduino and pin object parameters');
      endif

      if ! isarduino(parentObj)
        error('arduinosensor.GUVAS12SD: expected arduino object as first parameter');
      endif

      # check is an analog pin
      validatePin(parentObj, pin, "analog");

      # lookup/use name for pin (in the case where a terminal num was given instead of a pin number)
      this.Pin = getPinInfo(parentObj, pin).name;

      this.Parent = parentObj;

    endfunction

    function val = read (this)
      # Vo = 4.3 * diodeuA
      # UV index = Vo/0.1
      val = readAnalogPin(this.Parent, this.Pin);
    endfunction

    function val = readIndex (this)
      val = read(this)/this.SCALE_INDEX;
    endfunction

    function val = readuA (this)
      val = read(this)/this.SCALE_UAMPS;
    endfunction

    function disp(this)
      printf("    %s with properties\n", class(this));
      printf("        Pin = %s\n", this.Pin);
    endfunction

  endmethods
endclassdef