Serial Wombat Arduino Library
SerialWombatQuadEnc.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*
4 Copyright 2020-2021 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 
31 
35 typedef enum
36 {
44 
45 
46 
105 {
106 public:
107 
112  SerialWombatQuadEnc(SerialWombatChip& serialWombatChip) :SerialWombatPin(serialWombatChip)
113  {
114  _secondPin = 255;
115  }
116 
127  void begin(uint8_t pin, uint8_t secondPin, uint16_t debounce_mS = 10, bool pullUpsEnabled = true, QE_READ_MODE_t readState = QE_ONBOTH_POLL)
128  {
129  _pin = pin;
130  _secondPin = secondPin;
131  uint8_t tx[] = { 200,_pin,PIN_MODE_QUADRATUREENCODER,SW_LE16(debounce_mS), _secondPin,(uint8_t)readState,pullUpsEnabled };
132  uint8_t rx[8];
133  _sw.sendPacket(tx, rx);
134  }
135 
140  uint16_t read()
141  {
142  return _sw.readPublicData(_pin);
143  }
144 
154  uint16_t read(uint16_t replacementValue)
155  {
156  return _sw.writePublicData(_pin, replacementValue);
157  }
158 
163  void write(uint16_t value)
164  {
165  _sw.writePublicData(_pin, value);
166  }
167 private:
168 
169  uint8_t _secondPin;
170 };
171 
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition: SerialWombat.h:283
QE_ONLOW_POLL
@ QE_ONLOW_POLL
1mS Polling, process on high to low transition
Definition: SerialWombatQuadEnc.h:40
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition: SerialWombatPin.h:134
SerialWombat.h
SerialWombatChip::readPublicData
uint16_t readPublicData(uint8_t pin)
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
Definition: SerialWombat.h:658
SerialWombatPin
Describes a Serial Wombat Pin. Is base class for other pin modes.
Definition: SerialWombatPin.h:38
QE_ONBOTH_POLL
@ QE_ONBOTH_POLL
1mS Polling, process on low to high and high to low transition
Definition: SerialWombatQuadEnc.h:42
QE_ONBOTH_INT
@ QE_ONBOTH_INT
Interrupt driven, process on low to high and high to low transition.
Definition: SerialWombatQuadEnc.h:39
SerialWombatChip::sendPacket
int sendPacket(uint8_t tx[], uint8_t rx[])
Send an 8 byte packet to the Serial Wombat chip and wait for 8 bytes back.
Definition: SerialWombat.cpp:114
QE_READ_MODE_t
QE_READ_MODE_t
Definition: SerialWombatQuadEnc.h:35
SerialWombatChip::writePublicData
uint16_t writePublicData(uint8_t pin, uint16_t value)
Write a 16 bit value to a Serial Wombat pin Mode.
Definition: SerialWombat.h:685
SerialWombatQuadEnc::read
uint16_t read()
Read the quadrature encoder position from the Serial Wombat chip.
Definition: SerialWombatQuadEnc.h:140
SerialWombatQuadEnc::read
uint16_t read(uint16_t replacementValue)
Read the quadrature encoder position from the Serial Wombat chip then set the position value.
Definition: SerialWombatQuadEnc.h:154
SerialWombatQuadEnc
A class that uses two Serial Wombat input pins to read quadrature encoder input.
Definition: SerialWombatQuadEnc.h:104
SerialWombatPin::pin
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.
Definition: SerialWombatPin.h:121
QE_ONHIGH_INT
@ QE_ONHIGH_INT
Interrupt driven, process on low to high transition.
Definition: SerialWombatQuadEnc.h:38
SerialWombatQuadEnc::begin
void begin(uint8_t pin, uint8_t secondPin, uint16_t debounce_mS=10, bool pullUpsEnabled=true, QE_READ_MODE_t readState=QE_ONBOTH_POLL)
Initialization for SerialWombatQuadEnc that allows configuration of debounce time,...
Definition: SerialWombatQuadEnc.h:127
SerialWombatPin::_pin
uint8_t _pin
Definition: SerialWombatPin.h:133
PIN_MODE_QUADRATUREENCODER
@ PIN_MODE_QUADRATUREENCODER
(5)
Definition: SerialWombat.h:247
SW_LE16
#define SW_LE16(_a)
Convert a uint16_t to two bytes in little endian format for array initialization.
Definition: SerialWombat.h:41
QE_ONHIGH_POLL
@ QE_ONHIGH_POLL
1mS Polling, process on low to high transition
Definition: SerialWombatQuadEnc.h:41
QE_ONLOW_INT
@ QE_ONLOW_INT
Interrupt driven, process on high to low transition.
Definition: SerialWombatQuadEnc.h:37
SerialWombatQuadEnc::write
void write(uint16_t value)
This function initializes the position of the encoder.
Definition: SerialWombatQuadEnc.h:163
SerialWombatQuadEnc::SerialWombatQuadEnc
SerialWombatQuadEnc(SerialWombatChip &serialWombatChip)
Constructor for the SerialWombatQuadEnc class.
Definition: SerialWombatQuadEnc.h:112