Last active
December 25, 2019 14:40
-
-
Save boochow/2165806796cd8695dd0f20b9b91c2d9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "command_responder.h" | |
#include <M5Stack.h> | |
#include <Avatar.h> | |
using namespace m5avatar; | |
Avatar avatar; | |
void InitResponder() { | |
M5.begin(); | |
M5.Lcd.fillScreen(BLACK); | |
avatar.init(); | |
avatar.setExpression(Expression::Sleepy); | |
} | |
void RespondToCommand(tflite::ErrorReporter* error_reporter, | |
int32_t current_time, const char* found_command, | |
uint8_t score, bool is_new_command) { | |
static int32_t last_timestamp = 0; | |
if (is_new_command) { | |
Expression exp = Expression::Sleepy; | |
error_reporter->Report("Heard %s (%d) @%dms", found_command, score, | |
current_time); | |
if (strcmp(found_command, "yes") == 0) { | |
exp = Expression::Happy; | |
avatar.setSpeechText("Yes!"); | |
} else if (strcmp(found_command, "no") == 0) { | |
exp = Expression::Sad; | |
avatar.setSpeechText("No!"); | |
} else if (strcmp(found_command, "unknown") == 0) { | |
exp = Expression::Doubt; | |
avatar.setSpeechText("?"); | |
} else if (strcmp(found_command, "silence") == 0) { | |
exp = Expression::Sleepy; | |
avatar.setSpeechText("zzz..."); | |
} | |
avatar.setExpression(exp); | |
last_timestamp = current_time; | |
} else { | |
if ((current_time - last_timestamp) > 2000) { | |
avatar.setSpeechText(""); | |
avatar.setExpression(Expression::Neutral); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment