User manual

AOAA Kit Software User’s Guide
Page 37
Copyright 2012 © Embedded Artists AB
6.1.4 Message Identifier in the Accessory
Add a new message identifier in the accessory by opening the AndroidAccessoryHost.c file and define
a new constant with a unique ID. See how these defines are related to the constants in the
AccessoryControl.java file
/*
* Message indexes for messages sent to the device
*/
#define CMD_TRIMPOT (0)
#define CMD_BTN_1 (1)
#define CMD_BTN_2 (2)
/*
* Message indexes for messages sent from the device
*/
#define CMD_RGB_LED6 (10)
#define CMD_RGB_LED7 (11)
6.1.5 Receive a New Message in the Accessory
Locate the processCommand function in the AndroidAccessoryHost.c file and add processing of the
new message.
static void processCommand(uint8_t cmd, uint8_t hi, uint8_t lo)
{
switch (cmd) {
case CMD_RGB_LED6:
if (lo != 0) {
on = hi;
}
else {
off = hi;
}
rgb_setLeds(LED_6, on, off);
break;
case CMD_RGB_LED7:
if (lo != 0) {
on = hi;
}
else {
off = hi;
}
rgb_setLeds(LED_7, on, off);
break;
6.1.6 Send a New Message from the Accessory
The Monitor_Task function in the AndroidAccessoryHost.c file is called regularly to check if a state has
been changed that the Android device should be notified about. If a new peripheral is to be monitored
and messages sent to the Android device add it in the Montor_Task function.
void Monitor_Task(void)
{
uint8_t data[2];
uint8_t joy = 0;
...
if (getMsTicks() > lastTrimpotCheck + 50) {
uint16_t v = trimpot_get();
if (v != lastTrimpot) {
lastTrimpot = v;