Skip to content

Commit

Permalink
restructure controller stamp
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-haynes committed Aug 10, 2019
1 parent f015e70 commit a1f833d
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/controller/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,51 @@ const LEDArray = require('./led_array');
const PinController = require('./pin_controller');
const Relay = require('./relay');

const Controller = stampit.compose(EventLogger, PinController, {
props: {
const Controller = stampit.compose(
EventLogger,
PinController,
)
.props({
LED,
LEDArray,
Pin,
Relay,
Thermostat,
},
init({ leds, relays, schedule, thermometer }) {
this.config = {
})
.init(function (controllerConfig) {
const {
leds,
pid,
relays,
schedule,
thermometer,
};
} = controllerConfig;

this.leds = this.LEDArray.props({
leds: _.map(
this.config.leds,
leds,
({ color, pIndex }) =>
this.composePinToggle(this.LED, pIndex)({ color })
),
})();

this.relays = _.map(
this.config.relays,
relays,
({ pIndex }) => this.composePinToggle(this.Relay, pIndex)()
);

this.thermometerConfig = thermometer;
this.thermostat = this.Thermostat
.props({ logLevel: this.logLevel })({
pidParams: this.config.pid,
pidParams: pid,
relays: this.relays,
targetTemperature: this.config.schedule.targetTemperature,
targetTemperature: schedule.targetTemperature,
});

// Timeout object for recurring thermometer reads
this.temperatureReadInterval = null;
},
methods: {
})
.methods({
composePinToggle(composable, pIndex) {
return composable.props({
logLevel: this.logLevel,
Expand All @@ -70,7 +75,7 @@ const Controller = stampit.compose(EventLogger, PinController, {
.then(() => {
this.temperatureReadInterval = setInterval(
() => this.thermostat.update(),
this.config.thermometer.readIntervalMS
this.thermometerConfig.readIntervalMS
);
});
},
Expand All @@ -80,7 +85,6 @@ const Controller = stampit.compose(EventLogger, PinController, {
}
this.temperatureReadInterval = null;
},
},
});
});

module.exports = Controller;

0 comments on commit a1f833d

Please sign in to comment.