Skip to content

Instantly share code, notes, and snippets.

@KorkyraBoyCRO
Last active August 29, 2019 06:32
Show Gist options
  • Save KorkyraBoyCRO/95a47cfae42de9f6c54a to your computer and use it in GitHub Desktop.
Save KorkyraBoyCRO/95a47cfae42de9f6c54a to your computer and use it in GitHub Desktop.
ANCS ON SERIAL MONITOR
#include <lib_aci.h>
#include <SPI.h>
#include <EEPROM.h>
#include <notif.h>
Notif notif(10,2);
ancs_notification_t* current_notif = NULL;
boolean connected = false;
void ancs_connected() {
connected = true;
}
void ancs_disconnected() {
connected = false;
}
void ancs_reset() {
connected = false;
Serial.println(" Bond Cleared ");
Serial.println("Please Reset");
}
void ancs_notifications(ancs_notification_t* notif) {
Serial.print (F("["));
if ((notif->flags & ANCS_EVT_FLAG_SILENT) == ANCS_EVT_FLAG_SILENT)
Serial.print(F("-"));
else if ((notif->flags & ANCS_EVT_FLAG_IMPORTANT) == ANCS_EVT_FLAG_IMPORTANT)
Serial.print(F("!"));
else
Serial.print(" ");
Serial.print (F("] "));
Serial.print(F("Notif #")); Serial.print( notif->uid); Serial.print( F(" ; from: '"));
#ifdef ANCS_USE_APP
Serial.print( notif->app);
#endif
Serial.println( F("'"));
Serial.print(F(" category: "));
switch (notif->category) {
case ANCS_CATEGORY_INCOMING_CALL:
Serial.println(F("incoming call"));
break;
case ANCS_CATEGORY_MISSED_CALL:
Serial.println(F("missed call"));
break;
case ANCS_CATEGORY_VOICEMAIL:
Serial.println(F("voicemail call"));
break;
case ANCS_CATEGORY_SOCIAL:
Serial.println(F("social msg"));
break;
case ANCS_CATEGORY_OTHER:
Serial.println(F("other"));
break;
case ANCS_CATEGORY_SCHEDULE:
Serial.println(F("schedule"));
break;
case ANCS_CATEGORY_EMAIL:
Serial.println(F("email"));
break;
case ANCS_CATEGORY_NEWS :
Serial.println(F("news"));
break;
case ANCS_CATEGORY_HEALTH_FITNESS:
Serial.println(F("health & fitness"));
break;
case ANCS_CATEGORY_BUSINESS_FINANCE:
Serial.println(F("business & finance"));
break;
case ANCS_CATEGORY_LOCATION:
Serial.println(F("location"));
break;
case ANCS_CATEGORY_ENTERTAINMENT:
Serial.println(F("entertainment"));
break;
default:
Serial.print(F("unknown: "));
Serial.println(notif->category, DEC);
break;
//return;
}
Serial.print(F(" title: '")); Serial.print( notif->title ); Serial.println("'");
#ifdef ANCS_USE_SUBTITLE
Serial.print(F(" subtitle: '")); Serial.print( notif->subtitle ); Serial.println("'");
#endif
Serial.print(F(" message: '")); Serial.print( notif->message ); Serial.println("'");
current_notif = notif;
}
void eepromWrite(int address, uint8_t value)
{
eeprom_write_byte((unsigned char *) address, value);
}
void setup(void)
{
Serial.begin(115200);
//Wait until the serial port is available (useful only for the Leonardo)
//As the Leonardo board is not reseted every time you open the Serial Monitor
/*
#if defined (__AVR_ATmega32U4__)
while(!Serial)
{}
#endif*/
//If things get really crazy, uncomment this line. It wipes the saved EEPROM information for the Nordic chip. Good to do this if the services.h file gets updated.
//After it is wiped, comment and reupload.
//eepromWrite(0, 0xFF);
Serial.println(F("Arduino setup"));
notif.setup();
notif.set_notification_callback_handle(ancs_notifications);
notif.set_connect_callback_handle(ancs_connected);
notif.set_disconnect_callback_handle(ancs_disconnected);
notif.set_reset_callback_handle(ancs_reset);
Serial.print(" Apple iOS ");
Serial.print(" Notifications ");
}
void loop()
{
notif.ReadNotifications();
notif.set_notification_callback_handle(ancs_notifications);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment