Serial Wombat Arduino Library

Loading...
Searching...
No Matches
SerialWombatProtectedOutput.h
Go to the documentation of this file.
1#pragma once
2/*
3 Copyright 2020-2023 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#include "SerialWombat.h"
30
31
32 typedef enum
33{
34 PO_FAULT_IF_NOT_EQUAL = 0,
35 PO_FAULT_IF_FEEDBACK_LESS_THAN_EXPECTED= 1,
36 PO_FAULT_IF_FEEDBACK_GREATER_THAN_EXPECTED = 2,
37} PO_COMPARE_t;
38
39
68 class SerialWombatProtectedOutput : public SerialWombatPin
69{
70 public:
73 SerialWombatProtectedOutput(SerialWombatChip& serialWombat):SerialWombatPin(serialWombat){}
77 void begin(uint8_t pin, uint8_t monitoredPin)
78 {
79 _pin = pin;
80 _monitoredPin = monitoredPin;
81 }
82
88 void configure(PO_COMPARE_t compareMode, uint16_t compareValue, uint8_t debounceTime, SerialWombatPinState_t activeState, SerialWombatPinState_t safeState)
89 {
90 _debounceTime = debounceTime;
91 _safeState = safeState;
92 _compareMode = compareMode;
93 _activeState = activeState;
94 {
95 uint8_t tx[] = { 200,_pin,PIN_MODE_PROTECTED_OUTPUT,SW_LE16(compareValue), _debounceTime,_monitoredPin,(uint8_t)_safeState };
96 _sw.sendPacket(tx);
97 }
98 {
99 uint8_t tx1[] = { 201,_pin,PIN_MODE_PROTECTED_OUTPUT,(uint8_t) _compareMode,(uint8_t)_activeState,0x55,0x55,0x55 };
100 _sw.sendPacket(tx1);
101 }
102
103 }
104
106 bool isInSafeState()
107 {
108
109 return (_sw.readPublicData(_pin) >= _debounceTime);
110 }
111
112 void makeInput()
113 {
114 configure(PO_FAULT_IF_FEEDBACK_LESS_THAN_EXPECTED, 0, 100, SW_INPUT, SW_INPUT);
115 }
116
121 void digitalWrite(uint8_t state)
122 {
123 if (state == HIGH)
124 {
125 configure(PO_FAULT_IF_FEEDBACK_LESS_THAN_EXPECTED, 0, 100, SW_HIGH, SW_HIGH);
126 }
127 else if (state == LOW)
128 {
129
130 configure(PO_FAULT_IF_FEEDBACK_LESS_THAN_EXPECTED, 0, 100, SW_LOW, SW_LOW);
131 }
132 }
133
134 private:
135
136 uint8_t _monitoredPin = 255;
137 PO_COMPARE_t _compareMode = PO_FAULT_IF_NOT_EQUAL;
138 uint8_t _debounceTime = 0;
139 SerialWombatPinState_t _safeState = SW_INPUT;
140 SerialWombatPinState_t _activeState = SW_INPUT;
141 uint16_t _compareValue;
142};
143
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:43
PIN_MODE_PROTECTED_OUTPUT
@ PIN_MODE_PROTECTED_OUTPUT
(8)
Definition SerialWombat.h:261
SerialWombatPinState_t
SerialWombatPinState_t
Definition SerialWombat.h:54
SW_INPUT
@ SW_INPUT
Definition SerialWombat.h:57
SW_HIGH
@ SW_HIGH
Definition SerialWombat.h:56
SW_LOW
@ SW_LOW
Definition SerialWombat.h:55
PO_COMPARE_t
PO_COMPARE_t
Definition SerialWombatProtectedOutput.h:33
PO_FAULT_IF_NOT_EQUAL
@ PO_FAULT_IF_NOT_EQUAL
Definition SerialWombatProtectedOutput.h:34
PO_FAULT_IF_FEEDBACK_GREATER_THAN_EXPECTED
@ PO_FAULT_IF_FEEDBACK_GREATER_THAN_EXPECTED
Definition SerialWombatProtectedOutput.h:36
PO_FAULT_IF_FEEDBACK_LESS_THAN_EXPECTED
@ PO_FAULT_IF_FEEDBACK_LESS_THAN_EXPECTED
Definition SerialWombatProtectedOutput.h:35
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition SerialWombat.h:300
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition SerialWombatPin.h:206
SerialWombatPin::SerialWombatPin
SerialWombatPin(SerialWombatChip &serialWombatChip)
Instantiates a Serial Wombat Pin.
Definition SerialWombatPin.h:45
SerialWombatPin::_pin
uint8_t _pin
Definition SerialWombatPin.h:205
SerialWombatPin::pin
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.
Definition SerialWombatPin.h:121
SerialWombatProtectedOutput::begin
void begin(uint8_t pin, uint8_t monitoredPin)
Definition SerialWombatProtectedOutput.h:77
SerialWombatProtectedOutput::configure
void configure(PO_COMPARE_t compareMode, uint16_t compareValue, uint8_t debounceTime, SerialWombatPinState_t activeState, SerialWombatPinState_t safeState)
Definition SerialWombatProtectedOutput.h:88
SerialWombatProtectedOutput::digitalWrite
void digitalWrite(uint8_t state)
Turn off the protection features and make the protected pin an unprotected output.
Definition SerialWombatProtectedOutput.h:121
SerialWombatProtectedOutput::makeInput
void makeInput()
Turn off protection features and make the protected pin an input.
Definition SerialWombatProtectedOutput.h:112
SerialWombatProtectedOutput::isInSafeState
bool isInSafeState()
Queries the Serial Wombat to see if the protected output has entered safe mode due to a fault.
Definition SerialWombatProtectedOutput.h:106
SerialWombatProtectedOutput::SerialWombatProtectedOutput
SerialWombatProtectedOutput(SerialWombatChip &serialWombat)
Constructor for SerialWombatProtectedOutput.
Definition SerialWombatProtectedOutput.h:73