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(); }
public static void sendLcdBitmap(Bitmap bitmap, MetaWatchService.WatchBuffers bufferType) { // var pixelArray = new byte[96*96]; // bitmap.pi // bitmap.getPixels(pixelArray, 0, 96, 0, 0, 96, 96); // sendLcdArray(bitmap, bufferType); }
static void sendLcdBuffer(byte[] buffer, MetaWatchService.WatchBuffers bufferType) { if (MetaWatchService.connectionState != MetaWatchService.ConnectionState.CONNECTED) return; int i = 0; if (bufferType == MetaWatchService.WatchBuffers.IDLE) i = 30; for (; i < 96; i += 2) { byte[] bytes = new byte[30]; bytes[0] = BtMessage.Start; bytes[1] = (byte) (bytes.Length+2); // packet length bytes[2] = (byte) BtMessage.Message.WriteBuffer; bytes[3] = (byte) bufferType; bytes[4] = (byte) i; // row A for (int j = 0; j < 12; j++) bytes[j + 5] = buffer[i * 12 + j]; bytes[4+13] = (byte) (i+1); // row B for (int j = 0; j < 12; j++) bytes[j + 5 + 13] = buffer[i * 12 + j + 12]; sendQueue.Add(bytes); } processSendQueue(); }
public static void sendLcdArray(Bitmap bitmap, MetaWatchService.WatchBuffers bufferType) { var send = new byte[1152]; var i = 0; for(var y = 0; y < 96; y++, i++) { var p = new byte[8]; for(var x = 0; x < 96; x += 8) { for (int j = 0; j < 8; j++) { if (bitmap.GetPixel(y, x) == System.Drawing.Color.White) p[j] = 0; else p[j] = 1; } } send[i] = (byte) (p[7] << 7 | p[6] << 6 | p[5] << 5 | p[4] << 4 | p[3] << 3 | p[2] << 2 | p[1] << 1 | p[0]); } sendLcdBuffer(send, bufferType); }