Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is redundancy deliberate in AS3935 code #1

Open
ve3sjk opened this issue Aug 18, 2020 · 0 comments
Open

Is redundancy deliberate in AS3935 code #1

ve3sjk opened this issue Aug 18, 2020 · 0 comments

Comments

@ve3sjk
Copy link

ve3sjk commented Aug 18, 2020

I am in the process of adding sensors to the files and converting all the tabs to space i have noticed things are being done twice in this section of code, is this deliberate. Please note my device is on address 0x03 and does work with the code below as written.

`# as3935 Set up Lightning Detector
as3935LastInterrupt = 0
as3935LightningCount = 0
as3935LastDistance = 0
as3935LastStatus = ""
as3935Interrupt = False

switch to BUS1 - for low loading ib Base Bus

if (config.TCA9545_I2CMux_Present):
tca9545.write_control_register(TCA9545_CONFIG_BUS1)

as3935 = RPi_AS3935(address=0x02, bus=1)

#set values for lightning

format: [NoiseFloor, Indoor, TuneCap, DisturberDetection, WatchDogThreshold, SpikeDetection]

default: [2,1,7,0,3,3]

NoiseFloor = config.AS3935_Lightning_Config[0]
Indoor = config.AS3935_Lightning_Config[1]
TuneCap = config.AS3935_Lightning_Config[2]
DisturberDetection = config.AS3935_Lightning_Config[3]
WatchDogThreshold = config.AS3935_Lightning_Config[4]
SpikeDetection = config.AS3935_Lightning_Config[5]

try:

            print "as3935 start"

            as3935.set_noise_floor(NoiseFloor)
            as3935.set_indoors(Indoor)
            as3935.calibrate(tun_cap=TuneCap)
            as3935.set_mask_disturber(DisturberDetection)
            as3935.set_watchdog_threshold(WatchDogThreshold)
            as3935.set_spike_detection(SpikeDetection)


            config.AS3935_Present = True
            print "as3935 present at 0x02"
	#process_as3935_interrupt()
            if (config.TCA9545_I2CMux_Present):
     	    	tca9545.write_control_register(TCA9545_CONFIG_BUS1)

except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)

    	as3935 = RPi_AS3935(address=0x03, bus=1)

    	try:

                    as3935.set_noise_floor(NoiseFloor)
                    as3935.set_indoors(Indoor)
                    as3935.calibrate(tun_cap=TuneCap)
                    as3935.set_mask_disturber(DisturberDetection)
                    as3935.set_watchdog_threshold(WatchDogThreshold)
                    as3935.set_spike_detection(SpikeDetection)

            	config.AS3935_Present = True
            	#print "as3935 present"
    	except IOError as e:

           		print "I/O error({0}): {1}".format(e.errno, e.strerror)
            	config.AS3935_Present = False
            	# back to BUS0
            	if (config.TCA9545_I2CMux_Present):
    		 	tca9545.write_control_register(TCA9545_CONFIG_BUS0)

back to BUS0

if (config.TCA9545_I2CMux_Present):
tca9545.write_control_register(TCA9545_CONFIG_BUS0)
time.sleep(0.003`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant