-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathboard_config.py
84 lines (71 loc) · 2.97 KB
/
board_config.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
""" Defines the BOARD class that contains the board pin mappings and RF module HF/LF info. """
# -*- coding: utf-8 -*-
# Copyright 2015-2018 Mayer Analytics Ltd.
#
# This file is part of pySX127x.
#
# pySX127x is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public
# License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# pySX127x is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You can be released from the requirements of the license by obtaining a commercial license. Such a license is
# mandatory as soon as you develop commercial activities involving pySX127x without disclosing the source code of your
# own applications, or shipping pySX127x with a closed source product.
#
# You should have received a copy of the GNU General Public License along with pySX127. If not, see
# <http://www.gnu.org/licenses/>.
import RPi.GPIO as GPIO
import spidev
import config
import time
class BOARD:
""" Board initialisation/teardown and pin configuration is kept here.
Also, information about the RF module is kept here.
This is the Raspberry Pi board with one LED and a modtronix inAir9B.
"""
DIO0=config.irqPin
# The spi object is kept here
spi = None
# tell pySX127x here whether the attached RF module uses low-band (RF*_LF pins) or high-band (RF*_HF pins).
# low band (called band 1&2) are 137-175 and 410-525
# high band (called band 3) is 862-1020
low_band = True
@staticmethod
def setup():
""" Configure the Raspberry GPIOs
:rtype : None
"""
GPIO.setmode(GPIO.BCM)
GPIO.setup(BOARD.DIO0, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
@staticmethod
def teardown():
""" Cleanup GPIO and SpiDev """
GPIO.cleanup()
BOARD.spi.close()
@staticmethod
def SpiDev(spi_bus=config.busId, spi_cs=config.csId):
""" Init and return the SpiDev object
:return: SpiDev object
:param spi_bus: The RPi SPI bus to use: 0 or 1
:param spi_cs: The RPi SPI chip select to use: 0 or 1
:rtype: SpiDev
"""
BOARD.spi = spidev.SpiDev()
BOARD.spi.open(spi_bus, spi_cs)
BOARD.spi.max_speed_hz = 5000000 # SX127x can go up to 10MHz, pick half that to be safe
return BOARD.spi
@staticmethod
def add_event_detect(dio_number, callback):
""" Wraps around the GPIO.add_event_detect function
:param dio_number: DIO pin 0
:param callback: The function to call when the DIO triggers an IRQ.
:return: None
"""
GPIO.add_event_detect(dio_number, GPIO.RISING, callback=callback)
@staticmethod
def add_events(cb_dio0):
BOARD.add_event_detect(BOARD.DIO0, callback=cb_dio0)