Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: changed the Message class to accept the List of Strings. #950

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/bademagic_module/bluetooth/bluetooth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/bademagic_module/models/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> text;
final bool flash;
final bool marquee;
final Speed speed;
Expand Down
22 changes: 22 additions & 0 deletions lib/bademagic_module/utils/converters.dart
Original file line number Diff line number Diff line change
@@ -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<String> messageTohex(String message) {
List<String> 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;
}
}
8 changes: 7 additions & 1 deletion lib/providers/badge_message_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down
Loading