Lukas Bachschwell
df94ff0654
moved drinksMax to beerbox struct and refactored to maxDrink added if(debug) to all serial write and serial print statements Moved BLE com to seperat file and added command and subcommandparsing Added filename JSON method
124 lines
3.5 KiB
C++
124 lines
3.5 KiB
C++
void bluetoothCommands(){
|
|
if (Serial3.available() > 0) {
|
|
char command = Serial3.read();
|
|
char subCommand = Serial3.read();
|
|
|
|
if (command == '#') { //1 General Info Command
|
|
if(subCommand == '1'){ // Get All Drinks
|
|
char incomingByte = Serial3.read(); // ignore ;
|
|
|
|
|
|
|
|
} else if(subCommand == '2'){ // Get All filenames
|
|
char incomingByte = Serial3.read(); // ignore ;
|
|
//while
|
|
//filenames_JSON(box,person)
|
|
|
|
}
|
|
} else if (command == '!') { //2 User Managment Command
|
|
if(subCommand == '1'){ // Create new User
|
|
|
|
|
|
char incomingByte = Serial3.read();
|
|
String personName;
|
|
|
|
while (incomingByte != ';'){
|
|
personName = String(personName + incomingByte);
|
|
incomingByte = Serial3.read();
|
|
}
|
|
if(debug)Serial.println(personName);
|
|
lcd.clear();
|
|
lcd.print(personName);
|
|
if(debug)Serial.println(box->maxID);
|
|
//lcd.setCursor(0,1);
|
|
//lcd.print("Fin pls");
|
|
int fingerReturn = -1;
|
|
while (fingerReturn != 0)
|
|
{
|
|
fingerReturn = getFingerprintEnroll(box->maxID + 1);
|
|
}
|
|
lcd.clear();
|
|
lcd.print(personName);
|
|
lcd.setCursor(0, 1);
|
|
lcd.print("RFID pls");
|
|
|
|
zugang = "";
|
|
while (zugang == "") {
|
|
getRFIDEnroll();
|
|
}
|
|
if(debug)Serial.println(zugang);
|
|
box->maxID++;
|
|
Person* newPerson = new Person;
|
|
personName.toCharArray(newPerson->name, personName.length()+1);
|
|
char tmp[FILE_NAME_LEN + 1];
|
|
sprintf(tmp,"p%03d%s",box->maxID,FILE_EXTENSION);
|
|
strcpy(newPerson->file_name, tmp);
|
|
zugang.toCharArray(newPerson->rfid_uuid, zugang.length()+1);
|
|
newPerson->finger_uuid = box->maxID;
|
|
newPerson->credits_left = 1000;
|
|
for (int i = 0; i < box->maxDrink; i++) {
|
|
newPerson->drinks_taken[i]=0;
|
|
}
|
|
write_pers_file(newPerson);
|
|
|
|
|
|
zugang = ""; // reset here
|
|
lcd.clear();
|
|
lcd.print(personName);
|
|
lcd.setCursor(0, 1);
|
|
lcd.print("Sucess!");
|
|
delay(1000);
|
|
//and revert to normal:
|
|
lcd.clear();
|
|
lcd.print("Drink:");
|
|
lcd.setCursor(0, 1);
|
|
lcd.print(box->drinks[currentDrink].name);
|
|
}//new User
|
|
else if(subCommand == '2'){ //get user by filename
|
|
|
|
}//get user
|
|
else if(subCommand == '3'){ //trigger user scan for ID
|
|
|
|
//return filename
|
|
|
|
}//user scan
|
|
else if(subCommand == '4'){ //revoke user finger by filename
|
|
|
|
}//revoke finger
|
|
else if(subCommand == '5'){ //revoke user rfid by filename
|
|
|
|
}//revoke rfid
|
|
else if(subCommand == '6'){ //delete user by filename
|
|
|
|
}//delete user
|
|
else if(subCommand == '6'){ //set user credits
|
|
|
|
}//set credits
|
|
else if(subCommand == '6'){ //set name by filename
|
|
|
|
}//set name
|
|
} // User Managment Command
|
|
} //BLE available
|
|
|
|
}//end function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void filenames_JSON(Beerbox *box, Person *aperson) {
|
|
|
|
int i = 0;
|
|
sprintf(toprint, "{\"name\": \"%s\",\"filename\":\"%s\",\"creditsleft\":\"%s\",\"drinks\":[", aperson->name, aperson->file_name, aperson->credits_left);
|
|
Serial.write(toprint);
|
|
for (i = 0; i < box->maxDrink; i++) {
|
|
if (aperson->drinks_taken[i] != -1) {
|
|
if(i=0) sprintf(toprint, "{\"%s\":\"%s\"}", box->drinks[i].name,aperson->drinks_taken[i]);
|
|
else sprintf(toprint, ",{\"%s\":\"%s\"}", box->drinks[i].name,aperson->drinks_taken[i]);
|
|
Serial.write(toprint);
|
|
}
|
|
}
|
|
Serial.write("]}");
|
|
} // end print JSON
|