basic.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. addEvent("onload", init);
  2. addEvent("onresize", checkOrientation);
  3. var screenmode = 0;
  4. var xAxis = 0;
  5. var yAxis = 0;
  6. var zAxis = 0;
  7. var Rotation_timeStamp = null;
  8. var Rotation_Rotation = null;
  9. var Accelerometer_timeStamp = null;
  10. var Accelerometer_AxisData = null;
  11. var Orientation_timeStamp = null;
  12. var Orientation_deviceOrientation = null;
  13. function init(){
  14. Rotation_timeStamp = document.getElementById("Rotation_timeStamp");
  15. Rotation_Rotation = document.getElementById("Rotation_Rotation");
  16. Accelerometer_timeStamp = document.getElementById("Accelerometer_timeStamp");
  17. Accelerometer_AxisData = document.getElementById("Accelerometer_AxisData");
  18. Orientation_timeStamp = document.getElementById("Orientation_timeStamp");
  19. Orientation_deviceOrientation = document.getElementById("Orientation_deviceOrientation");
  20. try {
  21. var myStyleTweaks = new StyleTweaker();
  22. myStyleTweaks.add("Series60/5.0", "styles/tweaks/S605th.css");
  23. myStyleTweaks.add("Series60/3.2", "styles/tweaks/S603rdFP2.css");
  24. myStyleTweaks.tweak();
  25. // Initiate toggle switch components for enabling / disabling each supported channel
  26. var toggle_rotation = new ToggleSwitch("toggle_sensors_rotation", toggle_sensors_rotation_click);
  27. var toggle_accelerometer = new ToggleSwitch("toggle_sensors_accelerometer", toggle_sensors_accelerometer_click);
  28. var toggle_orientation = new ToggleSwitch("toggle_sensors_orientation", toggle_sensors_orientation_click);
  29. initSensors();
  30. }
  31. catch (e) {
  32. var error = e.toString();
  33. alert(error);
  34. }
  35. }
  36. function checkOrientation(){
  37. try {
  38. var width = parseInt(screen.width);
  39. var height = parseInt(screen.height);
  40. //var landscapeTweaker = new StyleTweaker();
  41. // Landscape tweaks for template styles not available in templates?
  42. //landscapeTweaker.add("Series60/5.0", "../resources/styles/tweaks/S605thLandscape.css");
  43. if (width > height) {
  44. // if already in landscape mode, return
  45. if (screenmode == 1)
  46. return;
  47. // landscapeTweaker.tweak();
  48. screenmode = 1;
  49. }
  50. else {
  51. // if already in portrait mode, return
  52. if (screenmode == 0)
  53. return;
  54. // landscapeTweaker.untweak();
  55. screenmode = 0;
  56. }
  57. }
  58. catch (e) {
  59. var error = e.toString();
  60. alert(error);
  61. }
  62. }
  63. // Callback handler for rotation channel toggle click(Nokia templates object)
  64. function toggle_sensors_rotation_click(actionobj){
  65. try {
  66. var state = actionobj.getAttribute("class");
  67. var on = state.search(/on/) + 1;
  68. if (on) {
  69. startRotationSensorChannel();
  70. }
  71. else {
  72. MystopChannel("Rotation");
  73. }
  74. }
  75. catch (e) {
  76. var error = e.toString();
  77. alert(error);
  78. }
  79. }
  80. // Callback handler for rotation channel toggle click (Nokia templates object)
  81. function toggle_sensors_orientation_click(actionobj){
  82. try {
  83. var state = actionobj.getAttribute("class");
  84. var on = state.search(/on/) + 1;
  85. if (on) {
  86. startOrientationSensorChannel();
  87. }
  88. else {
  89. MystopChannel("Orientation");
  90. }
  91. }
  92. catch (e) {
  93. var error = e.toString();
  94. alert(error);
  95. }
  96. }
  97. // Callback handler for accelerometer channel toggle click (Nokia templates object)
  98. function toggle_sensors_accelerometer_click(actionobj){
  99. try {
  100. var state = actionobj.getAttribute("class");
  101. var on = state.search(/on/) + 1;
  102. if (on) {
  103. startAccelerometerAxisSensorChannel();
  104. }
  105. else {
  106. MystopChannel("AccelerometerAxis");
  107. }
  108. }
  109. catch (e) {
  110. var error = e.toString();
  111. alert(error);
  112. }
  113. }
  114. /*
  115. Displays XYZ channel sensor data in widget ui.
  116. sensordata object is passed to display function in
  117. service platform asyncronous callback handlers. sensordata schema:
  118. "timeStamp": Date,
  119. "rotationAboutXAxis": Number,
  120. "rotationAboutYAxis": Number,
  121. "rotationAboutZAxis": Number
  122. */
  123. function displayRotationChannel(sensordata){
  124. try {
  125. if (sensordata.timeStamp && sensordata.rotationAboutXAxis.toString.length
  126. && sensordata.rotationAboutYAxis.toString.length && sensordata.rotationAboutZAxis.toString.length) {
  127. if (xAxis != sensordata.rotationAboutXAxis ||
  128. yAxis != sensordata.rotationAboutYAxis ||
  129. zAxis != sensordata.rotationAboutZAxis) {
  130. xAxis = sensordata.rotationAboutXAxis;
  131. yAxis = sensordata.rotationAboutYAxis;
  132. zAxis = sensordata.rotationAboutZAxis;
  133. Rotation_timeStamp.innerHTML = (typeof sensordata.timeStamp == 'number'? new Date(sensordata.timeStamp).toLocaleString() : sensordata.timeStamp);
  134. Rotation_Rotation.innerHTML = "X: " + xAxis + ", Y: " + yAxis + ", Z: " + zAxis;
  135. }
  136. }
  137. }
  138. catch (e) {
  139. var error = e.toString();
  140. alert("displayRotationChannel " +error);
  141. }
  142. }
  143. /*
  144. Displays Accelerometer channel sensor data in widget ui.
  145. sensordata object is passed to display function in
  146. service platform asyncronous callback handlers. sensordata schema:
  147. /*
  148. {
  149. "timeStamp": Date,
  150. "axisX": Number,
  151. "axisY": Number,
  152. "axisZ": Number
  153. }
  154. */
  155. function displayAccelerometerAxisChannel(sensordata){
  156. try {
  157. if (sensordata.timeStamp && sensordata.axisX.toString.length
  158. && sensordata.axisY.toString.length && sensordata.axisZ.toString.length) {
  159. Accelerometer_timeStamp.innerHTML = (typeof sensordata.timeStamp == 'number'? new Date(sensordata.timeStamp).toLocaleString() : sensordata.timeStamp);;
  160. Accelerometer_AxisData.innerHTML = "X: " + sensordata.axisX + ", Y: " + sensordata.axisY + ", Z: " + sensordata.axisZ;
  161. }
  162. }
  163. catch (e) {
  164. var error = e.toString();
  165. alert("displayAccelerometerAxisChannel" + error);
  166. }
  167. }
  168. /*
  169. Displays orientation channel sensor data in widget ui.
  170. sensordata object is passed to display function in
  171. service platform asyncronous callback handlers. sensordata schema:
  172. {
  173. "timeStamp": Date,
  174. "deviceOrientation": String // supported values are DisplayUp, DisplayDown, DisplayLeftUp, DisplayRightUp, DisplayUpwards, and DisplayDownwards.
  175. }
  176. */
  177. function displayOrientationChannel(sensordata){
  178. try {
  179. if (sensordata.timeStamp && sensordata.deviceOrientation.length) {
  180. Orientation_timeStamp.innerHTML = (typeof sensordata.timeStamp == 'number'? new Date(sensordata.timeStamp).toLocaleString() : sensordata.timeStamp);
  181. Orientation_deviceOrientation.innerHTML = sensordata.deviceOrientation;
  182. }
  183. }
  184. catch (e) {
  185. var error = e.toString();
  186. alert("displayOrientationChannel" +error);
  187. }
  188. }