Пример #1
0
 /// <summary> Get the Pebble's version info.  </summary>
 /// <param name="async">If true, return immediately.  If false, wait until the response
 /// has been received.</param>
 public void GetVersion(Boolean async = false)
 {
     byte[] data = { 0 };
     sendMessage(Endpoints.VERSION, data);
     if (!async)
     {
         var wait = new EndpointSync <MessageReceivedEventArgs>(this, Endpoints.VERSION);
         wait.WaitAndReturn(timeout: 5000);
     }
 }
Пример #2
0
 /// <summary>
 /// Fetch the contents of the Appbank.
 /// </summary>
 /// <param name="async">When true, this returns null immediately.  Otherwise it waits for the event and sends
 /// the appropriate AppbankContentsReceivedEventArgs.</param>
 /// <returns></returns>
 public AppbankContentsReceivedEventArgs GetAppbankContents(bool async = false)
 {
     sendMessage(Endpoints.APP_MANAGER, new byte[] { 1 });
     if (!async)
     {
         var wait = new EndpointSync <AppbankContentsReceivedEventArgs>(this, Endpoints.APP_MANAGER);
         return(wait.WaitAndReturn());
     }
     else
     {
         return(null);
     }
 }
Пример #3
0
 /// <summary>
 /// Get the time from the connected Pebble.
 /// </summary>
 /// <param name="async">When true, this returns null immediately.  Otherwise it waits for the event and sends
 /// the appropriate TimeReceivedEventArgs.</param>
 /// <returns>A TimeReceivedEventArgs with the time, or null.</returns>
 public TimeReceivedEventArgs GetTime(bool async = false)
 {
     byte[] data = { 0 };
     sendMessage(Endpoints.TIME, data);
     if (!async)
     {
         var wait = new EndpointSync <TimeReceivedEventArgs>(this, Endpoints.TIME);
         return(wait.WaitAndReturn());
     }
     else
     {
         return(null);
     }
 }
Пример #4
0
            public void init()
            {
                if (state_ != PutBytesState.NotStarted)
                {
                    HasError = true;
                    throw new Exception("Already init()ed");
                }
                byte[] data = Util.Pack("!bIbb", 1, buffer_.Length, transferType_, index_);
                pebble_.RegisterEndpointCallback(Endpoints.PUT_BYTES, PutBytesReceived);
                pebble_.sendMessage(Endpoints.PUT_BYTES, data);
                var wait = new EndpointSync <AppbankInstallMessageEventArgs>(pebble_, Endpoints.PUT_BYTES);

                state_ = PutBytesState.WaitForToken;
            }
Пример #5
0
        /// <summary>
        /// Remove an app from the Pebble, using an App instance retrieved from the Appbank.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="async">When true, this returns null immediately.  Otherwise it waits for the event and sends
        /// the appropriate AppbankInstallMessageEventArgs.</param>
        /// <returns></returns>
        public AppbankInstallMessageEventArgs RemoveApp(AppBank.App app, bool async = false)
        {
            var msg = Util.Pack("!bII", 2, app.ID, app.Index);

            sendMessage(Endpoints.APP_MANAGER, msg);
            if (!async)
            {
                var wait = new EndpointSync <AppbankInstallMessageEventArgs>(this, Endpoints.APP_MANAGER);
                return(wait.WaitAndReturn());
            }
            else
            {
                return(null);
            }
        }
Пример #6
0
        /// <summary> Send the Pebble a ping. </summary>
        /// <param name="cookie"></param>
        /// <param name="async">If true, return null immediately and let the caller wait for a PING event.  If false,
        /// wait for the reply and return the PingReceivedEventArgs.</param>
        public PingReceivedEventArgs Ping(UInt32 cookie = 0, Boolean async = false)
        {
            byte[] _cookie = new byte[5];
            // No need to worry about endianness as it's sent back byte for byte anyway.
            Array.Copy(BitConverter.GetBytes(cookie), 0, _cookie, 1, 4);

            sendMessage(Endpoints.PING, _cookie);
            if (!async)
            {
                var wait = new EndpointSync <PingReceivedEventArgs>(this, Endpoints.PING);
                return(wait.WaitAndReturn(timeout: 10000));
            }
            else
            {
                return(null);
            }
        }
Пример #7
0
        /// <summary> Recurring prod to check whether the Pebble is still connected and responding.
        /// </summary>
        /// <remarks>
        /// Ugly hack?  Yes.  It might be possible to do this more properly with the 32feet.NET bt lib.
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void pingTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (Alive)
            {
                byte[] data = { 0 };

                try
                {
                    sendMessage(Endpoints.TIME, data);
                    var wait = new EndpointSync <TimeReceivedEventArgs>(this, Endpoints.TIME);
                    wait.WaitAndReturn(timeout: PingTimeout);
                }
                catch (TimeoutException)
                {
                    Disconnect();
                }
            }
        }