Merge pull request #5 from Szewcson/master

fix renames in raspi lib
pull/9/head
唐杰 3 years ago committed by GitHub
commit 56bb66cbf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 102
      python/raspberrypi/DFRobot_AS3935_Lib.py

@ -51,40 +51,40 @@ class DFRobot_AS3935:
def set_tuning_caps(self, capVal):
#Assume only numbers divisible by 8 (because that's all the chip supports)
if capVal > 120: #cap_value out of range, assume highest capacitance
self.singRegWrite(0x08, 0x0F, 0x0F) #set capacitance bits to maximum
self.sing_reg_write(0x08, 0x0F, 0x0F) #set capacitance bits to maximum
else:
self.singRegWrite(0x08, 0x0F, capVal >> 3) #set capacitance bits
self.singRegRead(0x08)
self.sing_reg_write(0x08, 0x0F, capVal >> 3) #set capacitance bits
self.sing_reg_read(0x08)
#print('capacitance set to 8x%d'%(self.register[0] & 0x0F))
def power_up(self):
#register 0x00, PWD bit: 0 (clears PWD)
self.singRegWrite(0x00, 0x01, 0x00)
self.calRCO() #run RCO cal cmd
self.singRegWrite(0x08, 0x20, 0x20) #set DISP_SRCO to 1
self.sing_reg_write(0x00, 0x01, 0x00)
self.cal_RCO() #run RCO cal cmd
self.sing_reg_write(0x08, 0x20, 0x20) #set DISP_SRCO to 1
time.sleep(0.002)
self.singRegWrite(0x08, 0x20, 0x00) #set DISP_SRCO to 0
self.sing_reg_write(0x08, 0x20, 0x00) #set DISP_SRCO to 0
def power_down(self):
#register 0x00, PWD bit: 0 (sets PWD)
self.singRegWrite(0x00, 0x01, 0x01)
self.sing_reg_write(0x00, 0x01, 0x01)
def cal_RCO(self):
self.writeByte(0x3D, 0x96)
self.write_byte(0x3D, 0x96)
time.sleep(0.002)
'''!
@brief Disturber detection enabled
'''
def set_indoors(self):
self.singRegWrite(0x00, 0x3E, 0x24)
self.sing_reg_write(0x00, 0x3E, 0x24)
print("set to indoors model")
'''!
@brief Set to the outdoor model
'''
def set_outdoors(self):
self.singRegWrite(0x00, 0x3E, 0x1C)
self.sing_reg_write(0x00, 0x3E, 0x1C)
print("set to outdoors model")
'''!
@ -92,7 +92,7 @@ class DFRobot_AS3935:
'''
def disturber_dis(self):
#register 0x03, PWD bit: 5 (sets MASK_DIST)
self.singRegWrite(0x03, 0x20, 0x20)
self.sing_reg_write(0x03, 0x20, 0x20)
print("disenable disturber detection")
'''!
@ -100,24 +100,24 @@ class DFRobot_AS3935:
'''
def disturber_en(self):
#register 0x03, PWD bit: 5 (sets MASK_DIST)
self.singRegWrite(0x03, 0x20, 0x00)
self.sing_reg_write(0x03, 0x20, 0x00)
print("enable disturber detection")
def sing_reg_write(self, regAdd, dataMask, regData):
#start by reading original register data (only modifying what we need to)
self.singRegRead(regAdd)
self.sing_reg_read(regAdd)
#calculate new register data... 'delete' old targeted data, replace with new data
#note: 'dataMask' must be bits targeted for replacement
#add'l note: this function does NOT shift values into the proper place... they need to be there already
newRegData = (self.register[0] & ~dataMask)|(regData & dataMask)
#finally, write the data to the register
self.writeByte(regAdd, newRegData)
self.write_byte(regAdd, newRegData)
#print('wrt: %02x'%newRegData)
self.singRegRead(regAdd)
self.sing_reg_read(regAdd)
#print('Act: %02x'%self.register[0])
def sing_reg_read(self,regAdd):
self.readData(regAdd)
self.read_data(regAdd)
'''!
@brief Get mid-range type
@ -132,7 +132,7 @@ class DFRobot_AS3935:
#for this function:
#0 = unknown src, 1 = lightning detected, 2 = disturber, 3 = Noise level too high
time.sleep(0.03) #wait 3ms before reading (min 2ms per pg 22 of datasheet)
self.singRegRead(0x03) #read register, get rid of non-interrupt data
self.sing_reg_read(0x03) #read register, get rid of non-interrupt data
intSrc = self.register[0]&0x0F
if intSrc == 0x08:
return 1 #lightning caused interrupt
@ -147,7 +147,7 @@ class DFRobot_AS3935:
@brief Sensor reset
'''
def reset(self):
err = self.writeByte(0x3C, 0x96)
err = self.write_byte(0x3C, 0x96)
time.sleep(0.002) #wait 2ms to complete
return err
@ -156,7 +156,7 @@ class DFRobot_AS3935:
@param fdiv Set 0, 1, 2 or 3 for ratios of 16, 32, 64 and 128, respectively
'''
def set_lco_fdiv(self,fdiv):
self.singRegWrite(0x03, 0xC0, (fdiv & 0x03) << 6)
self.sing_reg_write(0x03, 0xC0, (fdiv & 0x03) << 6)
'''!
@brief Set interrupt source
@ -168,20 +168,20 @@ class DFRobot_AS3935:
#only one should be set at once, I think
#0 = NONE, 1 = TRCO, 2 = SRCO, 3 = LCO
if irqSelect == 1:
self.singRegWrite(0x08, 0xE0, 0x20) #set only TRCO bit
self.sing_reg_write(0x08, 0xE0, 0x20) #set only TRCO bit
elif irqSelect == 2:
self.singRegWrite(0x08, 0xE0, 0x40) #set only SRCO bit
self.sing_reg_write(0x08, 0xE0, 0x40) #set only SRCO bit
elif irqSelect == 3:
self.singRegWrite(0x08, 0xE0, 0x80) #set only SRCO bit
self.sing_reg_write(0x08, 0xE0, 0x80) #set only SRCO bit
else:
self.singRegWrite(0x08, 0xE0, 0x00) #clear IRQ pin display bits
self.sing_reg_write(0x08, 0xE0, 0x00) #clear IRQ pin display bits
'''
@brief get lightning distance
@return unit kilometer
'''
def get_lightning_distKm(self):
self.singRegRead(0x07) #read register, get rid of non-distance data
self.sing_reg_read(0x07) #read register, get rid of non-distance data
return self.register[0]&0x3F
'''
@ -189,12 +189,12 @@ class DFRobot_AS3935:
@return lightning energy intensity(0-1000)
'''
def get_strike_energy_raw(self):
self.singRegRead(0x06) #MMSB, shift 8 bits left, make room for MSB
self.sing_reg_read(0x06) #MMSB, shift 8 bits left, make room for MSB
nrgyRaw = (self.register[0]&0x1F) << 8
self.singRegRead(0x05) #read MSB
self.sing_reg_read(0x05) #read MSB
nrgyRaw |= self.register[0]
nrgyRaw <<= 8 #shift 8 bits left, make room for LSB
self.singRegRead(0x04) #read LSB, add to others
self.sing_reg_read(0x04) #read LSB, add to others
nrgyRaw |= self.register[0]
return nrgyRaw/16777
@ -203,23 +203,23 @@ class DFRobot_AS3935:
#This function sets min strikes to the closest available number, rounding to the floor,
#where necessary, then returns the physical value that was set. Options are 1, 5, 9 or 16 strikes.
if minStrk < 5:
self.singRegWrite(0x02, 0x30, 0x00)
self.sing_reg_write(0x02, 0x30, 0x00)
return 1
elif minStrk < 9:
self.singRegWrite(0x02, 0x30, 0x10)
self.sing_reg_write(0x02, 0x30, 0x10)
return 5
elif minStrk < 16:
self.singRegWrite(0x02, 0x30, 0x20)
self.sing_reg_write(0x02, 0x30, 0x20)
return 9
else:
self.singRegWrite(0x02, 0x30, 0x30)
self.sing_reg_write(0x02, 0x30, 0x30)
return 16
def clear_statistics(self):
#clear is accomplished by toggling CL_STAT bit 'high-low-high' (then set low to move on)
self.singRegWrite(0x02, 0x40, 0x40) #high
self.singRegWrite(0x02, 0x40, 0x00) #low
self.singRegWrite(0x02, 0x40, 0x40) #high
self.sing_reg_write(0x02, 0x40, 0x40) #high
self.sing_reg_write(0x02, 0x40, 0x00) #low
self.sing_reg_write(0x02, 0x40, 0x40) #high
'''
@brief Get the noise level
@ -228,7 +228,7 @@ class DFRobot_AS3935:
def get_noise_floor_lv1(self):
#NF settings addres 0x01, bits 6:4
#default setting of 010 at startup (datasheet, table 9)
self.singRegRead(0x01) #read register 0x01
self.sing_reg_read(0x01) #read register 0x01
return (self.register[0] & 0x70) >> 4 #should return value from 0-7, see table 16 for info
'''
@ -239,9 +239,9 @@ class DFRobot_AS3935:
#NF settings addres 0x01, bits 6:4
#default setting of 010 at startup (datasheet, table 9)
if nfSel <= 7: #nfSel within expected range
self.singRegWrite(0x01, 0x70, (nfSel & 0x07) << 4)
self.sing_reg_write(0x01, 0x70, (nfSel & 0x07) << 4)
else: #out of range, set to default (power-up value 010)
self.singRegWrite(0x01, 0x70, 0x20)
self.sing_reg_write(0x01, 0x70, 0x20)
'''
@brief read WDTH
@ -253,7 +253,7 @@ class DFRobot_AS3935:
#WDTH register: add 0x01, bits 3:0
#default value of 0010
#values should only be between 0x00 and 0x0F (0 and 7)
self.singRegRead(0x01)
self.sing_reg_read(0x01)
return self.register[0] & 0x0F
'''
@ -266,7 +266,7 @@ class DFRobot_AS3935:
#WDTH register: add 0x01, bits 3:0
#default value of 0010
#values should only be between 0x00 and 0x0F (0 and 7)
self.singRegWrite(0x01, 0x0F, wdth & 0x0F)
self.sing_reg_write(0x01, 0x0F, wdth & 0x0F)
'''
@brief read SREJ (spike rejection)
@ -279,7 +279,7 @@ class DFRobot_AS3935:
#SREJ register: add 0x02, bits 3:0
#default value of 0010
#values should only be between 0x00 and 0x0F (0 and 7)
self.singRegRead(0x02)
self.sing_reg_read(0x02)
return self.register[0] & 0x0F
'''
@ -293,26 +293,26 @@ class DFRobot_AS3935:
#WDTH register: add 0x02, bits 3:0
#default value of 0010
#values should only be between 0x00 and 0x0F (0 and 7)
self.singRegWrite(0x02, 0x0F, srej & 0x0F)
self.sing_reg_write(0x02, 0x0F, srej & 0x0F)
def print_all_regs(self):
self.singRegRead(0x00)
self.sing_reg_read(0x00)
print("Reg 0x00: %02x"%self.register[0])
self.singRegRead(0x01)
self.sing_reg_read(0x01)
print("Reg 0x01: %02x"%self.register[0])
self.singRegRead(0x02)
self.sing_reg_read(0x02)
print("Reg 0x02: %02x"%self.register[0])
self.singRegRead(0x03)
self.sing_reg_read(0x03)
print("Reg 0x03: %02x"%self.register[0])
self.singRegRead(0x04)
self.sing_reg_read(0x04)
print("Reg 0x04: %02x"%self.register[0])
self.singRegRead(0x05)
self.sing_reg_read(0x05)
print("Reg 0x05: %02x"%self.register[0])
self.singRegRead(0x06)
self.sing_reg_read(0x06)
print("Reg 0x06: %02x"%self.register[0])
self.singRegRead(0x07)
self.sing_reg_read(0x07)
print("Reg 0x07: %02x"%self.register[0])
self.singRegRead(0x08)
self.sing_reg_read(0x08)
print("Reg 0x08: %02x"%self.register[0])

Loading…
Cancel
Save