Saturday, 28 May 2011

Blu-ray wireless connection with PC



Kind of awesome to be able to connect my Samsung Blu-ray BD-C5500 to my TV and stream from an internet connection of a PC. This means you can connect any device which support IPv4. I am still hoping that IPv6 will not come in and make all my devices obsolete.

If you are keen to try, you will definitely need a player with built-in Ethernet. The wireless dongle and wireless player cost more, so if you have limited budget, this is 1 of the options.

PC Windows configuration (it can be a Linux/MAC):
Start up your PC with wireless network and share its connection with a Local Area Network (LAN).
In a normal Internet Connection Sharing (ICS) connection, Windows will default whichever connection you have selected. Normally, the default IP Address of the LAN TCP/IPv4 will be 192.168.0.1 with 255.255.255.0 as its subnet mask.
Get a cross network cable and connect 1 end to your PC and the other to the player.

Blu-ray player configuration:
Start up the player and go to Settings. Select Network and then choose Network Settings.
In Network Settings, in the Network Type, choose Wired.
Move down to Network Setting and configure it as the IP Address as 192.168.0.2 with a subnet mask of 255.255.255.0.
You can set both the Gateway and DNS Server as 192.168.0.1.

Friday, 20 May 2011

NZ Transport Agency Live Traffic Camera

Since not many users using webOS in NZ, perhaps it is time to do up a Live Traffic Camera app for webOS. I have requested for permission from NZTA, but still no news. Anyway, not going to wait for them since I know someone has developed an Android version.

Here you go, start-up another project and this is the 1st few screenshots of the app.


Sunday, 15 May 2011

Where Am I source code







Feel free to take this source away for your learning in webOS.


function WAIAssistant() {
/*
* Author : Peter Wong
* Website : petkatan.blogspot.com
*/
}


WAIAssistant.prototype.setup = function() {
// Set orientation
if (this.controller.stageController.setWindowOrientation) {
this.controller.stageController.setWindowOrientation("free")
};

// Setup Spinner while getting a GPS fix and set to false until got a GPS fix
this.controller.setupWidget("divSpinner", { spinnerSize : "large" }, { spinning : true });

// Latitude and Longitude (set to read-only)
this.attributes = { maxLength : 20 };
this.model = {'txtLatitudeModel' : '', disabled: true };
this.controller.setupWidget("txtLatitude", this.attributes, this.model);

this.attributes = { maxLength : 20 };
this.model = {'txtLongitudeModel' : '', disabled: true };
this.controller.setupWidget("txtLongitude", this.attributes, this.model);

// Address (set to multiline)
this.attributes = { maxLength : 50, holdToEdit : true };
this.model = {'txtAddressModel' : '' , disabled: false };
this.controller.setupWidget("txtAddress", this.attributes, this.model);

// Mobile Phone number (set to editable and set numlock on)
this.attributes = { modifierState : Mojo.Widget.numLock, maxLength : 20,
focusMode : Mojo.Widget.focusInsertMode, holdToEdit : true };
this.model = {'txtMobileModel' : '' };
this.controller.setupWidget("txtMobile", this.attributes, this.model);

// SMS button
this.controller.setupWidget("btnSMS", { }, { label : "SMS" } );
Mojo.Event.listen(this.controller.get("btnSMS"), Mojo.Event.tap, this.onSMSTap.bind(this));

// WAI button
this.controller.setupWidget("btnWAI", { }, { label : "WAI" } );
Mojo.Event.listen(this.controller.get("btnWAI"), Mojo.Event.tap, this.onWAITap.bind(this));

// Map button
this.controller.setupWidget("btnMap", { }, { label : "Map" } );
Mojo.Event.listen(this.controller.get("btnMap"), Mojo.Event.tap, this.onMapTap.bind(this));
};


