public static void sendLcdIdle() { var bitmap = createLcdIdle(); //Protocol.loadTemplate(0); BtProtocol.sendLcdBitmap(bitmap, MetaWatchService.WatchBuffers.IDLE); //Protocol.activateBuffer(); BtProtocol.updateDisplay(0); }
public static void addTextNotification(String text, VibratePattern vibratePattern, TimeSpan timeout) { var notification = new NotificationType(); notification.bitmap = BtProtocol.createTextBitmap(text); notification.timeout = timeout; if (vibratePattern == null) { notification.vibratePattern = new VibratePattern(false, 0, 0, 0); } else { notification.vibratePattern = vibratePattern; } notificationQueue.Add(notification); lastNotification = notification; processNotificationQueue(); }
void connect() { try { //Log.d(MetaWatch.TAG, "got Bluetooth socket"); //if (bluetoothSocket == null) //Log.d(MetaWatch.TAG, "Bluetooth socket is null"); var addr = BluetoothAddress.Parse("d0:37:61:c4:cb:25"); var serviceClass = BluetoothService.SerialPort; var ep = new BluetoothEndPoint(addr, serviceClass); bluetoothAdapter.Connect(ep); inputOutputStream = bluetoothAdapter.GetStream(); connectionState = ConnectionState.CONNECTED; BtProtocol.SendRtcNow(); BtProtocol.GetDeviceType(); } catch (IOException ioexception) { // Log.d(MetaWatch.TAG, ioexception.toString()); // sendToast(ioexception.toString()); } /*catch (SecurityException e) { * Log.d(MetaWatch.TAG, e.toString()); * } catch (NoSuchMethodException e) { * Log.d(MetaWatch.TAG, e.toString()); * } catch (IllegalArgumentException e) { * Log.d(MetaWatch.TAG, e.toString()); * } catch (IllegalAccessException e) { * Log.d(MetaWatch.TAG, e.toString()); * } catch (InvocationTargetException e) { * Log.d(MetaWatch.TAG, e.toString()); * }*/ }
public static void processNotificationQueue() { if (isSending) { return; } else { isSending = true; } Thread thread = new Thread(() => { if (notificationQueue.Count > 0) { MetaWatchService.watchState = MetaWatchService.WatchStates.NOTIFICATION; MetaWatchService.WatchModes.NOTIFICATION = true; } while (notificationQueue.Count > 0) { NotificationType notification = notificationQueue.ElementAt(0); //Protocol.loadTemplate(2); if (notification.bitmap != null) { BtProtocol.sendLcdBitmap(notification.bitmap, MetaWatchService.WatchBuffers.NOTIFICATION); } // else if (notification.array != null) // BtProtocol.sendLcdArray(notification.array, MetaWatchService.WatchBuffers.NOTIFICATION); // else if (notification.buffer != null) // BtProtocol.sendLcdBuffer(notification.buffer, MetaWatchService.WatchBuffers.NOTIFICATION); BtProtocol.updateDisplay(2); if (notification.vibratePattern._vibrate) { BtProtocol.vibrate(notification.vibratePattern.on, notification.vibratePattern.off, notification.vibratePattern.cycles); } // Log.d(MetaWatch.TAG, "notif bitmap sent from thread"); MetaWatchService.nap(notification.timeout); if (MetaWatchService.WatchModes.CALL == true) { isSending = false; return; } notificationQueue.RemoveAt(0); } isSending = false; exitNotification(); } ); thread.Start(); }
private void button3_Click(object sender, RoutedEventArgs e) { BtProtocol.UploadDiary(_diary); }
private void Button1Click(object sender, RoutedEventArgs e) { var addr = BluetoothAddress.Parse("d0:37:61:c4:cb:25"); var serviceClass = BluetoothService.SerialPort; var ep = new BluetoothEndPoint(addr, serviceClass); _bluetoothClient = new BluetoothClient(); _bluetoothClient.Connect(ep); // Stream peerStream = cli.GetStream(); BtProtocol.OutStream = _bluetoothClient.GetStream(); MetaWatchService.inputOutputStream = BtProtocol.OutStream; BtProtocol.SendRtcNow(); BtProtocol.GetDeviceType(); BtProtocol.OutStream.Flush(); _readThread = new Thread(() => { while (true) { BtProtocol.OutStream.ReadTimeout = 2000000; var startByte = BtProtocol.OutStream.ReadByte(); if (startByte != 1) { continue; } var msgLen = BtProtocol.OutStream.ReadByte(); if (msgLen < 6) { MessageBox.Show("Ошибка приёма"); continue; } var msgType = BtProtocol.OutStream.ReadByte(); var msgOptions = BtProtocol.OutStream.ReadByte(); var msgDataLen = msgLen - 6; var data = new byte[msgDataLen]; BtProtocol.OutStream.Read(data, 0, msgDataLen); //CRC BtProtocol.OutStream.ReadByte(); BtProtocol.OutStream.ReadByte(); switch (msgType) { case (int)BtMessage.Message.GetDeviceTypeResponse: switch (data[0]) { case 2: Dispatcher.Invoke(new Action(delegate { sbiConnect.Content = "Подключено!"; }), System.Windows.Threading.DispatcherPriority.Normal); //MessageBox.Show("Цифровые!"); break; } break; case (int)BtMessage.Message.ButtonEventMsg: if ((data[0] & 0x1) == 0x1) { MessageBox.Show("A!"); } if ((data[0] & 0x2) == 0x2) { MessageBox.Show("B!"); } if ((data[0] & 0x4) == 0x4) { MessageBox.Show("C!"); } if ((data[0] & 0x8) == 0x8) { MessageBox.Show("D!"); } if ((data[0] & 0x20) == 0x20) { MessageBox.Show("E!"); } if ((data[0] & 0x40) == 0x40) { MessageBox.Show("F!"); } if ((data[0] & 0x80) == 0x80) { MessageBox.Show("S!"); } break; case (int)BtMessage.Message.ReadBatteryVoltageResponse: var powerGood = data[0]; var batteryCharging = data[1]; var voltage = (data[3] << 8) | data[2]; var voltageAverage = (data[5] << 8) | data[4]; MessageBox.Show(string.Format("volt:{0} avg:{1} powerGood:{2} batteryCharging: {3}", voltage / 1000f, voltageAverage / 1000f, powerGood, batteryCharging)); break; } } }); _readThread.Start(); // var buf = new byte[2]; // var readLen = peerStream.Read(buf, 0, buf.Length); // if (readLen == 2) // { // MessageBox.Show(buf[1].ToString()); // } // peerStream.Write/Read ... // //e.g. /*var buf = new byte[1000]; * var readLen = peerStream.Read(buf, 0, buf.Length); * if (readLen == 0) * { * Console.WriteLine("Connection is closed"); * } * else * * { * * Console.WriteLine("Recevied {0} bytes", readLen); * * }*/ }
private void Button5Click(object sender, RoutedEventArgs e) { BtProtocol.AccelerometerAccess(); BtProtocol.OutStream.Flush(); }
private void Button4Click(object sender, RoutedEventArgs e) { BtProtocol.DisableAccelerometer(); BtProtocol.OutStream.Flush(); }
private void Button2Click(object sender, RoutedEventArgs e) { BtProtocol.ReadBatteryVoltage(); BtProtocol.OutStream.Flush(); }
void readFromDevice() { try { var bytes = new byte[256]; //Log.d(MetaWatch.TAG, "before blocking read"); inputOutputStream.Read(bytes, 0, 256); // wakeLock.acquire(5000); // print received var str = "received: "; int len = (bytes[1] & 0xFF); // Log.d(MetaWatch.TAG, "packet length: " + len); /* * for (int i = 0; i < len; i ++) { * //str+= Byte.toString(bytes[i]) + ", "; * str+= "0x" + ((bytes[i] & 0xff) + 0x100, 16).substring(1) + ", "; * } * Log.d(MetaWatch.TAG, str); */ switch (bytes[2]) { case 0x02: // Log.d(MetaWatch.TAG, "received: device type response"); break; case 0x31: // Log.d(MetaWatch.TAG, "received: nval response"); break; case 0x33: // Log.d(MetaWatch.TAG, "received: status change event"); break; } /* * if (bytes[2] == 0x31) { // nval response * if (bytes[3] == 0x00) // success * if (bytes[4] == 0x00) // set to 12 hour format * Protocol.setNvalTime(true); * } */ if (bytes[2] == 0x33) { // status change event if (bytes[4] == 0x11) { // Log.d(MetaWatch.TAG, "notify scroll request"); // synchronized (Notification.scrollRequest) // Notification.scrollRequest.notify(); } } if (bytes[4] == 0x10) { // Log.d(MetaWatch.TAG, "scroll completed"); } if (bytes[2] == 0x34) // button press // Log.d(MetaWatch.TAG, "button event"); { pressedButton(bytes[3]); } if (bytes[2] == 0x02) // device type { { if (Preferences.idleMusicControls) { BtProtocol.enableMediaButtons(); } //else //Protocol.disableMediaButtons(); if (Preferences.idleReplay) { BtProtocol.enableReplayButton(); } //else //Protocol.disableReplayButton(); BtProtocol.configureMode(); ////Idle.toIdle(this); ////Idle.updateLcdIdle(this); BtProtocol.queryNvalTime(); } } } catch (IOException e) { if (connectionState != ConnectionState.DISCONNECTING) { connectionState = ConnectionState.CONNECTING; } } }