Serial Wombat Arduino Library

Loading...
Searching...
No Matches
SerialWombatResistanceInput.h
Go to the documentation of this file.
1#pragma once
2
3/*
4 Copyright 2020-2023 Broadwell Consulting Inc.
5
6"Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
7 the United States. See SerialWombat.com for usage guidance.
8
9 Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26*/
27
28#include <stdint.h>
29#include "SerialWombat.h"
30
33
34
35 enum ResistanceInputPublicDataOutput {
36 ResistanceInputPublicDataOutput_Raw = 0,
37 ResistanceInputPublicDataOutput_Filtered = 1,
38 ResistanceInputPublicDataOutput_Averaged = 2,
39 ResistanceInputPublicDataOutput_Minimum = 3,
40 ResistanceInputPublicDataOutput_Maximum = 4,
41};
42
74 class SerialWombatResistanceInput : public SerialWombatPin, public SerialWombatAbstractProcessedInput
75{
76 public:
82 SerialWombatResistanceInput(SerialWombatChip& serialWombatChip):SerialWombatPin(serialWombatChip), SerialWombatAbstractProcessedInput(serialWombatChip){}
83
93 int16_t begin(uint8_t pin)
94 {
95 _pin = pin;
96 uint8_t tx[] = { 200,_pin,PIN_MODE_RESISTANCEINPUT,0,0,0,0,0 };
97 uint8_t rx[8];
98 _sw.sendPacket(tx, rx);
99 uint8_t tx1[] = { 201,_pin,PIN_MODE_RESISTANCEINPUT,4,0,0xFF,0x80,0 };
100 return _sw.sendPacket(tx1, rx);
101 }
102
112 int16_t begin(uint8_t pin, uint16_t averageSamples, uint16_t filterConstant)
113 {
114 begin(pin);
115 uint8_t tx[] = { 201,_pin,PIN_MODE_RESISTANCEINPUT,SW_LE16(averageSamples) ,SW_LE16(filterConstant),0 };
116 return _sw.sendPacket(tx);
117 }
118
129 int16_t begin(uint8_t pin, uint16_t averageSamples, uint16_t filterConstant, ResistanceInputPublicDataOutput output)
130 {
131 begin(pin);
132 uint8_t tx[] = { 201,_pin,PIN_MODE_RESISTANCEINPUT,SW_LE16(averageSamples) ,SW_LE16(filterConstant),(uint8_t)output };
133 return _sw.sendPacket(tx);
134 }
135
145 uint16_t readFilteredOhms()
146 {
147 uint8_t tx[] = { 204,_pin,PIN_MODE_RESISTANCEINPUT,0x55,0x55,0x55,0x55,0x55 };
148 uint8_t rx[8];
149
150 _sw.sendPacket(tx, rx);
151
152 return(rx[5] + rx[6] * 256);
153 }
154
155
164 uint16_t readAveragedOhms()
165 {
166 uint8_t tx[] = { 204,_pin,PIN_MODE_RESISTANCEINPUT,0x55,0x55,0x55,0x55,0x55 };
167 uint8_t rx[8];
168
169 _sw.sendPacket(tx, rx);
170
171 return(rx[3] + rx[4] * 256);
172 }
173
174
184 uint16_t readMaximumOhms(bool resetAfterRead)
185 {
186 uint8_t tx[] = { 203,_pin,PIN_MODE_RESISTANCEINPUT,0,0x55,0x55,0x55,0x55 };
187 uint8_t rx[8];
188
189 if (resetAfterRead)
190 {
191 tx[3] = 1;
192 }
193 _sw.sendPacket(tx, rx);
194
195 return(rx[5] + rx[6] * 256);
196 }
197
207 uint16_t readMinimumOhms(bool resetAfterRead)
208 {
209 uint8_t tx[] = { 203,_pin,PIN_MODE_RESISTANCEINPUT,0,0x55,0x55,0x55,0x55 };
210 uint8_t rx[8];
211
212 if (resetAfterRead)
213 {
214 tx[3] = 1;
215 }
216 _sw.sendPacket(tx, rx);
217
218 return(rx[3] + rx[4] * 256);
219 }
220
221 uint8_t pin() { return _pin; }
222 uint8_t swPinModeNumber() { return _pinMode; }
223
224 private:
225
226};
227
SerialWombat.h
SW_LE16
#define SW_LE16(_a)
Convert a uint16_t to two bytes in little endian format for array initialization.
Definition SerialWombat.h:41
PIN_MODE_RESISTANCEINPUT
@ PIN_MODE_RESISTANCEINPUT
(24)
Definition SerialWombat.h:272
ResistanceInputPublicDataOutput
ResistanceInputPublicDataOutput
Definition SerialWombatResistanceInput.h:35
ResistanceInputPublicDataOutput_Minimum
@ ResistanceInputPublicDataOutput_Minimum
The Minimum Resistance reading is displayed as public data (default)
Definition SerialWombatResistanceInput.h:39
ResistanceInputPublicDataOutput_Maximum
@ ResistanceInputPublicDataOutput_Maximum
The Maximum Resistance reading is displayed as public data (default)
Definition SerialWombatResistanceInput.h:40
ResistanceInputPublicDataOutput_Filtered
@ ResistanceInputPublicDataOutput_Filtered
The Filtered Resistance reading is displayed as public data (default)
Definition SerialWombatResistanceInput.h:37
ResistanceInputPublicDataOutput_Averaged
@ ResistanceInputPublicDataOutput_Averaged
The Averaged Resistance reading is displayed as public data (default)
Definition SerialWombatResistanceInput.h:38
ResistanceInputPublicDataOutput_Raw
@ ResistanceInputPublicDataOutput_Raw
The raw Resistance reading is displayed as public data (default)
Definition SerialWombatResistanceInput.h:36
SerialWombatAbstractProcessedInput::SerialWombatAbstractProcessedInput
SerialWombatAbstractProcessedInput(SerialWombatChip &sw)
Constructor for the SerialWombatAbstractScaledOutput Class.
Definition SerialWombatAbstractProcessedInput.h:87
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition SerialWombat.h:297
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition SerialWombatPin.h:194
SerialWombatPin::SerialWombatPin
SerialWombatPin(SerialWombatChip &serialWombatChip)
Instantiates a Serial Wombat Pin.
Definition SerialWombatPin.h:45
SerialWombatPin::_pin
uint8_t _pin
Definition SerialWombatPin.h:193
SerialWombatPin::_pinMode
uint8_t _pinMode
Definition SerialWombatPin.h:195
SerialWombatResistanceInput::SerialWombatResistanceInput
SerialWombatResistanceInput(SerialWombatChip &serialWombatChip)
Constructor for the SerialWombatResistanceInput class.
Definition SerialWombatResistanceInput.h:82
SerialWombatResistanceInput::readFilteredOhms
uint16_t readFilteredOhms()
Retreive a filtered Resistance measurement.
Definition SerialWombatResistanceInput.h:145
SerialWombatResistanceInput::begin
int16_t begin(uint8_t pin, uint16_t averageSamples, uint16_t filterConstant, ResistanceInputPublicDataOutput output)
Initialize a resistance input on a given pin.
Definition SerialWombatResistanceInput.h:129
SerialWombatResistanceInput::begin
int16_t begin(uint8_t pin, uint16_t averageSamples, uint16_t filterConstant)
Initialize a resistance input on a given pin.
Definition SerialWombatResistanceInput.h:112
SerialWombatResistanceInput::swPinModeNumber
uint8_t swPinModeNumber()
Used for ineheritance.
Definition SerialWombatResistanceInput.h:222
SerialWombatResistanceInput::begin
int16_t begin(uint8_t pin)
Initialize a resistance input on a given pin.
Definition SerialWombatResistanceInput.h:93
SerialWombatResistanceInput::readAveragedOhms
uint16_t readAveragedOhms()
Retreive an averaged Resistance measurement.
Definition SerialWombatResistanceInput.h:164
SerialWombatResistanceInput::readMinimumOhms
uint16_t readMinimumOhms(bool resetAfterRead)
Retreive the maximum single sample Resistance value in Ohms.
Definition SerialWombatResistanceInput.h:207
SerialWombatResistanceInput::readMaximumOhms
uint16_t readMaximumOhms(bool resetAfterRead)
Retreive the maximum single sample Resistance value in Ohms.
Definition SerialWombatResistanceInput.h:184
SerialWombatResistanceInput::pin
uint8_t pin()
Used for inheritance.
Definition SerialWombatResistanceInput.h:221