WAIAssistant.prototype.getAddress = function(){
// Get latitude and longitude and store somewhere
this.gps_latitude = this.controller.get('txtLatitude').mojo.getValue();
this.gps_longitude = this.controller.get('txtLongitude').mojo.getValue();
/*if (this.gps_latitude == "" || this.gps_longitude == "") {
return;
}*/

// Run Spinner until GPS fix is completed
$("divScrim").show();

// Get Address based on latitude and longitude
this.controller.serviceRequest('palm://com.palm.location', {
method:"getReverseLocation",
parameters:{ latitude : this.gps_latitude, longitude : this.gps_longitude},
onSuccess: function(inResponse2){
// Hide Spinner once GPS fix is completed
$("divScrim").hide();

switch (inResponse2.errorCode) {
case 0:
this.address = inResponse2.address;
// Set the Address
this.controller.get('txtAddress').mojo.setValue (this.address);
break;

case 6:
Mojo.Controller.errorDialog("GPS fix cannot be activated - Location Service is off or not accepted the terms of use.");
break;

case 7: case 8:
Mojo.Controller.errorDialog("GPS fix is underway - pending request or temporarily blacklisted.");
break;
}
}.bind(this),
onFailure : function(inResponse2) {
// Hide Spinner once GPS fix is completed
$("divScrim").hide();

switch (inResponse2.errorCode) {
case 6:
Mojo.Controller.errorDialog("GPS fix cannot be activated - Location Service is off or not accepted the terms of use.");
break;

case 7: case 8:
Mojo.Controller.errorDialog("GPS fix is underway - pending request or temporarily blacklisted.");
break;
}
}
});
}


WAIAssistant.prototype.prepareMessage = function(){
// Get address to be passed to SMS
this.address = this.controller.get('txtAddress').mojo.getValue();
if (this.address == "") {
Mojo.Controller.errorDialog("Unable to pass Address to SMS, please retry.");
return;
}

// Call and prepare Messaging API with latitude and longitude
this.google_map_url = "http://maps.google.com/?q=" + this.gps_latitude + "," + this.gps_longitude;
this.gps_address = " Address:" + this.address;
this.message_text = this.google_map_url + this.gps_address;

// Prepare the SMS
this.controller.serviceRequest('palm://com.palm.applicationManager', {
method: 'launch',
parameters: {
id: 'com.palm.app.messaging',
params: {
composeRecipients: [
/*{
address: "email",
serviceName: "gmail"
},*/
{
address: this.mobile_no
}
],
messageText: this.message_text
}
},
onSuccess: {},
onFailure: {}
});
}

WAIAssistant.prototype.prepareMap = function(){
// Call Google Map API with latitude and longitude
this.controller.serviceRequest("palm://com.palm.applicationManager", {
method: "open",
parameters: {
id: "com.palm.app.maps",
params: {
location: {lat: this.gps_latitude, lng: this.gps_longitude},
type: "m"
}
}
});
}


WAIAssistant.prototype.gpsLocation = function(param){
// Run Spinner until GPS fix is completed
$("divScrim").show();

// Call GPS API to get latitude and longitude
this.controller.serviceRequest("palm://com.palm.location", {
method : "getCurrentPosition",
parameters : { maximumAge : 60 },
onSuccess : function(inResponse) {
// Hide Spinner once GPS fix is completed
$("divScrim").hide();

switch (inResponse.errorCode) {
case 0:
// Get the latitude and longitude
this.gps_latitude = inResponse.latitude;
this.gps_longitude = inResponse.longitude;

// Set the texfields of latitude and longitude
this.controller.get('txtLatitude').mojo.setValue (this.gps_latitude);
this.controller.get('txtLongitude').mojo.setValue (this.gps_longitude);

// Convert to numeric and check to ensure it is still on earth
// Waiting for HP to produce a fix for Southern Hemisphere
this.ngps_latitude = Number(this.gps_latitude);
if (this.ngps_latitude < -90.0 || this.ngps_latitude > 90.0) {
Mojo.Controller.errorDialog("GPS Latitude fix timeout - you will need a clear sky for GPS fix.");
break;
}
this.ngps_longitude = Number(this.gps_longitude);
if (this.ngps_longitude < -180.0 || this.ngps_longitude > 180.0) {
Mojo.Controller.errorDialog("GPS Longitude fix timeout - you will need a clear sky for GPS fix.");
break;
}

// WAI, SMS and MAP
switch (param) {
case "WAI":
this.getAddress();
break;

case "SMS":
this.getAddress();
this.prepareMessage();
break;

case "MAP":
this.getAddress();
this.prepareMap();
break;
}
break;

case 1: case 2: case 3:
Mojo.Controller.errorDialog("GPS fix timeout - you will need a clear sky for GPS fix.");
break;

case 5: case 6:
Mojo.Controller.errorDialog("GPS fix cannot be activated - Location Service is off or not accepted the terms of use.");
break;

case 7: case 8:
Mojo.Controller.errorDialog("GPS fix is underway - pending request or temporarily blacklisted.");
break;
}
}.bind(this),
onFailure : function(inResponse) {
$("divScrim").hide();
switch (inResponse.errorCode) {
case 1: case 2: case 3:
Mojo.Controller.errorDialog("GPS fix timeout - you will need a clear sky for GPS fix.");
break;

case 5: case 6:
Mojo.Controller.errorDialog("GPS fix cannot be activated - Location Service is off or not accepted the terms of use.");
break;

case 7: case 8:
Mojo.Controller.errorDialog("GPS fix is underway - pending request or temporarily blacklisted.");
break;
}
}
});
}

