implemented delete
implemented namechange fixed bug in saving credits added reset all counts! added less outputmode to print Person JSON
This commit is contained in:
parent
1bb6704d6e
commit
0ff99e00f3
@ -57,6 +57,7 @@ void setup() {
|
|||||||
Serial1.begin(9600);
|
Serial1.begin(9600);
|
||||||
|
|
||||||
// BLE Com init
|
// BLE Com init
|
||||||
|
//Serial3.begin(115200);
|
||||||
Serial3.begin(115200);
|
Serial3.begin(115200);
|
||||||
|
|
||||||
|
|
||||||
@ -248,7 +249,7 @@ Person read_person(Beerbox *box, char *filename) {
|
|||||||
if (aperson.finger_uuid > box->maxID) box->maxID = aperson.finger_uuid;
|
if (aperson.finger_uuid > box->maxID) box->maxID = aperson.finger_uuid;
|
||||||
|
|
||||||
//if(debug)print_person(box, &aperson,&Serial);
|
//if(debug)print_person(box, &aperson,&Serial);
|
||||||
print_person_JSON(box,&aperson,&Serial);
|
print_person_JSON(box,&aperson,&Serial,false);
|
||||||
|
|
||||||
read.close();
|
read.close();
|
||||||
return aperson;
|
return aperson;
|
||||||
|
@ -17,10 +17,21 @@ void bluetoothCommands() {
|
|||||||
Serial3.print("{\"persons\":[");
|
Serial3.print("{\"persons\":[");
|
||||||
for (int i = 0; i < box->personCount; i++) {
|
for (int i = 0; i < box->personCount; i++) {
|
||||||
if (i != 0)Serial3.print(",");
|
if (i != 0)Serial3.print(",");
|
||||||
print_person_JSON(box, &persons[i], &Serial3);
|
print_person_JSON(box, &persons[i], &Serial3, true);
|
||||||
|
print_person_JSON(box, &persons[i], &Serial, false);
|
||||||
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial3.println("]}");
|
Serial3.println("]}");
|
||||||
}
|
}
|
||||||
|
else if (subCommand == '3') { //reset all counts
|
||||||
|
|
||||||
|
for (int i = 0; i < box->personCount; i++) {
|
||||||
|
reset_person_drinks(box, &persons[i], i);
|
||||||
|
print_person_JSON(box, &persons[i], &Serial, false);
|
||||||
|
}
|
||||||
|
Serial3.println("{\"Success\"}");
|
||||||
|
}
|
||||||
} else if (command == '!') { //2 User Managment Command
|
} else if (command == '!') { //2 User Managment Command
|
||||||
if (subCommand == '1') { // Create new User
|
if (subCommand == '1') { // Create new User
|
||||||
char incomingByte = Serial3.read();
|
char incomingByte = Serial3.read();
|
||||||
@ -81,7 +92,7 @@ void bluetoothCommands() {
|
|||||||
data.toCharArray(filename, data.length() + 1);
|
data.toCharArray(filename, data.length() + 1);
|
||||||
if (personExists(filename)) {
|
if (personExists(filename)) {
|
||||||
Person* aperson = &persons[getFileIndex(filename)];
|
Person* aperson = &persons[getFileIndex(filename)];
|
||||||
print_person_JSON(box, aperson, &Serial3);
|
print_person_JSON(box, aperson, &Serial3, false);
|
||||||
} else {
|
} else {
|
||||||
Serial3.println("{\"Error\":\"no such file\"}");
|
Serial3.println("{\"Error\":\"no such file\"}");
|
||||||
}
|
}
|
||||||
@ -167,7 +178,13 @@ void bluetoothCommands() {
|
|||||||
Serial.println(data);
|
Serial.println(data);
|
||||||
data.toCharArray(filename, data.length() + 1);
|
data.toCharArray(filename, data.length() + 1);
|
||||||
if (personExists(filename)) {
|
if (personExists(filename)) {
|
||||||
Serial3.println("{\"Error\":\"not implemented yet\"}");
|
//Delete file
|
||||||
|
SD.remove(filename);
|
||||||
|
//rescan it!
|
||||||
|
delete [] persons; // When done, free memory pointed to
|
||||||
|
persons = NULL;
|
||||||
|
persons = readAllPersons();
|
||||||
|
if (debug)Serial.println(sizeof(persons));
|
||||||
} else {
|
} else {
|
||||||
Serial3.println("{\"Error\":\"no such file\"}");
|
Serial3.println("{\"Error\":\"no such file\"}");
|
||||||
}
|
}
|
||||||
@ -190,7 +207,7 @@ void bluetoothCommands() {
|
|||||||
Person* setPerson = &persons[lastPersonIndex];
|
Person* setPerson = &persons[lastPersonIndex];
|
||||||
setPerson->credits_left = atoi(credits_string);
|
setPerson->credits_left = atoi(credits_string);
|
||||||
update_pers_file();
|
update_pers_file();
|
||||||
print_person_JSON(box,setPerson,&Serial3);
|
print_person_JSON(box, setPerson, &Serial3, false);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Serial3.println("{\"Error\":\"no such file\"}");
|
Serial3.println("{\"Error\":\"no such file\"}");
|
||||||
@ -198,11 +215,25 @@ void bluetoothCommands() {
|
|||||||
|
|
||||||
}//set credits
|
}//set credits
|
||||||
else if (subCommand == '8') { //set name by filename
|
else if (subCommand == '8') { //set name by filename
|
||||||
|
//TODO: Better namechecking
|
||||||
char filename[data.length() + 1];
|
char filename[data.length() + 1];
|
||||||
Serial.println(data);
|
Serial.println(data);
|
||||||
data.toCharArray(filename, data.length() + 1);
|
data.toCharArray(filename, data.length() + 1);
|
||||||
if (personExists(filename)) {
|
if (personExists(filename)) {
|
||||||
Serial3.println("{\"Error\":\"not implemented yet\"}");
|
//Scann second time for newName
|
||||||
|
char incomingByte = Serial3.read();
|
||||||
|
String data2;
|
||||||
|
while (incomingByte != ';') {
|
||||||
|
data2 = String(data2 + incomingByte);
|
||||||
|
incomingByte = Serial3.read();
|
||||||
|
}
|
||||||
|
char name_string[11];
|
||||||
|
data2.toCharArray(name_string, data2.length() + 1);
|
||||||
|
lastPersonIndex = getFileIndex(filename);
|
||||||
|
Person* setPerson = &persons[lastPersonIndex];
|
||||||
|
strcpy(setPerson->name, name_string);
|
||||||
|
update_pers_file();
|
||||||
|
print_person_JSON(box, setPerson, &Serial3, false);
|
||||||
} else {
|
} else {
|
||||||
Serial3.println("{\"Error\":\"no such file\"}");
|
Serial3.println("{\"Error\":\"no such file\"}");
|
||||||
}
|
}
|
||||||
@ -214,7 +245,12 @@ void bluetoothCommands() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void print_person_JSON(Beerbox *box, Person *aperson, HardwareSerial* com) {
|
void print_person_JSON(Beerbox *box, Person *aperson, HardwareSerial* com, bool less) {
|
||||||
|
|
||||||
|
if (less) {
|
||||||
|
sprintf(toprint, "{\"name\": \"%s\",\"filename\":\"%s\"}", aperson->name, aperson->file_name);
|
||||||
|
com->write(toprint);
|
||||||
|
} else {
|
||||||
|
|
||||||
sprintf(toprint, "{\"name\": \"%s\",\"filename\":\"%s\",\"creditsleft\":\"%i\",\"drinks\":[", aperson->name, aperson->file_name, aperson->credits_left);
|
sprintf(toprint, "{\"name\": \"%s\",\"filename\":\"%s\",\"creditsleft\":\"%i\",\"drinks\":[", aperson->name, aperson->file_name, aperson->credits_left);
|
||||||
com->write(toprint);
|
com->write(toprint);
|
||||||
@ -227,6 +263,7 @@ void print_person_JSON(Beerbox *box, Person *aperson, HardwareSerial* com) {
|
|||||||
}
|
}
|
||||||
com->println("]}");
|
com->println("]}");
|
||||||
box->scanning = false;
|
box->scanning = false;
|
||||||
|
}
|
||||||
} // end print JSON
|
} // end print JSON
|
||||||
|
|
||||||
void print_drinks_JSON(Beerbox *box, HardwareSerial* com) {
|
void print_drinks_JSON(Beerbox *box, HardwareSerial* com) {
|
||||||
@ -241,3 +278,14 @@ void print_drinks_JSON(Beerbox *box, HardwareSerial* com) {
|
|||||||
com->print("]}");
|
com->print("]}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void reset_person_drinks(Beerbox *box,Person *aperson,int personIndex){
|
||||||
|
for (int i = 0; i < box->maxDrink; i++) {
|
||||||
|
if (box->drinks[i].price != -1) {
|
||||||
|
aperson->drinks_taken[i] = 0;
|
||||||
|
lastPersonIndex = personIndex;
|
||||||
|
update_pers_file();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -21,6 +21,8 @@ void checkButton() {
|
|||||||
{
|
{
|
||||||
//revert save
|
//revert save
|
||||||
persons[lastPersonIndex].drinks_taken[currentDrink]--;
|
persons[lastPersonIndex].drinks_taken[currentDrink]--;
|
||||||
|
persons[personIndex].credits_left = persons[personIndex].credits_left + box->drinks[currentDrink].price;
|
||||||
|
|
||||||
box->waiting = 0;
|
box->waiting = 0;
|
||||||
lcd.clear();
|
lcd.clear();
|
||||||
lcd.print("Abort!");
|
lcd.print("Abort!");
|
||||||
@ -65,7 +67,7 @@ bool checkFinger() {
|
|||||||
if(debug)Serial.print("This is ");
|
if(debug)Serial.print("This is ");
|
||||||
if(debug)Serial.println(persons[getFingerIndex(finger.fingerID)].name);
|
if(debug)Serial.println(persons[getFingerIndex(finger.fingerID)].name);
|
||||||
if(!box->scanning) countUp(getFingerIndex(finger.fingerID), 0);//for finger context
|
if(!box->scanning) countUp(getFingerIndex(finger.fingerID), 0);//for finger context
|
||||||
else print_person_JSON(box,&persons[getFingerIndex(finger.fingerID)],&Serial3);
|
else print_person_JSON(box,&persons[getFingerIndex(finger.fingerID)],&Serial3, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +104,7 @@ bool checkRFID() {
|
|||||||
if(getRFIDIndex( code)!=-1){
|
if(getRFIDIndex( code)!=-1){
|
||||||
if(!box->scanning)
|
if(!box->scanning)
|
||||||
countUp(getRFIDIndex( code), 1); // 1 for rfid context
|
countUp(getRFIDIndex( code), 1); // 1 for rfid context
|
||||||
else print_person_JSON(box,&persons[getRFIDIndex( code)],&Serial3);
|
else print_person_JSON(box,&persons[getRFIDIndex( code)],&Serial3, false);
|
||||||
}else{
|
}else{
|
||||||
if(debug)Serial.println("Error: Nonexisting Card");
|
if(debug)Serial.println("Error: Nonexisting Card");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user