Serial Wombat Arduino Library

Loading...
Searching...
No Matches
SerialWombatHSCounter.h
Go to the documentation of this file.
1#pragma once
2/*
3 Copyright 2023-2024 Broadwell Consulting Inc.
4
5"Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
6 the United States. See SerialWombat.com for usage guidance.
7
8 Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25*/
26
27
28#include <stdint.h>
29#include "SerialWombat.h"
30
31 class SerialWombat;
32
35
36
63
64 class SerialWombatHSCounter : public SerialWombatPin, public SerialWombatAbstractProcessedInput
65{
66 public:
67 enum publicDataOutput {
68 PULSE_COUNT = 2,
69 FREQUENCY_ON_LTH_TRANSITION = 5,
70 };
71
76 SerialWombatHSCounter(SerialWombatChip& serialWombat):SerialWombatPin(serialWombat), SerialWombatAbstractProcessedInput(serialWombat){}
77
85 int16_t begin(uint8_t pin, SerialWombatHSCounter::publicDataOutput publicDataOutput = publicDataOutput::FREQUENCY_ON_LTH_TRANSITION ,uint16_t framesBetweenUpdates = 100, uint16_t publicOutputDivisor = 1)
86 {
87 _pin = pin;
88 _pinMode = PIN_MODE_HS_COUNTER;
89 return initPacketNoResponse(0,framesBetweenUpdates, publicOutputDivisor, (uint8_t)publicDataOutput );
90 }
91
92 uint32_t readCounts(bool resetCounts = false)
93 {
94 uint8_t tx[8] =
95 {
96 (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE1,
97 _pin,
98 _pinMode,
99 (uint8_t)(resetCounts?1:0),
100 0x55,
101 0x55,
102 0x55,
103 0x55};
104 uint8_t rx[8];
105 int16_t result = _sw.sendPacket(tx, rx);
106 if (result < 0)
107 {
108 return 0;
109 }
110 uint32_t returnval = (((uint32_t)rx[6]) << 24) + (((uint32_t)rx[5]) << 16) + (((uint16_t)rx[4]) << 8) + rx[3];
111 return(returnval);
112 }
113
114 int32_t readFrequency()
115 {
116 uint8_t tx[8] =
117 {
118 (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE2,
119 _pin,
120 _pinMode,
121 0x55,
122 0x55,
123 0x55,
124 0x55,
125 0x55 };
126 uint8_t rx[8];
127 int16_t result = _sw.sendPacket(tx, rx);
128 if (result < 0)
129 {
130 return result;
131 }
132 uint32_t returnval = (((uint32_t)rx[6]) << 24) + (((uint32_t)rx[5]) << 16) + (((uint16_t)rx[4]) << 8) + rx[3];
133 return(returnval);
134 }
135
138 int16_t disable ()
139 {
140 uint8_t tx[] =
141 {
142 (uint8_t)SerialWombatCommands::CONFIGURE_PIN_MODE_DISABLE,
143 _pin,
144 _pinMode,
145 0x55,0x55,0x55,0x55,0x55
146 };
147 return _sw.sendPacket(tx);
148 }
149
150 uint8_t pin() { return _pin; }
151 uint8_t swPinModeNumber() { return _pinMode; }
152
153 private:
154
155};
SerialWombat.h
SerialWombatCommands::CONFIGURE_PIN_MODE_DISABLE
@ CONFIGURE_PIN_MODE_DISABLE
(219)
Definition SerialWombat.h:240
SerialWombatCommands::CONFIGURE_PIN_MODE2
@ CONFIGURE_PIN_MODE2
(202)
Definition SerialWombat.h:230
SerialWombatCommands::CONFIGURE_PIN_MODE1
@ CONFIGURE_PIN_MODE1
(201)
Definition SerialWombat.h:229
PIN_MODE_HS_COUNTER
@ PIN_MODE_HS_COUNTER
< (29)
Definition SerialWombat.h:278
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
SerialWombatHSCounter::readFrequency
int32_t readFrequency()
Definition SerialWombatHSCounter.h:114
SerialWombatHSCounter::disable
int16_t disable()
Disables the high speed clock output.
Definition SerialWombatHSCounter.h:138
SerialWombatHSCounter::begin
int16_t begin(uint8_t pin, SerialWombatHSCounter::publicDataOutput publicDataOutput=publicDataOutput::FREQUENCY_ON_LTH_TRANSITION, uint16_t framesBetweenUpdates=100, uint16_t publicOutputDivisor=1)
Initialization routine for SerialWombatHSCounter.
Definition SerialWombatHSCounter.h:85
SerialWombatHSCounter::readCounts
uint32_t readCounts(bool resetCounts=false)
Definition SerialWombatHSCounter.h:92
SerialWombatHSCounter::publicDataOutput
publicDataOutput
Definition SerialWombatHSCounter.h:67
SerialWombatHSCounter::FREQUENCY_ON_LTH_TRANSITION
@ FREQUENCY_ON_LTH_TRANSITION
The frequency of the pulse in Hz.
Definition SerialWombatHSCounter.h:69
SerialWombatHSCounter::PULSE_COUNT
@ PULSE_COUNT
The number of pulses that have occured since initialization.
Definition SerialWombatHSCounter.h:68
SerialWombatHSCounter::swPinModeNumber
uint8_t swPinModeNumber()
Used for ineheritance.
Definition SerialWombatHSCounter.h:151
SerialWombatHSCounter::SerialWombatHSCounter
SerialWombatHSCounter(SerialWombatChip &serialWombat)
Class constructor for SerialWombatHSCounter.
Definition SerialWombatHSCounter.h:76
SerialWombatHSCounter::pin
uint8_t pin()
Used for inheritance.
Definition SerialWombatHSCounter.h:150
SerialWombat
This class name is depricated. Do not use for new development. Use SerialWombatChip instead.
Definition SerialWombat.h:1581
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition SerialWombatPin.h:194
SerialWombatPin::SerialWombatPin
SerialWombatPin(SerialWombatChip &serialWombatChip)
Instantiates a Serial Wombat Pin.
Definition SerialWombatPin.h:45
SerialWombatPin::initPacketNoResponse
int16_t initPacketNoResponse(uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55)
Definition SerialWombatPin.h:131
SerialWombatPin::_pin
uint8_t _pin
Definition SerialWombatPin.h:193
SerialWombatPin::_pinMode
uint8_t _pinMode
Definition SerialWombatPin.h:195