-
Notifications
You must be signed in to change notification settings - Fork 0
/
ignition.py
82 lines (77 loc) · 2.2 KB
/
ignition.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
#!/usr/bin/python
import Adafruit_BBIO.PWM as PWM
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.ADC as ADC
import time
def simple_ignite(debuglevel):
GPIO.setup("P8_14",GPIO.OUT) #This pin fires the ignition
GPIO.output("P8_14",GPIO.LOW)
PWM.start("P8_19",15,49500) #works best with an 11 turn primary
GPIO.output("P8_14",GPIO.HIGH)
if debuglevel:
print "Igniting"
time.sleep(2) #plenty of time for ignition
GPIO.output("P8_14",GPIO.LOW)
PWM.stop("P8_19")
PWM.cleanup()
failure=0
return {'failure':failure}
def selftest(debuglevel):
threshold=340 #150mv threshold
threshigh=1024 #450mv upper threshold
ADC.setup()
ADC.read_raw("AIN4") #Flush this
baseline=ADC.read_raw("AIN4")
GPIO.setup("P8_14",GPIO.OUT) #This pin fires the ignition
GPIO.output("P8_14",GPIO.LOW)
PWM.start("P8_19",15,49500) #works best with an 11 turn primary
time.sleep(0.05) #50ms Settling time for the analogue front end
ADC.read_raw("AIN4")
selftest=ADC.read_raw("AIN4")
if selftest>threshold and selftest<threshigh and baseline<128:
if debuglevel:
print "Self test ok"
failure=0
else:
if debuglevel:
print "Failed"
failure=1
PWM.stop("P8_19")
time.sleep(0.2)
PWM.cleanup()
GPIO.cleanup()
#Debug output
if debuglevel:
print baseline
print selftest
return {'failure':failure, 'baseline':baseline ,'selftest':selftest }
def ignite(debuglevel):
threshold=340 #150mv threshold
threshigh=1024 #450mv upper threshold
ADC.setup()
ADC.read_raw("AIN4") #Flush this
baseline=ADC.read_raw("AIN4")
GPIO.setup("P8_14",GPIO.OUT) #This pin fires the ignition
GPIO.output("P8_14",GPIO.LOW)
PWM.start("P8_19",15,49500) #works best with an 11 turn primary
time.sleep(0.05) #50ms Settling time for the analogue front end
ADC.read_raw("AIN4")
selftest=ADC.read_raw("AIN4")
if selftest>threshold and selftest<threshigh and baseline<128:
GPIO.output("P8_14",GPIO.HIGH)
if debuglevel:
print "Igniting"
time.sleep(2) #plenty of time for ignition
failure=0
else:
if debuglevel:
print "Failed"
failure=1
GPIO.output("P8_14",GPIO.LOW)
PWM.stop("P8_19")
PWM.cleanup()
#Debug output
if debuglevel:
print baseline
print selftest
return {'failure':failure, 'baseline':baseline ,'selftest':selftest }