From 3f5d8cc3f1f66510386c7e6e616d8bf774978f64 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Apr 2017 13:57:13 +0700 Subject: [PATCH] handle title Unicode Bidirectional control --- .../examples/Peripheral/ancs/ancs.ino | 7 ++++-- .../Peripheral/ancs_oled/ancs_oled.ino | 23 +++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/ancs/ancs.ino b/libraries/Bluefruit52Lib/examples/Peripheral/ancs/ancs.ino index bd155cb9..70b6e6c2 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/ancs/ancs.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/ancs/ancs.ino @@ -114,7 +114,7 @@ void connect_callback(void) Serial.println("Found it"); // ANCS requires pairing to work, it makes sense to request security here as well - Serial.print("Attempt to bond/pair with iOS, please press PAIR on your phone ... "); + Serial.print("Attempt to PAIR with iOS, please press PAIR on your phone ... "); if ( Bluefruit.requestPairing() ) { Serial.println("Done"); @@ -139,10 +139,13 @@ void ancs_notification_callback(AncsNotification_t* notif) Serial.print(" | "); // Get notification Title + // iDevice often include Unicode "Bidirection Text Control" in the Title. + // Mostly are U+202D as beginning and U+202C as ending. You may want to remove them + // U+202D is E2-80-AD, U+202C is E2-80-AC in UTF-8 memset(buffer, 0, sizeof(buffer)); bleancs.getAttribute(notif->uid, ANCS_ATTR_TITLE, buffer, sizeof(buffer)); Serial.printf("%-14s | ", buffer); - + // Get notification Message memset(buffer, 0, sizeof(buffer)); bleancs.getAttribute(notif->uid, ANCS_ATTR_MESSAGE, buffer, sizeof(buffer)); diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/ancs_oled/ancs_oled.ino b/libraries/Bluefruit52Lib/examples/Peripheral/ancs_oled/ancs_oled.ino index e245706b..36bcd4c4 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/ancs_oled/ancs_oled.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/ancs_oled/ancs_oled.ino @@ -212,6 +212,26 @@ void displayNotification(int index) { notif->title[0] = 0; // invalid data if failed to receive } + else + { + // iDevice often include Unicode "Bidirection Text Control" in the Title. + // Mostly are U+202D as beginning and U+202C as ending. Let's remove them + char u202D[3] = { 0xE2, 0x80, 0xAD }; // U+202D in UTF-8 + char u202C[3] = { 0xE2, 0x80, 0xAC }; // U+202C in UTF-8 + + int len = strlen(notif->title); + + if ( 0 == memcmp(¬if->title[len-3], u202C, 3) ) + { + len -= 3; + notif->title[len] = 0; // chop ending U+202C + } + + if ( 0 == memcmp(notif->title, u202D, 3) ) + { + memmove(notif->title, notif->title+3, len-2); // move null-terminator as well + } + } } if ( notif->message[0] == 0 ) @@ -244,8 +264,7 @@ void displayNotification(int index) oled.println(" Btn C to DECLINE"); }else { - // Text size = 1, max char is 21 - // Text size = 2, max char is 10 + // Text size = 1, max char is 21. Text size = 2, max char is 10 char tempbuf[22]; sprintf(tempbuf, "%-15s %02d/%02d", notif->app_name, index+1, notifCount);