Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Feb 6, 2016
2 parents f1f3157 + 25b81c2 commit 7223d3a
Show file tree
Hide file tree
Showing 238 changed files with 4,612 additions and 1,901 deletions.
13 changes: 10 additions & 3 deletions App/HA4IoT.WebApp/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ function setupController() {
$.ajax({ method: "GET", url: "/api/status", timeout: 2500 }).done(function (data) {
c.errorMessage = null;

if (data.hash === c.previousHash) {
if (data._hash === c.previousHash) {
return;
}

c.previousHash = data.hash;
c.previousHash = data._hash;
console.log("Updating UI due to state changes");

$.each(data.status, function(id, state) {
Expand Down Expand Up @@ -376,7 +376,14 @@ function getConfigurationValue(actuator, name, defaultValue) {
function invokeActuator(id, request, successCallback) {
var url = "/api/actuator/" + id + "?body=" + JSON.stringify(request);

$.ajax({ method: "POST", url: url, timeout: 2500 }).done(function () {
$.ajax({
method: "POST",
async: false,
url: url,
data: JSON.stringify(request),
contentType: "application/json; charset=utf-8",
timeout: 2500
}).done(function () {
if (successCallback != null) {
successCallback();
}
Expand Down
2 changes: 1 addition & 1 deletion App/HA4IoT.WebApp/cache.manifest
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CACHE MANIFEST
# Version 1.8.23
# Version 1.8.40

CACHE:

Expand Down
35 changes: 18 additions & 17 deletions ExampleControllers/HA4IoT.Controller.Cellar/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
using Windows.Data.Json;
using Windows.Storage;
using HA4IoT.Actuators;
using HA4IoT.Actuators.Automations;
using HA4IoT.Actuators.Connectors;
using HA4IoT.Contracts.Actuators;
using HA4IoT.Contracts.Configuration;
using HA4IoT.Contracts.Hardware;
using HA4IoT.Contracts.WeatherStation;
using HA4IoT.Core;
using HA4IoT.Hardware;
using HA4IoT.Hardware.CCTools;
using HA4IoT.Hardware.GenericIOBoard;
using HA4IoT.Hardware.OpenWeatherMapWeatherStation;
using HA4IoT.Hardware.Pi2;

Expand All @@ -20,10 +21,11 @@ internal class Controller : ControllerBase
{
private enum Device
{
WeatherStation,
CellarHSRT16
}

private enum Room
private enum RoomId
{
Garden
}
Expand All @@ -50,16 +52,15 @@ protected override void Initialize()

var pi2PortController = new Pi2PortController();

IWeatherStation weatherStation = CreateWeatherStation();
var i2CBus = new I2CBusWrapper(NotificationHandler);
InitializeWeatherStation(CreateWeatherStation());

var ioBoardManager = new IOBoardCollection(HttpApiController, NotificationHandler);
var ccToolsFactory = new CCToolsBoardController(i2CBus, ioBoardManager, NotificationHandler);
var hsrt16 = ccToolsFactory.CreateHSRT16(Device.CellarHSRT16, new I2CSlaveAddress(32));

var home = new Home(Timer, HealthMonitor, weatherStation, HttpApiController, NotificationHandler);
var i2cBus = new DefaultI2CBus("II2CBus.default".ToDeviceId(), Logger);
AddDevice(i2cBus);

var garden = home.AddRoom(Room.Garden)
var ccToolsFactory = new CCToolsBoardController(this, i2cBus, HttpApiController, Logger);
var hsrt16 = ccToolsFactory.CreateHSRT16(Device.CellarHSRT16, new I2CSlaveAddress(32));

var garden = this.CreateRoom(RoomId.Garden)
.WithLamp(Garden.LampTerrace, hsrt16[HSRT16Pin.Relay15])
.WithLamp(Garden.LampGarage, hsrt16[HSRT16Pin.Relay14])
.WithLamp(Garden.LampTap, hsrt16[HSRT16Pin.Relay13])
Expand All @@ -73,17 +74,17 @@ protected override void Initialize()

garden.StateMachine(Garden.StateMachine).ConnectMoveNextAndToggleOffWith(garden.Button(Garden.Button));

garden.SetupAlwaysOn()
garden.SetupAutomaticConditionalOnAutomation()
.WithActuator(garden.Lamp(Garden.LampParkingLot))
.WithOnAtNightRange(home.WeatherStation)
.WithOnAtNightRange(WeatherStation)
.WithOffBetweenRange(TimeSpan.Parse("22:30:00"), TimeSpan.Parse("05:00:00"));

home.PublishStatisticsNotification();
PublishStatisticsNotification();

Timer.Tick += (s, e) => { pi2PortController.PollOpenInputPorts(); };
}

private void SetupStateMachine(StateMachine stateMachine, Actuators.Room garden)
private void SetupStateMachine(StateMachine stateMachine, IRoom garden)
{
stateMachine.AddOffState()
.WithActuator(garden.Lamp(Garden.LampTerrace), BinaryActuatorState.Off)
Expand Down Expand Up @@ -159,14 +160,14 @@ private IWeatherStation CreateWeatherStation()
double lon = configuration.GetNamedNumber("lon");
string appId = configuration.GetNamedString("appID");

var weatherStation = new OWMWeatherStation(lat, lon, appId, Timer, HttpApiController, NotificationHandler);
NotificationHandler.Info("WeatherStation initialized successfully");
var weatherStation = new OWMWeatherStation(DeviceId.From(Device.WeatherStation), lat, lon, appId, Timer, HttpApiController, Logger);
Logger.Info("WeatherStation initialized successfully");

return weatherStation;
}
catch (Exception exception)
{
NotificationHandler.Warning("Unable to create weather station. " + exception.Message);
Logger.Warning("Unable to create weather station. " + exception.Message);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<AssemblyName>HA4IoT.Controller.Cellar</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<TargetPlatformVersion>10.0.10586.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10586.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<EnableDotNetNativeCompatibleProfile>true</EnableDotNetNativeCompatibleProfile>
<FileAlignment>512</FileAlignment>
Expand Down Expand Up @@ -147,10 +147,6 @@
<Project>{B0A7EF01-9382-422C-81AF-C90DC5A7AFFD}</Project>
<Name>HA4IoT.Hardware.CCTools</Name>
</ProjectReference>
<ProjectReference Include="..\..\SDK\Hardware\HA4IoT.Hardware.GenericIOBoard\HA4IoT.Hardware.GenericIOBoard.csproj">
<Project>{74BECF44-F00B-40F1-9220-06C4C7F2220F}</Project>
<Name>HA4IoT.Hardware.GenericIOBoard</Name>
</ProjectReference>
<ProjectReference Include="..\..\SDK\Hardware\HA4IoT.Hardware.OpenWeatherMapWeatherStation\HA4IoT.Hardware.OpenWeatherMapWeatherStation.csproj">
<Project>{25A0003B-E68E-481A-92AD-F4BDABC65700}</Project>
<Name>HA4IoT.Hardware.OpenWeatherMapWeatherStation</Name>
Expand Down
94 changes: 41 additions & 53 deletions ExampleControllers/HA4IoT.Controller.Demo/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
using Windows.Data.Json;
using Windows.Storage;
using HA4IoT.Actuators;
using HA4IoT.Actuators.Automations;
using HA4IoT.Actuators.Connectors;
using HA4IoT.Contracts;
using HA4IoT.Contracts.Actuators;
using HA4IoT.Contracts.Hardware;
using HA4IoT.Contracts.WeatherStation;
using HA4IoT.Core;
using HA4IoT.Hardware;
using HA4IoT.Hardware.CCTools;
using HA4IoT.Hardware.DHT22;
using HA4IoT.Hardware.GenericIOBoard;
using HA4IoT.Hardware.I2CHardwareBridge;
using HA4IoT.Hardware.OpenWeatherMapWeatherStation;
using HA4IoT.Hardware.Pi2;
Expand All @@ -28,7 +26,7 @@ internal class Controller : ControllerBase
private static readonly I2CSlaveAddress I2CHardwareBridgeAddress = new I2CSlaveAddress(50);
private const byte I2CHardwareBridge433MHzSenderPin = 6;

private enum Room
private enum RoomId
{
ExampleRoom
}
Expand Down Expand Up @@ -63,6 +61,7 @@ private enum ExampleRoom

private enum Device
{
WeatherStation,
HSPE16,
HSRel8,
HSRel5
Expand All @@ -77,79 +76,68 @@ protected override void Initialize()
var pi2PortController = new Pi2PortController();

// Setup the wrapper for I2C bus access.
var i2CBus = new I2CBusWrapper(NotificationHandler);

// Setup the manager for all types of IO boards which exposes all IO boards to the HTTP API
// and polls the states of the inputs.
var ioBoardManager = new IOBoardCollection(HttpApiController, NotificationHandler);
var i2CBus = new DefaultI2CBus("II2CBus.default".ToDeviceId(), Logger);

// Setup the controller which creates ports for IO boards from CCTools (or based on PCF8574/MAX7311/PCA9555D).
var ccToolsBoardController = new CCToolsBoardController(i2CBus, ioBoardManager, NotificationHandler);
ccToolsBoardController.CreateHSPE16InputOnly(Device.HSPE16, new I2CSlaveAddress(41));
ccToolsBoardController.CreateHSREL8(Device.HSRel8, new I2CSlaveAddress(40));
ccToolsBoardController.CreateHSREL5(Device.HSRel5, new I2CSlaveAddress(56));
var ccToolsBoardController = new CCToolsBoardController(this, i2CBus, HttpApiController, Logger);
var hspe16 = ccToolsBoardController.CreateHSPE16InputOnly(Device.HSPE16, new I2CSlaveAddress(41));
var hsrel8 = ccToolsBoardController.CreateHSREL8(Device.HSRel8, new I2CSlaveAddress(40));
var hsrel5 = ccToolsBoardController.CreateHSREL5(Device.HSRel5, new I2CSlaveAddress(56));

// Setup the remote switch 433Mhz sender which is attached to the I2C bus (Arduino Nano).
var i2CHardwareBridge = new I2CHardwareBridge(I2CHardwareBridgeAddress, i2CBus);
var i2CHardwareBridge = new I2CHardwareBridge(new DeviceId("HB"), I2CHardwareBridgeAddress, i2CBus, Timer);
var remoteSwitchSender = new LPD433MHzSignalSender(i2CHardwareBridge, I2CHardwareBridge433MHzSenderPin, HttpApiController);
var dht22Accessor = new DHT22Accessor(i2CHardwareBridge, Timer);

// Setup the controller which creates ports for wireless sockets (433Mhz).
var remoteSwitchController = new RemoteSwitchController(remoteSwitchSender, Timer);

var intertechnoCodes = new IntertechnoCodeSequenceProvider();
remoteSwitchController.Register(
0,
intertechnoCodes.GetSequence(IntertechnoSystemCode.A, IntertechnoUnitCode.Unit1, RemoteSwitchCommand.TurnOn),
intertechnoCodes.GetSequence(IntertechnoSystemCode.A, IntertechnoUnitCode.Unit1, RemoteSwitchCommand.TurnOff));

// Setup the weather station which provides sunrise and sunset information.
var weatherStation = CreateWeatherStation();
var ic = new IntertechnoCodeSequenceProvider();
var remoteSwitchController = new RemoteSocketController(new DeviceId("RemoteSocketController"), remoteSwitchSender, Timer)
.WithRemoteSocket(0, ic.GetSequence(IntertechnoSystemCode.A, IntertechnoUnitCode.Unit1, RemoteSocketCommand.TurnOn), ic.GetSequence(IntertechnoSystemCode.A, IntertechnoUnitCode.Unit1, RemoteSocketCommand.TurnOff));

var home = new Home(Timer, HealthMonitor, weatherStation, HttpApiController, NotificationHandler);
// Setup the weather station which provides sunrise and sunset information.
InitializeWeatherStation(CreateWeatherStation());

// Add new rooms with actuators here! Example:
var exampleRoom = home.AddRoom(Room.ExampleRoom)
.WithTemperatureSensor(ExampleRoom.TemperatureSensor, dht22Accessor.GetTemperatureSensor(5))
.WithHumiditySensor(ExampleRoom.HumiditySensor, dht22Accessor.GetHumiditySensor(5))
.WithMotionDetector(ExampleRoom.MotionDetector, ioBoardManager.GetInputBoard(Device.HSPE16).GetInput(8))
.WithWindow(ExampleRoom.Window, w => w.WithCenterCasement(ioBoardManager.GetInputBoard(Device.HSPE16).GetInput(0)))
var exampleRoom = this.CreateRoom(RoomId.ExampleRoom)
.WithTemperatureSensor(ExampleRoom.TemperatureSensor, i2CHardwareBridge.DHT22Accessor.GetTemperatureSensor(5))
.WithHumiditySensor(ExampleRoom.HumiditySensor, i2CHardwareBridge.DHT22Accessor.GetHumiditySensor(5))
.WithMotionDetector(ExampleRoom.MotionDetector, hspe16.GetInput(8))
.WithWindow(ExampleRoom.Window, w => w.WithCenterCasement(hspe16.GetInput(0)))
.WithLamp(ExampleRoom.Lamp1, remoteSwitchController.GetOutput(0))
.WithSocket(ExampleRoom.Socket1, ioBoardManager.GetOutputBoard(Device.HSRel5).GetOutput(0))
.WithSocket(ExampleRoom.Socket2, ioBoardManager.GetOutputBoard(Device.HSRel5).GetOutput(4))
.WithSocket(ExampleRoom.BathroomFan, ioBoardManager.GetOutputBoard(Device.HSRel5).GetOutput(3))
.WithLamp(ExampleRoom.Lamp2, ioBoardManager.GetOutputBoard(Device.HSRel8).GetOutput(0))
.WithLamp(ExampleRoom.Lamp3, ioBoardManager.GetOutputBoard(Device.HSRel8).GetOutput(1))
.WithLamp(ExampleRoom.Lamp4, ioBoardManager.GetOutputBoard(Device.HSRel8).GetOutput(2))
.WithLamp(ExampleRoom.Lamp5, ioBoardManager.GetOutputBoard(Device.HSRel8).GetOutput(3))
.WithLamp(ExampleRoom.Lamp6, ioBoardManager.GetOutputBoard(Device.HSRel8).GetOutput(4))
.WithButton(ExampleRoom.Button1, ioBoardManager.GetInputBoard(Device.HSPE16).GetInput(1))
.WithButton(ExampleRoom.Button2, ioBoardManager.GetInputBoard(Device.HSPE16).GetInput(2))
.WithSocket(ExampleRoom.Socket1, hsrel5.GetOutput(0))
.WithSocket(ExampleRoom.Socket2, hsrel5.GetOutput(4))
.WithSocket(ExampleRoom.BathroomFan, hsrel5.GetOutput(3))
.WithLamp(ExampleRoom.Lamp2, hsrel8.GetOutput(0))
.WithLamp(ExampleRoom.Lamp3, hsrel8.GetOutput(1))
.WithLamp(ExampleRoom.Lamp4, hsrel8.GetOutput(2))
.WithLamp(ExampleRoom.Lamp5, hsrel8.GetOutput(3))
.WithLamp(ExampleRoom.Lamp6, hsrel8.GetOutput(4))
.WithButton(ExampleRoom.Button1, hspe16.GetInput(1))
.WithButton(ExampleRoom.Button2, hspe16.GetInput(2))
.WithVirtualButtonGroup(ExampleRoom.LedStripRemote, g => SetupLEDStripRemote(i2CHardwareBridge, g))
.WithStateMachine(ExampleRoom.CeilingFan, (sm, r) => SetupCeilingFan(sm, r, ioBoardManager));
.WithStateMachine(ExampleRoom.CeilingFan, (sm, r) => SetupCeilingFan(sm));

exampleRoom.Lamp(ExampleRoom.Lamp5).ConnectToggleActionWith(exampleRoom.Button(ExampleRoom.Button1));
exampleRoom.Lamp(ExampleRoom.Lamp6).ConnectToggleActionWith(exampleRoom.Button(ExampleRoom.Button1), ButtonPressedDuration.Long);
exampleRoom.StateMachine(ExampleRoom.CeilingFan).ConnectMoveNextAndToggleOffWith(exampleRoom.Button(ExampleRoom.Button2));

SetupHumidityDependingOutput(exampleRoom.HumiditySensor(ExampleRoom.HumiditySensor), ioBoardManager.GetOutputBoard(Device.HSRel8).GetOutput(5));
SetupHumidityDependingOutput(exampleRoom.HumiditySensor(ExampleRoom.HumiditySensor), hsrel8.GetOutput(5));

exampleRoom.SetupAutomaticTurnOnAndOffAction()
exampleRoom.SetupAutomaticTurnOnAndOffAutomation()
.WithTrigger(exampleRoom.MotionDetector(ExampleRoom.MotionDetector))
.WithTarget(exampleRoom.BinaryStateOutput(ExampleRoom.BathroomFan))
.WithTarget(exampleRoom.BinaryStateOutput(ExampleRoom.Lamp2))
.WithOnDuration(TimeSpan.FromSeconds(10));

home.PublishStatisticsNotification();
PublishStatisticsNotification();

// Setup the CSV writer which writes all state changes to the SD card (package directory).
var localCsvFileWriter = new CsvHistory(NotificationHandler, HttpApiController);
localCsvFileWriter.ConnectActuators(home);
var localCsvFileWriter = new CsvHistory(Logger, HttpApiController);
localCsvFileWriter.ConnectActuators(this);

Timer.Tick += (s, e) =>
{
pi2PortController.PollOpenInputPorts();
ioBoardManager.PollInputBoardStates();
ccToolsBoardController.PollInputBoardStates();
};
}

Expand All @@ -168,9 +156,9 @@ private void SetupHumidityDependingOutput(IHumiditySensor sensor, IBinaryOutput
};
}

private void SetupCeilingFan(StateMachine stateMachine, Actuators.Room room, IOBoardCollection ioBoardManager)
private void SetupCeilingFan(StateMachine stateMachine)
{
var relayBoard = ioBoardManager.GetOutputBoard(Device.HSRel5);
var relayBoard = Device<HSREL5>(Device.HSRel5);
var gear1 = relayBoard.GetOutput(2);
var gear2 = relayBoard.GetOutput(1);

Expand Down Expand Up @@ -203,14 +191,14 @@ private IWeatherStation CreateWeatherStation()
double lon = configuration.GetNamedNumber("lon");
string appId = configuration.GetNamedString("appID");

var weatherStation = new OWMWeatherStation(lat, lon, appId, Timer, HttpApiController, NotificationHandler);
NotificationHandler.Info("WeatherStation initialized successfully");
var weatherStation = new OWMWeatherStation(DeviceId.From(Device.WeatherStation), lat, lon, appId, Timer, HttpApiController, Logger);
Logger.Info("WeatherStation initialized successfully");

return weatherStation;
}
catch (Exception exception)
{
NotificationHandler.Warning("Unable to create weather station. " + exception.Message);
Logger.Warning("Unable to create weather station. " + exception.Message);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<AssemblyName>HA4IoT.Controller.Demo</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<TargetPlatformVersion>10.0.10586.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10586.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<EnableDotNetNativeCompatibleProfile>true</EnableDotNetNativeCompatibleProfile>
<FileAlignment>512</FileAlignment>
Expand Down Expand Up @@ -151,14 +151,6 @@
<Project>{B0A7EF01-9382-422C-81AF-C90DC5A7AFFD}</Project>
<Name>HA4IoT.Hardware.CCTools</Name>
</ProjectReference>
<ProjectReference Include="..\..\SDK\Hardware\HA4IoT.Hardware.DHT22\HA4IoT.Hardware.DHT22.csproj">
<Project>{C838FE97-95A5-4D11-8F4E-19257B1D062A}</Project>
<Name>HA4IoT.Hardware.DHT22</Name>
</ProjectReference>
<ProjectReference Include="..\..\SDK\Hardware\HA4IoT.Hardware.GenericIOBoard\HA4IoT.Hardware.GenericIOBoard.csproj">
<Project>{74BECF44-F00B-40F1-9220-06C4C7F2220F}</Project>
<Name>HA4IoT.Hardware.GenericIOBoard</Name>
</ProjectReference>
<ProjectReference Include="..\..\SDK\Hardware\HA4IoT.Hardware.I2CHardwareBridge\HA4IoT.Hardware.I2CHardwareBridge.csproj">
<Project>{8BF16E28-A01D-47E9-A5C4-CC93E347AAF4}</Project>
<Name>HA4IoT.Hardware.I2CHardwareBridge</Name>
Expand Down
Loading

0 comments on commit 7223d3a

Please sign in to comment.