From 7d4936df294f50fff445d29fcd48f39c3b20e83f Mon Sep 17 00:00:00 2001 From: Jhalakupadhyay Date: Sun, 16 Jun 2024 15:10:45 +0530 Subject: [PATCH] Chore:Changed the Message class to accept the List of Strings. --- lib/bademagic_module/bluetooth/bluetooth.dart | 4 ++-- lib/bademagic_module/models/messages.dart | 2 +- lib/bademagic_module/utils/converters.dart | 22 +++++++++++++++++++ lib/providers/badge_message_provider.dart | 8 ++++++- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 lib/bademagic_module/utils/converters.dart diff --git a/lib/bademagic_module/bluetooth/bluetooth.dart b/lib/bademagic_module/bluetooth/bluetooth.dart index 51ba9f389..c782f96e4 100644 --- a/lib/bademagic_module/bluetooth/bluetooth.dart +++ b/lib/bademagic_module/bluetooth/bluetooth.dart @@ -60,8 +60,8 @@ class BadgeMagicBluetooth { (results) async { if (results.isNotEmpty) { foundDevice = results.firstWhere( - (result) => - result.device.remoteId.toString() == "50:54:7B:63:10:F5", + (result) => result.advertisementData.serviceUuids + .contains(Guid("0000fee0-0000-1000-8000-00805f9b34fb")), ); if (foundDevice != null) { await connectToDevice(foundDevice!, data); diff --git a/lib/bademagic_module/models/messages.dart b/lib/bademagic_module/models/messages.dart index efbbff550..dc60cf540 100644 --- a/lib/bademagic_module/models/messages.dart +++ b/lib/bademagic_module/models/messages.dart @@ -2,7 +2,7 @@ import 'package:badgemagic/bademagic_module/models/mode.dart'; import 'package:badgemagic/bademagic_module/models/speed.dart'; class Message { - final String text; + final List text; final bool flash; final bool marquee; final Speed speed; diff --git a/lib/bademagic_module/utils/converters.dart b/lib/bademagic_module/utils/converters.dart new file mode 100644 index 000000000..891dae668 --- /dev/null +++ b/lib/bademagic_module/utils/converters.dart @@ -0,0 +1,22 @@ +import 'package:badgemagic/bademagic_module/utils/data_to_bytearray_converter.dart'; + +class Converters { + //this function converts the user entered message to hex + //compares the message to the map of characters and returns the hex value of the character + //then adds the hexstring to the list + //thus generating the hex value of the message + static List messageTohex(String message) { + List messages = []; + int i = 0; + while (i < message.length) { + var ch = message[i]; + logger.d("ch = $ch"); + if (charCodes.containsKey(ch)) { + messages.add(charCodes[ch]!); + } + i++; + } + logger.d("message to hex = $message"); + return messages; + } +} diff --git a/lib/providers/badge_message_provider.dart b/lib/providers/badge_message_provider.dart index a93bff283..e8f83574c 100644 --- a/lib/providers/badge_message_provider.dart +++ b/lib/providers/badge_message_provider.dart @@ -3,6 +3,7 @@ import 'package:badgemagic/bademagic_module/models/data.dart'; import 'package:badgemagic/bademagic_module/models/messages.dart'; import 'package:badgemagic/bademagic_module/models/mode.dart'; import 'package:badgemagic/bademagic_module/models/speed.dart'; +import 'package:badgemagic/bademagic_module/utils/converters.dart'; import 'package:flutter/material.dart'; import 'package:logger/logger.dart'; @@ -36,7 +37,12 @@ class BadgeMessageProvider extends ChangeNotifier { void generateMessage( String text, bool flash, bool marq, Speed speed, Mode mode) { Data data = Data(messages: [ - Message(text: text, flash: flash, marquee: marq, speed: speed, mode: mode) + Message( + text: Converters.messageTohex(text), + flash: flash, + marquee: marq, + speed: speed, + mode: mode) ]); dataFormed(data); transferData(data);