2014-11-27 16:35:02 +00:00
|
|
|
import smbus
|
|
|
|
import struct
|
|
|
|
from collections import namedtuple
|
|
|
|
|
2014-11-27 16:44:37 +00:00
|
|
|
Status = namedtuple('Status', 'ignite flame motor main_temp ambient weight aux_temp0 aux_temp1')
|
2014-11-27 16:35:02 +00:00
|
|
|
|
|
|
|
class Kiln(object):
|
2014-11-27 16:44:37 +00:00
|
|
|
fmt = struct.Struct('<2BH5f')
|
2014-11-27 16:35:02 +00:00
|
|
|
def __init__(self, addr, bus=1):
|
|
|
|
self.bus = smbus.SMBus(1)
|
|
|
|
self.addr = addr
|
|
|
|
|
|
|
|
@property
|
|
|
|
def status(self):
|
|
|
|
chars = map(chr, self.bus.read_i2c_block_data(self.addr, 0, self.fmt.size))
|
|
|
|
return Status._make(self.fmt.unpack(''.join(chars)))
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return repr(self.status)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def motor(self):
|
|
|
|
return self.status.motor
|
|
|
|
|
|
|
|
@motor.setter
|
|
|
|
def motor(self, pos):
|
|
|
|
out = map(ord, struct.pack('I',pos))
|
|
|
|
self.bus.write_i2c_block_data(self.addr,ord('M'), out)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def temperature(self):
|
|
|
|
data = self.bus.read_i2c_block_data(self.addr,ord('T'), 4)
|
|
|
|
return struct.unpack('<f', ''.join(map(chr, data)))[0]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def ignite(self):
|
|
|
|
return self.status.ignite
|
|
|
|
|
|
|
|
@ignite.setter
|
|
|
|
def ignite(self, output):
|
|
|
|
self.bus.write_i2c_block_data(self.addr,ord('I'), [int(output)])
|