コード例 #1
0
 public EndpointSync(Pebble pebble, Pebble.Endpoints endpoint)
 {
     this.pebble   = pebble;
     this.endpoint = endpoint;
     Triggered     = false;
     pebble.RegisterEndpointCallback(endpoint, trigger);
 }
コード例 #2
0
        /// <summary> Returns one of the paired Pebbles, or a specific one
        /// when a four-character ID is provided.  Convenience function for
        /// when you know there's only one, mostly.
        /// </summary>
        /// <param name="pebbleid"></param>
        /// <returns></returns>
        /// <exception cref="pebble.PebbleNotFoundException">When no Pebble or no Pebble of the
        /// specified id was found.</exception>
        public static Pebble GetPebble(String pebbleid = null)
        {
            List <Pebble> peblist = DetectPebbles();

            if (peblist.Count == 0)
            {
                throw new PebbleNotFoundException("No paired Pebble found.");
            }

            if (pebbleid == null)
            {
                return(peblist[0]);
            }
            else
            {
                Pebble ret = peblist.FirstOrDefault((peb) => peb.PebbleID == pebbleid);
                if (ret == null)
                {
                    throw new PebbleNotFoundException(pebbleid);
                }
                else
                {
                    return(ret);
                }
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: peterrus/flint
 static void DeleteApp(Pebble pebble)
 {
     var applist = pebble.GetAppbankContents().AppBank.Apps;
     Console.WriteLine("Choose an app to remove");
     AppBank.App result = SharpMenu<AppBank.App>.WriteAndPrompt(applist);
     AppbankInstallMessageEventArgs ev = pebble.RemoveApp(result);
     Console.WriteLine(ev.MsgType);
 }
コード例 #4
0
ファイル: PutBytes.cs プロジェクト: sticks/flint
 public PutBytesClient(Pebble pebble, uint index, PutBytesType transferType, byte[] buffer)
 {
     pebble_ = pebble;
     index_ = index;
     transferType_ = transferType;
     buffer_ = buffer;
     state_ = PutBytesState.NotStarted;
     token_ = 0;
     left_ = 0;
 }
コード例 #5
0
ファイル: PebbleEventArgs.cs プロジェクト: peterrus/flint
 public AppbankInstallMessageEventArgs(Pebble.Endpoints endpoint, byte[] payload)
     : base(endpoint, payload)
 {
     if (BitConverter.IsLittleEndian)
     {
         Array.Reverse(Payload, 1, 4);
     }
     uint result = BitConverter.ToUInt32(Payload, 1);
     MsgType = (MessageType)result;
 }
コード例 #6
0
ファイル: PutBytes.cs プロジェクト: sticks/flint
 public PutBytesClient(Pebble pebble, uint index, PutBytesType transferType, byte[] buffer)
 {
     pebble_       = pebble;
     index_        = index;
     transferType_ = transferType;
     buffer_       = buffer;
     state_        = PutBytesState.NotStarted;
     token_        = 0;
     left_         = 0;
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: sticks/flint
        static void AddApp(Pebble pebble, string watch=null, bool removeFirst = false)
        {
            string watchdir=null;
            if (String.IsNullOrEmpty(watch))
            {
                watchdir = ConfigurationManager.AppSettings["watch-dir"];
                if (watchdir == null)
                {
                    Console.WriteLine("Missing .config entry for 'watch-dir'");
                    return;
                }
                if (!Directory.Exists(watchdir))
                {
                    Console.WriteLine("watch-dir not found: {0}", watchdir);
                    return;
                }
            }
            var appbank = pebble.GetAppbankContents().AppBank;
            var applist = appbank.Apps;
            if (applist.Count == appbank.Size)
            {
                Console.WriteLine("All {0} banks are full", appbank.Size);
                return;
            }
            try
            {
                if (String.IsNullOrEmpty(watch))
                {
                    Console.WriteLine("Choose an app to install");
                    var watches = Directory.GetFiles(watchdir, "*.pbw");
                    watch = SharpMenu<string>.WriteAndPrompt(watches);
                    watch = Path.Combine(watchdir, watch);
                }
                if (removeFirst)
                {
                    PebbleBundle pb = new PebbleBundle(watch);
                    var app2remove = applist.Find(delegate(AppBank.App app) { return app.Name == pb.Application.AppName; });
                    if (app2remove.Name != null)
                    {
                        Console.WriteLine("Removing existing...");
                        pebble.RemoveApp(app2remove);
                        Thread.Sleep(2000); // let things settle
                    }

                }
                Console.WriteLine("Installing...");
                pebble.InstallApp(watch, applist.Count);
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #8
0
ファイル: Flintlock.cs プロジェクト: barometz/flintlock
 private void Connect_Click(object sender, EventArgs e)
 {
     if (pebble != null)
     {
         pebble.Disconnect();
         pebble = null;
     }
     else
     {
         ConnectToSelectedPebble();
     }
     DisEnableControls();
 }
コード例 #9
0
ファイル: PebbleEventArgs.cs プロジェクト: peterrus/flint
        public LogReceivedEventArgs(Pebble.Endpoints endpoint, byte[] payload)
            : base(endpoint, payload)
        {
            byte[] metadata = new byte[8];
            byte msgsize;
            Array.Copy(Payload, metadata, 8);
            /*
             * Unpack the metadata.  Eight bytes:
             * 0..3 -> integer timestamp
             * 4    -> Message level (severity)
             * 5    -> Size of the message
             * 6..7 -> Line number (?)
             */
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(metadata);
                Timestamp = Util.TimestampToDateTime(BitConverter.ToInt32(metadata, 4));
                Level = metadata[3];
                msgsize = metadata[2];
                LineNo = BitConverter.ToInt16(metadata, 0);
            }
            else
            {
                Timestamp = Util.TimestampToDateTime(BitConverter.ToInt32(metadata, 0));
                Level = metadata[4];
                msgsize = metadata[5];
                LineNo = BitConverter.ToInt16(metadata, 6);
            }
            // Now to extract the actual data
            byte[] _filename = new byte[16];
            byte[] _data = new byte[msgsize];
            Array.Copy(Payload, 8, _filename, 0, 16);
            Array.Copy(Payload, 24, _data, 0, msgsize);

            Filename = Encoding.UTF8.GetString(_filename);
            Message = Encoding.UTF8.GetString(_data);
        }
コード例 #10
0
ファイル: Flintlock.cs プロジェクト: barometz/flintlock
 /// <summary>
 /// Connect to the Pebble that's currently selected in the combobox, if any.
 /// </summary>
 private void ConnectToSelectedPebble()
 {
     pebble = PebbleList.SelectedItem as Pebble;
     if (pebble != null)
     {
         pebble.OnConnect += pebble_OnConnect;
         pebble.OnDisconnect += pebble_OnDisconnect;
         pebble.MediaControlReceived += pebble_MediaControlReceived;
         try
         {
             pebble.Connect();
         }
         catch (IOException e)
         {
             MessageBox.Show("Failed to connect: " + e.Message);
             pebble = null;
         }
         catch (UnauthorizedAccessException e)
         {
             MessageBox.Show("Failed to connect: " + e.Message);
             pebble = null;
         }
     }
 }
コード例 #11
0
 void VersionReceived(object sender, MessageReceivedEventArgs e)
 {
     this.Firmware         = Pebble.ParseVersion(e.Payload.Skip(1).Take(47).ToArray());
     this.RecoveryFirmware = Pebble.ParseVersion(e.Payload.Skip(48).Take(47).ToArray());
 }
コード例 #12
0
ファイル: PebbleEventArgs.cs プロジェクト: peterrus/flint
        /// <summary> Create a new TimeReceivedEventArgs.
        /// </summary>
        /// <param name="payload">Must be 5 bytes long.  The latter four are interpreted as a timestamp.</param>
        public TimeReceivedEventArgs(Pebble.Endpoints endpoint, byte[] payload)
            : base(endpoint, payload)
        {
            if (Payload.Length != 5)
            {
                throw new ArgumentOutOfRangeException("payload", "TIME payload must be 5 bytes, the latter four being the timestamp.");
            }

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(Payload, 1, 4);
            }

            int timestamp = BitConverter.ToInt32(Payload, 1);
            Time = Util.TimestampToDateTime(timestamp);
        }
コード例 #13
0
ファイル: PebbleEventArgs.cs プロジェクト: peterrus/flint
 /// <summary> Create new eventargs for a PING. </summary>
 /// <param name="payload">The payload. Has to be five bytes long, 
 /// otherwise something's wrong.</param>
 public PingReceivedEventArgs(Pebble.Endpoints endpoint, byte[] payload)
     : base(endpoint, payload)
 {
     if (Payload.Length != 5)
     {
         throw new ArgumentOutOfRangeException("payload", "Payload for PING must be five bytes");
     }
     // No need to worry about endianness as ping cookies are echoed byte for byte.
     Cookie = BitConverter.ToUInt32(Payload, 1);
 }
コード例 #14
0
ファイル: PebbleEventArgs.cs プロジェクト: peterrus/flint
 public MessageReceivedEventArgs(Pebble.Endpoints endpoint, byte[] payload)
 {
     Endpoint = endpoint;
     Payload = new byte[payload.Length];
     payload.CopyTo(Payload, 0);
 }
コード例 #15
0
ファイル: PebbleEventArgs.cs プロジェクト: peterrus/flint
 /// <summary> Create a new media control event.  The payload should be 
 /// 1 byte long.
 /// </summary>
 /// <param name="payload"></param>
 public MediaControlReceivedEventArgs(Pebble.Endpoints endpoint, byte[] payload)
     : base(endpoint, payload)
 {
     Command = (Pebble.MediaControls)Payload[0];
 }
コード例 #16
0
ファイル: Flintlock.cs プロジェクト: barometz/flintlock
 private void pebble_OnConnect(object sender, EventArgs e)
 {
     // Dirtyfix for when things get out of sync for reasons yet to be found
     if (pebble == null)
     {
         return;
     }
     WatchfacePic.Image = Properties.Resources.watchface;
     Connect.Text = "Dis&connect";
     PebbleList.Enabled = false;
     try
     {
         pebble.GetVersion();
         Scan.Enabled = false;
         SetVersionInfo();
         Properties.Settings.Default.LastKnownPebble = pebble.PebbleID;
         Properties.Settings.Default.LastKnownPebblePort = pebble.Port;
         // Don't really like saving *all* settings here
         Properties.Settings.Default.Save();
         pebbleNameToolStripMenuItem.Text = pebble.ToString();
         disconnectToolStripMenuItem.Enabled = true;
         notifyIcon.Text = "Connected (" + pebble.PebbleID + ")";
     }
     // Some stuff that can go wrong while connecting...
     catch (TimeoutException err)
     {
         pebble.Disconnect();
         MessageBox.Show(err.Message, "Connection timeout",
             MessageBoxButtons.OK, MessageBoxIcon.Error);
         pebble = null;
     }
     catch (InvalidOperationException err)
     {
         pebble.Disconnect();
         MessageBox.Show(err.Message + "\nTry scanning again.", "Connection failed",
             MessageBoxButtons.OK, MessageBoxIcon.Error);
         pebble = null;
     }
 }
コード例 #17
0
ファイル: Program.cs プロジェクト: barometz/flint
 static async Task DeleteApp(Pebble pebble)
 {
     var applist = (await pebble.GetAppbankContentsAsync()).AppBank.Apps;
     Console.WriteLine("Choose an app to remove");
     AppBank.App result = SharpMenu<AppBank.App>.WriteAndPrompt(applist);
     AppbankInstallResponse ev = await pebble.RemoveAppAsync(result);
     Console.WriteLine(ev.MsgType);
 }
コード例 #18
0
ファイル: Program.cs プロジェクト: sticks/flint
 private static void SetTime(Pebble pebble)
 {
     Console.WriteLine("Enter time <current>:");
     var time = Console.ReadLine();
     if (String.IsNullOrEmpty(time))
         pebble.SetTime(DateTime.Now);
     else
     {
         DateTime result;
         if (DateTime.TryParse(time, out result))
         {
             pebble.SetTime(result);
         }
         else
         {
             Console.WriteLine("invalid time");
         }
     }
 }
コード例 #19
0
ファイル: Flintlock.cs プロジェクト: barometz/flintlock
 /// <summary>
 /// Reset the UI to the disconnected state.  To be called through Invoke.
 /// </summary>
 private void DisconnectUIUpdate()
 {
     WatchfacePic.Image = Properties.Resources.watchface_off;
     pebbleNameToolStripMenuItem.Text = "Disconnected";
     disconnectToolStripMenuItem.Enabled = false;
     notifyIcon.Text = "Disconnected";
     ResetVersionInfo();
     pebble = null;
     DisEnableControls();
 }
コード例 #20
0
ファイル: PebbleEventArgs.cs プロジェクト: peterrus/flint
 public AppbankContentsReceivedEventArgs(Pebble.Endpoints endpoint, byte[] payload)
     : base(endpoint, payload)
 {
     AppBank = new AppBank(Payload);
 }
コード例 #21
0
ファイル: Flintlock.cs プロジェクト: barometz/flintlock
 /// <summary>
 /// Background task for Pebble autodetect.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void listUpdateWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         List<Pebble> peblist = Pebble.DetectPebbles();
         e.Result = peblist;
     }
     catch (PlatformNotSupportedException)
     {
         MessageBox.Show("Failed to connect: make sure your Bluetooth adapter is connected and enabled.");
         pebble = null;
     }
 }