Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5D14CEFE7 for ; Tue, 28 May 2013 00:14:12 +0000 (UTC) Received: (qmail 59228 invoked by uid 500); 28 May 2013 00:14:12 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 59203 invoked by uid 500); 28 May 2013 00:14:12 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 59195 invoked by uid 99); 28 May 2013 00:14:12 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 May 2013 00:14:12 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 02A8D89B42D; Tue, 28 May 2013 00:14:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: bennmapes@apache.org To: commits@cordova.apache.org Date: Tue, 28 May 2013 00:14:11 -0000 Message-Id: <2f9fbd21ad4040eab9e612f6f706543c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/5] wp7 commit: removed compass plugin dependencies Updated Branches: refs/heads/3.0.0 b68ec5313 -> 86d27fc97 (forced update) removed compass plugin dependencies Project: http://git-wip-us.apache.org/repos/asf/cordova-wp7/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp7/commit/640e5051 Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp7/tree/640e5051 Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp7/diff/640e5051 Branch: refs/heads/3.0.0 Commit: 640e50515ef792228d209b4483e0dca4624698d6 Parents: 4836031 Author: Benn Mapes Authored: Tue May 21 18:20:05 2013 -0700 Committer: Benn Mapes Committed: Mon May 27 17:12:29 2013 -0700 ---------------------------------------------------------------------- templates/standalone/CordovaAppProj.csproj | 1 - templates/standalone/Plugins/Compass.cs | 362 ----------------------- templates/standalone/config.xml | 1 - 3 files changed, 0 insertions(+), 364 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/640e5051/templates/standalone/CordovaAppProj.csproj ---------------------------------------------------------------------- diff --git a/templates/standalone/CordovaAppProj.csproj b/templates/standalone/CordovaAppProj.csproj index 15e674c..3e0bc51 100644 --- a/templates/standalone/CordovaAppProj.csproj +++ b/templates/standalone/CordovaAppProj.csproj @@ -170,7 +170,6 @@ - http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/640e5051/templates/standalone/Plugins/Compass.cs ---------------------------------------------------------------------- diff --git a/templates/standalone/Plugins/Compass.cs b/templates/standalone/Plugins/Compass.cs deleted file mode 100644 index c9e1c4d..0000000 --- a/templates/standalone/Plugins/Compass.cs +++ /dev/null @@ -1,362 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -using System; -using System.Net; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Documents; -using System.Windows.Ink; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Animation; -using System.Windows.Shapes; -using DeviceCompass = Microsoft.Devices.Sensors.Compass; -using System.Windows.Threading; -using System.Runtime.Serialization; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.Threading; -using Microsoft.Devices.Sensors; - -namespace WPCordovaClassLib.Cordova.Commands -{ - - public class Compass : BaseCommand - { - #region Static members - - /// - /// Status of listener - /// - private static int currentStatus; - - /// - /// Id for get getCompass method - /// - private static string getCompassId = "getCompassId"; - - /// - /// Compass - /// - private static DeviceCompass compass = new DeviceCompass(); - - /// - /// Listeners for callbacks - /// - private static Dictionary watchers = new Dictionary(); - - #endregion - - #region Status codes - - public const int Stopped = 0; - public const int Starting = 1; - public const int Running = 2; - public const int ErrorFailedToStart = 4; - public const int Not_Supported = 20; - - /* - * // Capture error codes - CompassError.COMPASS_INTERNAL_ERR = 0; - CompassError.COMPASS_NOT_SUPPORTED = 20; - * */ - - #endregion - - #region CompassOptions class - /// - /// Represents Accelerometer options. - /// - [DataContract] - public class CompassOptions - { - /// - /// How often to retrieve the Acceleration in milliseconds - /// - [DataMember(IsRequired = false, Name = "frequency")] - public int Frequency { get; set; } - - /// - /// The change in degrees required to initiate a watchHeadingFilter success callback. - /// - [DataMember(IsRequired = false, Name = "filter")] - public int Filter { get; set; } - - /// - /// Watcher id - /// - [DataMember(IsRequired = false, Name = "id")] - public string Id { get; set; } - - } - #endregion - - - /// - /// Time the value was last changed - /// - //private DateTime lastValueChangedTime; - - /// - /// Accelerometer options - /// - private CompassOptions compassOptions; - - //bool isDataValid; - - //bool calibrating = false; - - public Compass() - { - - } - - /// - /// Formats current coordinates into JSON format - /// - /// Coordinates in JSON format - private string GetHeadingFormatted(CompassReading reading) - { - // NOTE: timestamp is generated on the JS side, to avoid issues with format conversions - string result = String.Format("\"magneticHeading\":{0},\"headingAccuracy\":{1},\"trueHeading\":{2}", - reading.MagneticHeading.ToString("0.0", CultureInfo.InvariantCulture), - reading.HeadingAccuracy.ToString("0.0", CultureInfo.InvariantCulture), - reading.TrueHeading.ToString("0.0", CultureInfo.InvariantCulture)); - return "{" + result + "}"; - } - - public void getHeading(string options) - { - if (!DeviceCompass.IsSupported) - { - DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "{code:" + Not_Supported + "}")); - } - else - { - //if (compass == null) - //{ - // // Instantiate the compass. - // compass = new DeviceCompass(); - // compass.TimeBetweenUpdates = TimeSpan.FromMilliseconds(40); - // compass.CurrentValueChanged += new EventHandler>(compass_CurrentValueChanged); - // compass.Calibrate += new EventHandler(compass_Calibrate); - //} - - - //compass.Start(); - - } - - try - { - if (currentStatus != Running) - { - lock (compass) - { - compass.CurrentValueChanged += compass_SingleHeadingValueChanged; - compass.Start(); - this.SetStatus(Starting); - } - - long timeout = 2000; - while ((currentStatus == Starting) && (timeout > 0)) - { - timeout = timeout - 100; - Thread.Sleep(100); - } - - if (currentStatus != Running) - { - DispatchCommandResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, ErrorFailedToStart)); - return; - } - } - lock (compass) - { - compass.CurrentValueChanged -= compass_SingleHeadingValueChanged; - if (watchers.Count < 1) - { - compass.Stop(); - this.SetStatus(Stopped); - } - } - } - catch (UnauthorizedAccessException) - { - DispatchCommandResult(new PluginResult(PluginResult.Status.ILLEGAL_ACCESS_EXCEPTION, ErrorFailedToStart)); - } - catch (Exception) - { - DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ErrorFailedToStart)); - } - } - - void compass_SingleHeadingValueChanged(object sender, Microsoft.Devices.Sensors.SensorReadingEventArgs e) - { - this.SetStatus(Running); - if (compass.IsDataValid) - { - // trueHeading :: The heading in degrees from 0 - 359.99 at a single moment in time. - // magneticHeading:: The heading relative to the geographic North Pole in degrees 0 - 359.99 at a single moment in time. - // A negative value indicates that the true heading could not be determined. - // headingAccuracy :: The deviation in degrees between the reported heading and the true heading. - //rawMagnetometerReading = e.SensorReading.MagnetometerReading; - - //Debug.WriteLine("Compass Result :: " + GetHeadingFormatted(e.SensorReading)); - - PluginResult result = new PluginResult(PluginResult.Status.OK, GetHeadingFormatted(e.SensorReading)); - - DispatchCommandResult(result); - } - } - - /// - /// Starts listening for compass sensor - /// - /// status of listener - private int start() - { - if ((currentStatus == Running) || (currentStatus == Starting)) - { - return currentStatus; - } - try - { - lock (compass) - { - watchers.Add(getCompassId, this); - compass.CurrentValueChanged += watchers[getCompassId].compass_CurrentValueChanged; - compass.Start(); - this.SetStatus(Starting); - } - } - catch (Exception) - { - this.SetStatus(ErrorFailedToStart); - } - return currentStatus; - } - - public void startWatch(string options) - { - if (!DeviceCompass.IsSupported) - { - DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, Not_Supported)); - } - - try - { - compassOptions = JSON.JsonHelper.Deserialize(options); - } - catch (Exception ex) - { - this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message)); - return; - } - - if (string.IsNullOrEmpty(compassOptions.Id)) - { - this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); - return; - } - - try - { - lock (compass) - { - watchers.Add(compassOptions.Id, this); - compass.CurrentValueChanged += watchers[compassOptions.Id].compass_CurrentValueChanged; - compass.Start(); - this.SetStatus(Starting); - } - } - catch (Exception) - { - this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ErrorFailedToStart)); - return; - } - } - - public void stopWatch(string options) - { - try - { - compassOptions = JSON.JsonHelper.Deserialize(options); - } - catch (Exception ex) - { - this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message)); - return; - } - - if (string.IsNullOrEmpty(compassOptions.Id)) - { - this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); - return; - } - - if (currentStatus != Stopped) - { - lock (compass) - { - Compass watcher = watchers[compassOptions.Id]; - compass.CurrentValueChanged -= watcher.compass_CurrentValueChanged; - watchers.Remove(compassOptions.Id); - watcher.Dispose(); - } - } - this.SetStatus(Stopped); - - this.DispatchCommandResult(); - } - - void compass_Calibrate(object sender, Microsoft.Devices.Sensors.CalibrationEventArgs e) - { - //throw new NotImplementedException(); - // TODO: pass calibration error to JS - } - - void compass_CurrentValueChanged(object sender, Microsoft.Devices.Sensors.SensorReadingEventArgs e) - { - this.SetStatus(Running); - if (compass.IsDataValid) - { - // trueHeading :: The heading in degrees from 0 - 359.99 at a single moment in time. - // magneticHeading:: The heading relative to the geographic North Pole in degrees 0 - 359.99 at a single moment in time. - // A negative value indicates that the true heading could not be determined. - // headingAccuracy :: The deviation in degrees between the reported heading and the true heading. - //rawMagnetometerReading = e.SensorReading.MagnetometerReading; - - //Debug.WriteLine("Compass Result :: " + GetHeadingFormatted(e.SensorReading)); - - PluginResult result = new PluginResult(PluginResult.Status.OK, GetHeadingFormatted(e.SensorReading)); - result.KeepCallback = true; - - DispatchCommandResult(result); - } - } - - /// - /// Sets current status - /// - /// current status - private void SetStatus(int status) - { - currentStatus = status; - } - - } -} http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/640e5051/templates/standalone/config.xml ---------------------------------------------------------------------- diff --git a/templates/standalone/config.xml b/templates/standalone/config.xml index 93ac43a..715c7d0 100644 --- a/templates/standalone/config.xml +++ b/templates/standalone/config.xml @@ -24,7 +24,6 @@ -