Serial Wombat Arduino Library
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"
32 typedef enum
33 {
37 } PO_COMPARE_t;
38 
39 
69 {
70 public:
77  void begin(uint8_t pin, uint8_t monitoredPin)
78  {
79  _pin = pin;
80  _monitoredPin = monitoredPin;
81  }
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  }
107  {
108 
109  return (_sw.readPublicData(_pin) >= _debounceTime);
110  }
112  void makeInput()
113  {
115  }
121  void digitalWrite(uint8_t state)
122  {
123  if (state == HIGH)
124  {
126  }
127  else if (state == LOW)
128  {
129 
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 
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition: SerialWombat.h:286
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
SerialWombatPin::_sw
SerialWombatChip & _sw
Definition: SerialWombatPin.h:134
PO_FAULT_IF_NOT_EQUAL
@ PO_FAULT_IF_NOT_EQUAL
Definition: SerialWombatProtectedOutput.h:34
SerialWombat.h
SW_HIGH
@ SW_HIGH
Definition: SerialWombat.h:50
SerialWombatChip::readPublicData
uint16_t readPublicData(uint8_t pin)
Read the 16 Bit public data associated with a Serial Wombat Pin Mode.
Definition: SerialWombat.h:661
SerialWombatPin
Describes a Serial Wombat Pin. Is base class for other pin modes.
Definition: SerialWombatPin.h:38
SerialWombatProtectedOutput::begin
void begin(uint8_t pin, uint8_t monitoredPin)
Definition: SerialWombatProtectedOutput.h:77
PO_FAULT_IF_FEEDBACK_LESS_THAN_EXPECTED
@ PO_FAULT_IF_FEEDBACK_LESS_THAN_EXPECTED
Definition: SerialWombatProtectedOutput.h:35
SerialWombatProtectedOutput::digitalWrite
void digitalWrite(uint8_t state)
Turn off the protection features and make the protected pin an unprotected output.
Definition: SerialWombatProtectedOutput.h:121
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:115
SerialWombatPinState_t
SerialWombatPinState_t
Definition: SerialWombat.h:47
PO_COMPARE_t
PO_COMPARE_t
Definition: SerialWombatProtectedOutput.h:32
SW_INPUT
@ SW_INPUT
Definition: SerialWombat.h:51
SerialWombatPin::pin
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.
Definition: SerialWombatPin.h:121
SW_LOW
@ SW_LOW
Definition: SerialWombat.h:49
SerialWombatPin::_pin
uint8_t _pin
Definition: SerialWombatPin.h:133
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_PROTECTED_OUTPUT
@ PIN_MODE_PROTECTED_OUTPUT
(8)
Definition: SerialWombat.h:250
PO_FAULT_IF_FEEDBACK_GREATER_THAN_EXPECTED
@ PO_FAULT_IF_FEEDBACK_GREATER_THAN_EXPECTED
Definition: SerialWombatProtectedOutput.h:36
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::SerialWombatProtectedOutput
SerialWombatProtectedOutput(SerialWombatChip &serialWombat)
Constructor for SerialWombatProtectedOutput.
Definition: SerialWombatProtectedOutput.h:73
SerialWombatProtectedOutput::makeInput
void makeInput()
Turn off protection features and make the protected pin an input.
Definition: SerialWombatProtectedOutput.h:112
SerialWombatProtectedOutput
Combine and input and output pin for a protected output.
Definition: SerialWombatProtectedOutput.h:68