1
1
#Registers adapted from sample code for SEMTECH SX1276
2
+ from __future__ import print_function
3
+
2
4
import time
3
5
4
6
def connect (SPI ,frq ,** kwargs ):
@@ -70,7 +72,7 @@ def __init__(self,SPI,frq,**kwargs):
70
72
self .reset ()
71
73
self .version = self .SPIRead (self .REG_VERSION ,1 )[0 ]
72
74
if self .version != 0x12 :
73
- print 'version error' ,self .version
75
+ print ( 'version error' ,self .version )
74
76
self .sleep ()
75
77
self .setFrequency (self .frequency )
76
78
@@ -110,7 +112,7 @@ def endPacket(self):
110
112
while 1 : #Wait for TX done
111
113
if self .SPIRead (self .REG_IRQ_FLAGS ,1 )[0 ] & self .IRQ_TX_DONE_MASK : break
112
114
else :
113
- print ('wait...' )
115
+ print ('wait...' )
114
116
time .sleep (0.1 )
115
117
self .SPIWrite (self .REG_IRQ_FLAGS ,[self .IRQ_TX_DONE_MASK ])
116
118
@@ -210,19 +212,19 @@ def setTxPower(self,level,pin):
210
212
elif level > 17 :
211
213
level = 17
212
214
if level == 17 :
213
- print ('max power output' )
215
+ print ('max power output' )
214
216
self .SPIWrite (self .REG_PA_DAC ,[0x87 ])
215
217
else :
216
218
self .SPIWrite (self .REG_PA_DAC ,[0x84 ])
217
219
self .SPIWrite (self .REG_PA_CONFIG ,[self .PA_BOOST | 0x70 | (level - 2 )])
218
220
219
- print 'power' ,hex (self .SPIRead (self .REG_PA_CONFIG )[0 ])
221
+ print ( 'power' ,hex (self .SPIRead (self .REG_PA_CONFIG )[0 ]) )
220
222
221
223
def setFrequency (self ,frq ):
222
224
self ._frequency = frq
223
225
frf = (int (frq )<< 19 )/ 32000000
224
- print ('frf' ,frf )
225
- print ('freq' ,(frf >> 16 )& 0xFF ,(frf >> 8 )& 0xFF ,(frf )& 0xFF )
226
+ print ('frf' ,frf )
227
+ print ('freq' ,(frf >> 16 )& 0xFF ,(frf >> 8 )& 0xFF ,(frf )& 0xFF )
226
228
self .SPIWrite (self .REG_FRF_MSB ,[(frf >> 16 )& 0xFF ])
227
229
self .SPIWrite (self .REG_FRF_MID ,[(frf >> 8 )& 0xFF ])
228
230
self .SPIWrite (self .REG_FRF_LSB ,[frf & 0xFF ])
@@ -247,7 +249,7 @@ def setSignalBandwidth(self,sbw):
247
249
bw = num
248
250
break
249
251
num += 1
250
- print ('bandwidth: ' ,bw )
252
+ print ('bandwidth: ' ,bw )
251
253
self .SPIWrite (self .REG_MODEM_CONFIG_1 ,[(self .SPIRead (self .REG_MODEM_CONFIG_1 )[0 ]& 0x0F )| (bw << 4 )])
252
254
253
255
def setCodingRate4 (self ,denominator ):
@@ -290,7 +292,7 @@ def handleDio0Rise(self):
290
292
291
293
self .SPIWrite (self .REG_FIFO_ADDR_PTR ,self .SPIRead (self .REG_FIFO_RX_CURRENT_ADDR ,1 ))
292
294
if self ._onReceive :
293
- print self .packetLength
295
+ print ( self .packetLength )
294
296
#self._onReceive(self.packetLength)
295
297
296
298
self .SPIWrite (self .REG_FIFO_ADDR_PTR ,[0 ])
@@ -319,13 +321,12 @@ def getRaw(self):
319
321
lora .beginPacket ()
320
322
lora .write ([cntr ])
321
323
#lora.write([ord(a) for a in ":"]+[cntr])
322
- print (time .ctime (),[ord (a ) for a in ":" ]+ [cntr ], hex (lora .SPIRead (lora .REG_OP_MODE )[0 ]))
324
+ print (time .ctime (),[ord (a ) for a in ":" ]+ [cntr ], hex (lora .SPIRead (lora .REG_OP_MODE )[0 ]))
323
325
lora .endPacket ()
324
326
cntr += 1
325
327
if cntr == 255 :cntr = 0
326
328
elif mode == RX :
327
329
packet_size = lora .parsePacket ()
328
330
if packet_size :
329
- print 'data' ,lora .readAll ()
330
- print ('Rssi' ,lora .packetRssi (),lora .packetSnr ())
331
-
331
+ print ('data' ,lora .readAll ())
332
+ print ('Rssi' ,lora .packetRssi (),lora .packetSnr ())
0 commit comments