Skip to content

Commit

Permalink
configuration in config.py
Browse files Browse the repository at this point in the history
  • Loading branch information
yggi committed Nov 29, 2013
1 parent 30b450c commit f706494
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
.DStore/
thumbs.db
storage/profiles
config.py
12 changes: 12 additions & 0 deletions config.pyEXAMPLE
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import logging

log_level = logging.INFO
log_format = '%(asctime)s %(levelname)s %(name)s: %(message)s'

gpio_heat = 11
gpio_cool = 10
gpio_air = 9

gpio_sensor_cs = 27
gpio_sensor_clock = 22
gpio_sensor_data = 17
36 changes: 19 additions & 17 deletions oven.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import threading,time,random,datetime,logging,json
import config

log = logging.getLogger(__name__)

Expand All @@ -9,17 +10,18 @@
log.warning("Could not initialize temperature sensor, using dummy values!")
sensor_available = False

GPIO_HEAT = 11
GPIO_COOL = 10
GPIO_AIR = 9
config.gpio_heat = 11
config.gpio_cool = 10
config.gpio_air = 9

try:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(GPIO_HEAT, GPIO.OUT)
GPIO.setup(GPIO_COOL, GPIO.OUT)
GPIO.setup(GPIO_AIR, GPIO.OUT)
GPIO.setwarnings(False)
GPIO.setup(config.gpio_heat, GPIO.OUT)
GPIO.setup(config.gpio_cool, GPIO.OUT)
GPIO.setup(config.gpio_air, GPIO.OUT)

gpio_available = True
except ImportError:
log.warning("Could not initialize GPIOs, oven operation will only be simulated!")
Expand Down Expand Up @@ -83,31 +85,31 @@ def set_heat(self,value):
if value:
self.heat = 1.0
if gpio_available:
GPIO.output(GPIO_HEAT, GPIO.LOW)
GPIO.output(config.gpio_heat, GPIO.LOW)
else:
self.heat = 0.0
if gpio_available:
GPIO.output(GPIO_HEAT, GPIO.HIGH)
GPIO.output(config.gpio_heat, GPIO.HIGH)

def set_cool(self,value):
if value:
self.cool = 1.0
if gpio_available:
GPIO.output(GPIO_COOL, GPIO.LOW)
GPIO.output(config.gpio_cool, GPIO.LOW)
else:
self.cool = 0.0
if gpio_available:
GPIO.output(GPIO_COOL, GPIO.HIGH)
GPIO.output(config.gpio_cool, GPIO.HIGH)

def set_air(self,value):
if value:
self.air = 1.0
if gpio_available:
GPIO.output(GPIO_AIR, GPIO.LOW)
GPIO.output(config.gpio_air, GPIO.LOW)
else:
self.air = 0.0
if gpio_available:
GPIO.output(GPIO_AIR, GPIO.HIGH)
GPIO.output(config.gpio_air, GPIO.HIGH)

def get_state(self):
state = {
Expand All @@ -131,11 +133,11 @@ def __init__(self,oven):
self.oven = oven

if sensor_available:
cs_pin = 27
clock_pin = 22
data_pin = 17
units = "c"
self.thermocouple = MAX31855(cs_pin, clock_pin, data_pin, units)
self.thermocouple = MAX31855(gpio_sensor_cs,
gpio_sensor_clock,
gpio_sensor_data,
"c"
)

def run(self):
while True:
Expand Down
10 changes: 8 additions & 2 deletions picoreflowd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
from gevent.pywsgi import WSGIServer
from geventwebsocket import WebSocketHandler, WebSocketError

log_format = '%(asctime)s %(levelname)s %(name)s: %(message)s'
logging.basicConfig(level = logging.INFO, format = log_format)
try:
import config
except:
print "Could not import config file."
print "Copy config.pyEXAMPLE to config.py and adapt it for your setup."
exit(1)

logging.basicConfig(level = config.log_level, format = config.log_format)
log = logging.getLogger("picoreflowd")
log.info("Starting picoreflowd")

Expand Down

0 comments on commit f706494

Please sign in to comment.