summaryrefslogtreecommitdiff
path: root/wasp/drivers/signal.py
blob: 974adb5fafadc450f7b70c89f1d00ddacce03116 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (C) 2020 Daniel Thompson

class Signal(object):
    '''Simplified Signal class

    Note: The normal C implementation isn't working for the NRF port
    '''

    def __init__(self, pin, invert=False):
        self.pin = pin
        self.invert = invert

    def __call__(self, v=None):
        return self.value(v)

    def value(self, v=None):
        if v == None:
            return self.invert ^ self.pin.value()
        self.pin.value(self.invert ^ bool(v))

    def on(self):
        self.value(1)

    def off(self):
        self.value(0)