-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathboards.py
45 lines (40 loc) · 1.72 KB
/
boards.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# classes to represent various hardware implementations
# saves time by not having to specific individual pins in
# the application program initialisation
from machine import SPI, Pin
import mcp2515
# base class
class cbus_board:
def __init__(self):
self.bus = None
self.controller = None
self.switch_pin_number = -1
self.green_led_pin_number = -1
self.yellow_led_pin_number = -1
# implementation of DG board
class dgboard(cbus_board):
def __init__(self):
super().__init__()
self.bus = SPI(0, baudrate=10_000_000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, sck=Pin(2), mosi=Pin(3), miso=Pin(4))
self.can = mcp2515.mcp2515(osc=16_000_000, cs_pin=5, interrupt_pin=1, bus=self.bus)
self.switch_pin_number = 22
self.green_led_pin_number = 21
self.yellow_led_pin_number = 20
# implemenation of IH board
class ihboard(cbus_board):
def __init__(self):
super().__init__()
self.bus = SPI(0, baudrate=10_000_000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, sck=Pin(2), mosi=Pin(3), miso=Pin(4))
self.can = mcp2515.mcp2515(osc=16_000_000, cs_pin=5, interrupt_pin=1, bus=self.bus)
self.switch_pin_number = 22
self.green_led_pin_number = 21
self.yellow_led_pin_number = 20
# a 3rd board example
class another_board(cbus_board):
def __init__(self):
super().__init__()
self.bus = SPI(0, baudrate=10_000_000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, sck=Pin(2), mosi=Pin(3), miso=Pin(4))
self.can = mcp2515.mcp2515(osc=16_000_000, cs_pin=5, interrupt_pin=1, bus=self.bus)
self.switch_pin_number = 22
self.green_led_pin_number = 21
self.yellow_led_pin_number = 20