Skip to content

Instantly share code, notes, and snippets.

@forslund
Created December 18, 2019 07:06
Show Gist options
  • Save forslund/f4fb0698ed508b6db553ea2b153bd34a to your computer and use it in GitHub Desktop.
Save forslund/f4fb0698ed508b6db553ea2b153bd34a to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
void show_icon(const char *code)
{
static char msgHold[31] = {0};
char icon[91];
//Arduinos have a hardcoded limit of 64 bytes for their serial input
//buffer. To get around this Mycroft sends large messages as two parts.
//check if first or second half of a message
//if it is, concatenate the message into one
if (code[strlen(code)-1] == '$')
{
if(msgHold[0] != 0) //if holding part of a messasge
{
strcpy(icon,msgHold);
strcat(icon,code);
icon[strlen(icon)-1] = 0;
msgHold[0] = 0;
}
else //hold part of a message
{
strcpy(msgHold, code);
return;
}
}
else
{
strcpy(icon, code);
}
printf("icon: %s\n", icon);
}
int main(void)
{
show_icon("AAAAAAAAAAA$");
show_icon("BBBBBBBBBBB$");
return 0;
}
ake@Woodstock:~/projects/c/test$ gcc mouth_process.c
ake@Woodstock:~/projects/c/test$ ./a.out
icon: AAAAAAAAAAA$BBBBBBBBBBB
ake@Woodstock:~/projects/c/test$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment