Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #2

Merged
merged 2 commits into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added port-companion/.DS_Store
Binary file not shown.
63 changes: 49 additions & 14 deletions port-companion/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@
*
*/

import { VerticalScroller, VerticalScrollbar, TopScrollerShadow, BottomScrollerShadow,
HorizontalScroller, HorizontalScrollbar, LeftScrollerShadow, RightScrollerShadow} from 'lib/scroller';
import {
VerticalScroller,
VerticalScrollbar,
TopScrollerShadow,
BottomScrollerShadow,
HorizontalScroller,
HorizontalScrollbar,
LeftScrollerShadow,
RightScrollerShadow
} from 'lib/scroller';

import {
DATA,
Expand Down Expand Up @@ -51,23 +59,44 @@ import {
} from "home";

import {
TimingScreen, TimingContent, TimingScreenTemplate,
TimingScreen,
TimingContent,
TimingScreenTemplate,
TimingContentTemplate
} from "timing";

// the variables: device screen (=content + top / bottom bar + scroller) & device screen's main content
export var DeviceScreen;
export var DeviceContent;

// the template: device screen, contains main contents & scroller (without top / bottom navbar on this page)export var DeviceScreenTemplate = Container.template($ => ({ left: 0, right: 0, top: 0, bottom: 0,
skin: whiteSkin, contents: [ VerticalScroller($, { active: true, top: 0, bottom: 0, contents: [ $.DeviceContent, VerticalScrollbar(), TopScrollerShadow(), BottomScrollerShadow(), ] }), ]}));

// the template: device screen, contains main contents & scroller (without top / bottom navbar on this page)
export var DeviceScreenTemplate = Container.template($ => ({
left: 0, right: 0, top: 0, bottom: 0,
skin: whiteSkin,
contents: [
VerticalScroller($, {
active: true, top: 0, bottom: 0,
contents: [
$.DeviceContent,
VerticalScrollbar(),
TopScrollerShadow(),
BottomScrollerShadow(),
]
}),
]
}));

// the template: device content, a parameter of device screen's template, contains the main contents
export var DeviceContentTemplate = Column.template($ => ({ top: 0, left: 0, right: 0, contents: [
export var DeviceContentTemplate = Column.template($ => ({
top: 0, left: 0, right: 0,
contents: [
new DeviceTopBar({idx: $.idx}),
new Line ( {
contents: [
new Picture({ url: DATA.init[$.idx].img, top: 0, left: 0, width: device_image_size, height: device_image_size, }),
new Picture({
url: DATA.init[$.idx].img,
top: 0, left: 0, width: device_image_size, height: device_image_size,
}),
]
}),
new Line({height: 20}),
Expand All @@ -76,7 +105,9 @@ export var DeviceContentTemplate = Column.template($ => ({ top: 0, left: 0,
new SettingOptions({label: "TIMING", idx: $.idx}),
new Divide({height: 1, length: 200}),
new SettingOptions({label: "ALERT", idx: $.idx}),
new Divide({height: 1, length: 200}), ]}));
new Divide({height: 1, length: 200}),
]
}));

// get the annotation string that appears on screen for each option (such as "On/Off" for "TYPE")
// called by the template: SettingOptions only
Expand All @@ -93,7 +124,8 @@ function getStr(idx, option) {
// return "24 to 24";// probably showing this way (a proposal)
var timing = DATA.init[idx].timing;
if (timing) {
return DATA.init[idx].time_start + " to " + DATA.init[idx].time_end;
return "Set";
//return DATA.init[idx].time_start + " to " + DATA.init[idx].time_end;
}
return "None";
}
Expand Down Expand Up @@ -167,7 +199,8 @@ var DeviceTopBar = Container.template($ => ({
new BackTemplate(),
new Blank({length: device_list_topbar_width}),
] }),
new Label({

new Label({
string: DATA.init[$.idx].DeviceName,
style: largeText,
}),
Expand All @@ -185,8 +218,10 @@ var DeviceTopBar = Container.template($ => ({
let BackTemplate = Container.template($ => ({
active: true,
contents: [
new Label({ string: "< BACK",
style: darkGraySmallText, })
new Label({
string: "< BACK",
style: darkGraySmallText,
})
],
behavior: Behavior({
onTouchEnded: function(container) {
Expand All @@ -204,4 +239,4 @@ let BackTemplate = Container.template($ => ({
// just for indentation, similar with Division, nothing special
let Blank = Container.template($ => ({
width: $.length,
}));
}));
2 changes: 1 addition & 1 deletion port-companion/files/init_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
{
"DeviceName":"Oven",
"DeviceGroup":"Kittchen",
"DeviceGroup":"Kitchen",
"id": "oven",
"type": "binary",
"value": 0,
Expand Down
1 change: 1 addition & 0 deletions port-companion/lib/field.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions port-companion/lib/keyboard.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 59 additions & 13 deletions port-companion/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/

import {
TMP_SCREEN, img_logo, whiteSkin,
TMP_SCREEN,
img_logo,
whiteSkin,
titleText,
welcome_img_padding,
welcome_img_size,
Expand All @@ -17,7 +19,15 @@ import {
DeviceSimulator,
deviceURL,
load_data,
DATA,} from "global_settings";import { Button, ButtonBehavior, RadioGroup, RadioGroupBehavior} from 'lib/buttons';
DATA,
} from "global_settings";

import {
Button,
ButtonBehavior,
RadioGroup,
RadioGroupBehavior
} from 'lib/buttons';

import {
HomeContentTemplate,
Expand All @@ -34,37 +44,73 @@ var size = welcome_img_size;
DATA = load_data();

// the button to enter the home page
let enterButtonTemplate = Button.template($ => ({ top: 0, width: 200, right: 0, height: welcome_button_height, contents: [ Label($, {left: 0, right: 0, height: welcome_button_height, string: $.textForLabel, style: buttonText}) ], Behavior: class extends ButtonBehavior { onTap(button){
let enterButtonTemplate = Button.template($ => ({
top: 0, width: 200, right: 0, height: welcome_button_height,
contents: [
Label($, {left: 0, right: 0, height: welcome_button_height, string: $.textForLabel, style: buttonText})
],
Behavior: class extends ButtonBehavior {
onTap(button){
application.remove(TMP_SCREEN);
HomeContent = HomeContentTemplate({});
LoadHomeContent(HomeContent);
HomeScreen = new HomeScreenTemplate({ HomeContent });
TMP_SCREEN = HomeScreen;
application.add(TMP_SCREEN); }
}}));
application.add(TMP_SCREEN);
}

}
}));

// the welcome page main contentvar WelcomePageTemplate = Container.template($ => ({ left: 0, right: 0, top: 0, bottom: 0, skin: $.skin, contents: [
// the welcome page main content
var WelcomePageTemplate = Container.template($ => ({
left: 0, right: 0, top: 0, bottom: 0,
skin: $.skin,
contents: [
new Column({
top: padding, bottom: padding,
contents: [ new Picture({ url: $.img_url, top: padding, left: padding, right: padding, width: size, height: size, }),
contents: [
new Picture({
url: $.img_url,
top: padding, left: padding, right: padding, width: size, height: size,
}),
new Label({
string: $.title,
style: titleText
}),
new enterButtonTemplate({textForLabel: "ENTER YOUR HOME"}),

]
}), ]}));
}),
]
}));

/* behavior of connecting the devices */
// connected by port
Handler.bind("/discover", Behavior({ onInvoke: function(handler, message){
trace("found the device.\n"); deviceURL = JSON.parse(message.requestText).url; }}));Handler.bind("/forget", Behavior({ onInvoke: function(handler, message){
trace("forget the device.\n"); deviceURL = ""; }}));
Handler.bind("/discover", Behavior({
onInvoke: function(handler, message){
trace("found the device.\n");
deviceURL = JSON.parse(message.requestText).url;
}
}));
Handler.bind("/forget", Behavior({
onInvoke: function(handler, message){
trace("forget the device.\n");
deviceURL = "";
}
}));
// will be used to communicate between device and the companion application
var ApplicationBehavior = Behavior.template({ onDisplayed: function(application) { application.discover(DeviceSimulator); // application.add(new HomeScreen({ onOff:"on" })); }, onQuit: function(application) { application.forget(DeviceSimulator); },});
var ApplicationBehavior = Behavior.template({
onDisplayed: function(application) {
application.discover(DeviceSimulator);
// application.add(new HomeScreen({ onOff:"on" }));
},
onQuit: function(application) {
application.forget(DeviceSimulator);
},
});

// initialize the welcome screen
// initialize the welcome screen
TMP_SCREEN = new WelcomePageTemplate({ skin: whiteSkin, img_url: img_logo, title: "HoM"});
application.behavior = new ApplicationBehavior();
application.add(TMP_SCREEN);
Expand Down
Loading