WAIAssistant.prototype.onSMSTap = function() {
// If Mobile number is blank, exit
this.mobile_no = this.controller.get('txtMobile').mojo.getValue();
if (this.mobile_no == "") {
Mojo.Controller.errorDialog("You must enter a Mobile before sending SMS.");
return;
}

// Check and make sure Mobile does not contain decimal value
this.nmobile_no = this.mobile_no.indexOf('.');
if (this.nmobile_no > 0) {
Mojo.Controller.errorDialog("You must enter numeric for Mobile.");
break;
}

// Check and make sure Mobile is less than 0 and more the length of Mobile
this.nmobile_no = Number(this.mobile_no);
if (this.nmobile_no <= 0 || this.nmobile_no > 99999999999999999999) {
Mojo.Controller.errorDialog("You must enter valid numeric for Mobile.");
break;
}

// Call GPS API and pass SMS (Short Messaging System) in for further action
this.gpsLocation('SMS');
};

WAIAssistant.prototype.onWAITap = function() {
// Call GPS API and pass WAI (Where Am I) in for further action
this.gpsLocation('WAI');
};


WAIAssistant.prototype.onMapTap = function() {
// Call GPS API and pass Map (Map) in for further action
this.gpsLocation('MAP');
};


WAIAssistant.prototype.clearValues = function(){
// Clear all the values
this.controller.get('txtLatitude').mojo.setValue ('');
this.controller.get('txtLongitude').mojo.setValue ('');
this.controller.get('txtAddress').mojo.setValue ('');
this.controller.get('txtMobile').mojo.setValue ('');

}


WAIAssistant.prototype.handleShaking = function(event) {
this.clearValues();
}


WAIAssistant.prototype.activate = function(event) {
this.controller.listen(document, 'shaking', this.handleShaking.bindAsEventListener(this));
};

WAIAssistant.prototype.deactivate = function(event) {
};

WAIAssistant.prototype.cleanup = function(event) {
};

Sunday, 8 May 2011

Added new feature - Shake to Clear values (reset)



After submitting the app, I have decided to add 1 minor feature - shake it to clear values. You can get this beta app from HP webOS App Catalog.

Codes:
WAIAssistant.prototype.clearValues = function(){
// Clear all the values
this.controller.get('txtLatitude').mojo.setValue ('');
this.controller.get('txtLongitude').mojo.setValue ('');
this.controller.get('txtMobile').mojo.setValue ('');
}

WAIAssistant.prototype.handleShaking = function(event) {
this.clearValues();
}

WAIAssistant.prototype.activate = function(event) {
this.controller.listen(document, 'shaking', this.handleShaking.bindAsEventListener(this));
};

Where Am I - SMS your current GPS fix or show it on Google Map



Finally, after couple of weeks learning Javascript and webOS, I have released my 1st app for beta testing.

You can download this app from HP webOS Apps Catalog

This is free for anyone to use and please do give your feedback on my 1st webOS app.

Tuesday, 3 May 2011

Send your GPS fix (geolocation) via SMS

Next, I will attempt to send a SMS of the current GPS fix to another phone using Google Map API V2. Unfortunately, this API is already deprecated by Google which I will need to find another way to future proof my app.


Codes:
gps_latitude = inResponse.latitude;
gps_longitude = inResponse.longitude;
this.controller.get('txtLatitude').mojo.setValue (gps_latitude);
this.controller.get('txtLongitude').mojo.setValue (gps_longitude);
google_map_url = "http://maps.google.com/?q=" + gps_latitude + "," + gps_longitude;
message_text = "Last known GPS fix - " + google_map_url;

this.controller.serviceRequest('palm://com.palm.applicationManager', {
method: 'launch',
parameters: {
id: 'com.palm.app.messaging',
params: {
composeRecipients: [
/*{
address: "the_email_address_you_want_to_send_to",
serviceName: "gmail"
},*/
{
address: mobile_no
}
],
messageText: message_text
}
},
onSuccess: {},
onFailure: {}
});