Skip to content

Instantly share code, notes, and snippets.

@sourceperl
Created December 5, 2014 15:06
Show Gist options
  • Save sourceperl/6fd6c86fa3dcdd34a517 to your computer and use it in GitHub Desktop.
Save sourceperl/6fd6c86fa3dcdd34a517 to your computer and use it in GitHub Desktop.
Simple Python class for relay (manage edge front, toggle)
class Relay:
def __init__(self):
self.value = False
self._value = False
@property
def state(self):
"""Get the current relay state."""
return self.value
@state.setter
def state(self, new_state):
self._value = self.value
self.value = new_state
@state.deleter
def state(self):
del self.value
del self._value
def triggPos(self):
"""True on positive edge."""
return (self.value and not self._value)
def triggNeg(self):
"""True on negative edge."""
return (self._value and not self.value)
def toggle(self):
"""Toggle relay state."""
self._value = self.value
self.value = not self.value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment