main/recipes.c

changeset 54
7b134c27fadb
parent 19
49e2960d4642
child 56
756d1a63d129
equal deleted inserted replaced
53:cf91a3a20d0d 54:7b134c27fadb
49 */ 49 */
50 void Addition_Add(char *Name, uint8_t Type, uint16_t Time) 50 void Addition_Add(char *Name, uint8_t Type, uint16_t Time)
51 { 51 {
52 if (! recipe.Additions) { 52 if (! recipe.Additions) {
53 // No entries yet, add the first one. 53 // No entries yet, add the first one.
54 sprintf(recipe.Addition[recipe.Additions].Name, "%s", Name); 54 snprintf(recipe.Addition[recipe.Additions].Name, 63, "%s", Name);
55 // recipe.Addition[recipe.Additions].Name = "";
56 // strncat(recipe.Addition[recipe.Additions].Name, Name, 63);
55 recipe.Addition[recipe.Additions].Type = Type; 57 recipe.Addition[recipe.Additions].Type = Type;
56 recipe.Addition[recipe.Additions].Time = Time; 58 recipe.Addition[recipe.Additions].Time = Time;
57 recipe.Additions++; 59 recipe.Additions++;
58 return; 60 return;
59 } 61 }
60 62
61 // See if we already got one with the same time. 63 // See if we already got one with the same time.
62 for (int i = 0; i < recipe.Additions; i++) { 64 for (int i = 0; i < recipe.Additions; i++) {
63 if (recipe.Addition[i].Time == Time) { 65 if (recipe.Addition[i].Time == Time) {
64 // Yes, update the name. 66 // Yes, update the name.
65 snprintf(recipe.Addition[i].Name, 63, "%s, %s", recipe.Addition[i].Name, Name); 67 //snprintf(recipe.Addition[i].Name, 63, "%s, %s", recipe.Addition[i].Name, Name);
68 strncat(recipe.Addition[i].Name, ", ", 63 - strlen(recipe.Addition[i].Name));
69 strncat(recipe.Addition[i].Name, Name, 63 - strlen(recipe.Addition[i].Name));
66 return; 70 return;
67 } 71 }
68 } 72 }
69 73
70 // A new entry and we already have some. Add it and keep the list sorted. 74 // A new entry and we already have some. Add it and keep the list sorted.
74 for (int j = i; j < recipe.Additions; j++) { 78 for (int j = i; j < recipe.Additions; j++) {
75 sprintf(recipe.Addition[j+1].Name, "%s", recipe.Addition[j].Name); 79 sprintf(recipe.Addition[j+1].Name, "%s", recipe.Addition[j].Name);
76 recipe.Addition[j+1].Type = recipe.Addition[j].Type; 80 recipe.Addition[j+1].Type = recipe.Addition[j].Type;
77 recipe.Addition[j+1].Time = recipe.Addition[j].Time; 81 recipe.Addition[j+1].Time = recipe.Addition[j].Time;
78 } 82 }
79 sprintf(recipe.Addition[i].Name, "%s", Name); 83 snprintf(recipe.Addition[i].Name, 63, "%s", Name);
80 recipe.Addition[i].Type = Type; 84 recipe.Addition[i].Type = Type;
81 recipe.Addition[i].Time = Time; 85 recipe.Addition[i].Time = Time;
82 recipe.Additions++; 86 recipe.Additions++;
83 return; 87 return;
84 } 88 }
85 } 89 }
86 90
87 // Just append. 91 // Just append.
88 sprintf(recipe.Addition[recipe.Additions].Name, "%s", Name); 92 snprintf(recipe.Addition[recipe.Additions].Name, 63, "%s", Name);
89 recipe.Addition[recipe.Additions].Type = Type; 93 recipe.Addition[recipe.Additions].Type = Type;
90 recipe.Addition[recipe.Additions].Time = Time; 94 recipe.Addition[recipe.Additions].Time = Time;
91 recipe.Additions++; 95 recipe.Additions++;
92 } 96 }
93 97
143 if ((_xml_depth > 2) && (strcmp(_xml_element[0], "RECIPES") == 0) && (strcmp(_xml_element[1], "RECIPE") == 0)) { 147 if ((_xml_depth > 2) && (strcmp(_xml_element[0], "RECIPES") == 0) && (strcmp(_xml_element[1], "RECIPE") == 0)) {
144 /* 148 /*
145 * We are in a recipe 149 * We are in a recipe
146 */ 150 */
147 if ((_xml_depth == 3) && (strcmp("NAME", _xml_element[2]) == 0)) { 151 if ((_xml_depth == 3) && (strcmp("NAME", _xml_element[2]) == 0)) {
148 snprintf(recipe.Name, 127, "%s", char_data_buffer); 152 recipe.Name[0] = '\0';
153 strncat(recipe.Name, char_data_buffer, 127);
149 } else if ((_xml_depth == 3) && (strcmp("BOIL_TIME", _xml_element[2]) == 0)) { 154 } else if ((_xml_depth == 3) && (strcmp("BOIL_TIME", _xml_element[2]) == 0)) {
150 recipe.BoilTime = atoi(char_data_buffer); 155 recipe.BoilTime = atoi(char_data_buffer);
151 } else if ((_xml_depth == 5) && (strcmp("HOPS", _xml_element[2]) == 0) && (strcmp("HOP", _xml_element[3]) == 0)) { 156 } else if ((_xml_depth == 5) && (strcmp("HOPS", _xml_element[2]) == 0) && (strcmp("HOP", _xml_element[3]) == 0)) {
152 /* 157 /*
153 * Hops that are added during the boil. 158 * Hops that are added during the boil.
442 char filename[256], newname[256]; 447 char filename[256], newname[256];
443 int rc; 448 int rc;
444 449
445 switch (Main_Screen) { 450 switch (Main_Screen) {
446 case MAIN_TOOLS_RECIPE: 451 case MAIN_TOOLS_RECIPE:
447 TopMessage("Recepten importeren"); 452 TopMessage((char *)"Recepten importeren");
448 r_Imported = 0; 453 r_Imported = 0;
449 TFT_setFont(DEFAULT_FONT, NULL); 454 TFT_setFont(DEFAULT_FONT, NULL);
450 y = 28; 455 y = 28;
451 if ((dir = opendir("/sdcard/recipe"))) { 456 if ((dir = opendir("/sdcard/recipe"))) {
452 de = readdir(dir); 457 de = readdir(dir);
462 ESP_LOGI(TAG, "Recipe %s parsed, rc=%d", filename, rc); 467 ESP_LOGI(TAG, "Recipe %s parsed, rc=%d", filename, rc);
463 if (rc == 0) { 468 if (rc == 0) {
464 append_recipe(); 469 append_recipe();
465 rename(filename, newname); 470 rename(filename, newname);
466 _fg = TFT_GREEN; 471 _fg = TFT_GREEN;
467 TFT_print(" Ok", LASTX, y); 472 TFT_print((char *)" Ok", LASTX, y);
468 } else { 473 } else {
469 _fg = TFT_RED; 474 _fg = TFT_RED;
470 TFT_print(" Fout", LASTX, y); 475 TFT_print((char *)" Fout", LASTX, y);
471 } 476 }
472 r_Imported++; // Count them all 477 r_Imported++; // Count them all
473 y += 16; 478 y += 16;
474 } 479 }
475 de = readdir(dir); 480 de = readdir(dir);
512 517
513 switch (Main_Screen) { 518 switch (Main_Screen) {
514 case MAIN_TOOLS_RECIPE: 519 case MAIN_TOOLS_RECIPE:
515 if (r_Imported) { 520 if (r_Imported) {
516 Buttons_Clear(); 521 Buttons_Clear();
517 Buttons_Add(135, 210, 50, 30, "Ok" , 0); 522 Buttons_Add(135, 210, 50, 30, (char *)"Ok" , 0);
518 Buttons_Show(); 523 Buttons_Show();
519 524
520 while (true) { 525 while (true) {
521 if (Buttons_Scan() == 0) 526 if (Buttons_Scan() == 0)
522 break; 527 break;
527 } 532 }
528 if (r_UpdateRec) { 533 if (r_UpdateRec) {
529 _bg = TFT_BLACK; 534 _bg = TFT_BLACK;
530 TFT_fillScreen(_bg); 535 TFT_fillScreen(_bg);
531 TFT_resetclipwin(); 536 TFT_resetclipwin();
532 TopMessage("Recepten"); 537 TopMessage((char *)"Recepten");
533 r_UpdateRec = false; 538 r_UpdateRec = false;
534 read_recipe(r_CurrentRec); 539 read_recipe(r_CurrentRec);
535 TFT_setFont(DEFAULT_FONT, NULL); 540 TFT_setFont(DEFAULT_FONT, NULL);
536 ShowText(2, 28, "Naam", recipe.Name); 541 ShowText(2, 28, (char *)"Naam", recipe.Name);
537 ShowText(2, 44, "Code", recipe.Code); 542 ShowText(2, 44, (char *)"Code", recipe.Code);
538 ShowInteger(162, 44, "Record", NULL, r_CurrentRec); 543 ShowInteger(162, 44, (char *)"Record", NULL, r_CurrentRec);
539 ShowInteger(2, 60, "Kooktijd", " min", recipe.BoilTime); 544 ShowInteger(2, 60, (char *)"Kooktijd", (char *)" min", recipe.BoilTime);
540 ShowFloat(162, 60, "Koel tot", " C", recipe.CoolTemp, 2); 545 ShowFloat(162, 60, (char *)"Koel tot", (char *)" C", recipe.CoolTemp, 2);
541 ShowFloat(2, 76, "Maisch in", " C", recipe.MashStep[0].Temperature, 2); 546 ShowFloat(2, 76, (char *)"Maisch in", (char *)" C", recipe.MashStep[0].Temperature, 2);
542 ShowFloat(162, 76, "Spoelwater", " C", recipe.SpargeTemp, 2); 547 ShowFloat(162, 76, (char *)"Spoelwater", (char *)" C", recipe.SpargeTemp, 2);
543 y = 92; 548 y = 92;
544 _fg = TFT_WHITE; 549 _fg = TFT_WHITE;
545 TFT_print("Maisch stap", 2, y); 550 TFT_print((char *)"Maisch stap", 2, y);
546 TFT_print("T", 200, y); 551 TFT_print((char *)"T", 200, y);
547 TFT_print("Temp.", 220, y); 552 TFT_print((char *)"Temp.", 220, y);
548 TFT_print("Rust", 280, y); 553 TFT_print((char *)"Rust", 280, y);
549 _fg = TFT_YELLOW; 554 _fg = TFT_YELLOW;
550 y += 16; 555 y += 16;
551 for (int i = 1; i < 8; i++) { 556 for (int i = 1; i < 8; i++) {
552 if (recipe.MashStep[i].Resttime) { 557 if (recipe.MashStep[i].Resttime) {
553 TFT_print(recipe.MashStep[i].Name, 2, y); 558 TFT_print(recipe.MashStep[i].Name, 2, y);
564 if (recipe.Additions) { 569 if (recipe.Additions) {
565 _fg = TFT_YELLOW; 570 _fg = TFT_YELLOW;
566 sprintf(tmp, "%d ", recipe.Additions); 571 sprintf(tmp, "%d ", recipe.Additions);
567 TFT_print(tmp, 2, y); 572 TFT_print(tmp, 2, y);
568 _fg = TFT_WHITE; 573 _fg = TFT_WHITE;
569 TFT_print("toevoegingen om", LASTX, y); 574 TFT_print((char *)"toevoegingen om", LASTX, y);
570 _fg = TFT_YELLOW; 575 _fg = TFT_YELLOW;
571 for (int i = 1; i <= recipe.Additions; i++) { 576 for (int i = 1; i <= recipe.Additions; i++) {
572 sprintf(tmp, " %d", recipe.Addition[i-1].Time); 577 sprintf(tmp, " %d", recipe.Addition[i-1].Time);
573 TFT_print(tmp, LASTX, y); 578 TFT_print(tmp, LASTX, y);
574 } 579 }
575 _fg = TFT_WHITE; 580 _fg = TFT_WHITE;
576 TFT_print(" minuten", LASTX, y); 581 TFT_print((char *)" minuten", LASTX, y);
577 } else { 582 } else {
578 _fg = TFT_WHITE; 583 _fg = TFT_WHITE;
579 TFT_print("Geen hop toevoegingen.", 2, y); 584 TFT_print((char *)"Geen hop toevoegingen.", 2, y);
580 } 585 }
581 y += 16; 586 y += 16;
582 if (recipe.Whirlpool9 || recipe.Whirlpool7 || recipe.Whirlpool6 || recipe.Whirlpool2) { 587 if (recipe.Whirlpool9 || recipe.Whirlpool7 || recipe.Whirlpool6 || recipe.Whirlpool2) {
583 _fg = TFT_WHITE; 588 _fg = TFT_WHITE;
584 TFT_print("Whirlpool ", 2, y); 589 TFT_print((char *)"Whirlpool ", 2, y);
585 _fg = TFT_YELLOW; 590 _fg = TFT_YELLOW;
586 if (recipe.Whirlpool9) 591 if (recipe.Whirlpool9)
587 TFT_print("88+ ", LASTX, y); 592 TFT_print((char *)"88+ ", LASTX, y);
588 if (recipe.Whirlpool7) 593 if (recipe.Whirlpool7)
589 TFT_print("71+ ", LASTX, y); 594 TFT_print((char *)"71+ ", LASTX, y);
590 if (recipe.Whirlpool6) 595 if (recipe.Whirlpool6)
591 TFT_print("60+ ", LASTX, y); 596 TFT_print((char *)"60+ ", LASTX, y);
592 if (recipe.Whirlpool2) 597 if (recipe.Whirlpool2)
593 TFT_print("koud", LASTX, y); 598 TFT_print((char *)"koud", LASTX, y);
594 } 599 }
595 600
596 Buttons_Clear(); 601 Buttons_Clear();
597 Buttons_Add( 0, 210, 45, 30, "Ok" , 0); 602 Buttons_Add( 0, 210, 45, 30, (char *)"Ok" , 0);
598 Buttons_Add( 46, 210, 45, 30, "+" , 1); 603 Buttons_Add( 46, 210, 45, 30, (char *)"+" , 1);
599 if (r_CurrentRec != config.RecipeRec) 604 if (r_CurrentRec != config.RecipeRec)
600 Buttons_Add( 92, 210, 45, 30, "-", 2); 605 Buttons_Add( 92, 210, 45, 30, (char *)"-", 2);
601 else 606 else
602 Buttons_Add( 92, 210, 45, 30, "" , 2); 607 Buttons_Add( 92, 210, 45, 30, (char *)"" , 2);
603 if (r_CurrentRec > 1) 608 if (r_CurrentRec > 1)
604 Buttons_Add(138, 210, 45, 30, "<", 3); 609 Buttons_Add(138, 210, 45, 30, (char *)"<", 3);
605 else 610 else
606 Buttons_Add(138, 210, 45, 30, "", 3); 611 Buttons_Add(138, 210, 45, 30, (char *)"", 3);
607 if (r_CurrentRec < r_Records) 612 if (r_CurrentRec < r_Records)
608 Buttons_Add(184, 210, 45, 30, ">", 4); 613 Buttons_Add(184, 210, 45, 30, (char *)">", 4);
609 else 614 else
610 Buttons_Add(184, 210, 45, 30, "", 4); 615 Buttons_Add(184, 210, 45, 30, (char *)"", 4);
611 if (r_CurrentRec != config.RecipeRec) 616 if (r_CurrentRec != config.RecipeRec)
612 Buttons_Add(230, 210, 45, 30, "Std", 5); 617 Buttons_Add(230, 210, 45, 30, (char *)"Std", 5);
613 else 618 else
614 Buttons_Add(230, 210, 45, 30, "", 5); 619 Buttons_Add(230, 210, 45, 30, (char *)"", 5);
615 Buttons_Add(276, 210, 45, 30, "Ed" , 6); 620 Buttons_Add(276, 210, 45, 30, (char *)"Ed" , 6);
616 Buttons[0].dark = true; 621 Buttons[0].dark = true;
617 Buttons_Show(); 622 Buttons_Show();
618 } /* if (r_UpdateRec) */ 623 } /* if (r_UpdateRec) */
619 switch (Buttons_Scan()) { 624 switch (Buttons_Scan()) {
620 case 0: Main_Screen = MAIN_TOOLS; 625 case 0: Main_Screen = MAIN_TOOLS;
699 704
700 case MAIN_TOOLS_RECIPE_EDIT: 705 case MAIN_TOOLS_RECIPE_EDIT:
701 dst = (uint8_t*)&recipe; 706 dst = (uint8_t*)&recipe;
702 crc1 = crc32_le(0, dst, sizeof(recipe)); 707 crc1 = crc32_le(0, dst, sizeof(recipe));
703 708
704 EditText("Naam", recipe.Name, 31); 709 EditText((char *)"Naam", recipe.Name, 31);
705 EditText("Code", recipe.Code, 31); 710 EditText((char *)"Code", recipe.Code, 31);
706 mashsteps = 0; 711 mashsteps = 0;
707 for (int i = 1; i < 7; i++) { 712 for (int i = 1; i < 7; i++) {
708 if (recipe.MashStep[i].Resttime) 713 if (recipe.MashStep[i].Resttime)
709 mashsteps++; 714 mashsteps++;
710 } 715 }
711 EditInt("Maisch stappen", &mashsteps, 1, 6); 716 EditInt((char *)"Maisch stappen", &mashsteps, 1, 6);
712 EditFloat("Inmaisch temperatuur", &recipe.MashStep[0].Temperature, 38, 74, 2); 717 EditFloat((char *)"Inmaisch temperatuur", &recipe.MashStep[0].Temperature, 38, 74, 2);
713 // Round to 0.25 values 718 // Round to 0.25 values
714 recipe.MashStep[0].Temperature = ((int)(recipe.MashStep[0].Temperature * 4)) / 4.0; 719 recipe.MashStep[0].Temperature = ((int)(recipe.MashStep[0].Temperature * 4)) / 4.0;
715 for (int i = 1; i <= mashsteps; i++) { 720 for (int i = 1; i <= mashsteps; i++) {
716 sprintf(tmp, "Maisch stap %d naam", i); 721 sprintf(tmp, "Maisch stap %d naam", i);
717 EditText(tmp, recipe.MashStep[i].Name, 31); 722 EditText(tmp, recipe.MashStep[i].Name, 31);
739 } else { 744 } else {
740 recipe.MashStep[i].Infusion_temp = recipe.MashStep[i].Infusion_amount = 0.0; 745 recipe.MashStep[i].Infusion_temp = recipe.MashStep[i].Infusion_amount = 0.0;
741 } 746 }
742 } 747 }
743 mintemp = recipe.MashStep[mashsteps].Temperature; 748 mintemp = recipe.MashStep[mashsteps].Temperature;
744 EditFloat("Uitmaischen temperatuur", &recipe.MashStep[7].Temperature, mintemp, 80, 2); 749 EditFloat((char *)"Uitmaischen temperatuur", &recipe.MashStep[7].Temperature, mintemp, 80, 2);
745 recipe.MashStep[7].Temperature = ((int)(recipe.MashStep[7].Temperature * 4)) / 4.0; 750 recipe.MashStep[7].Temperature = ((int)(recipe.MashStep[7].Temperature * 4)) / 4.0;
746 EditUint16("Uitmaischen tijd in minuten", &recipe.MashStep[7].Resttime, 1, 15); 751 EditUint16((char *)"Uitmaischen tijd in minuten", &recipe.MashStep[7].Resttime, 1, 15);
747 recipe.MashStep[7].Ramptime = (int)(recipe.MashStep[7].Temperature - recipe.MashStep[mashsteps].Temperature); 752 recipe.MashStep[7].Ramptime = (int)(recipe.MashStep[7].Temperature - recipe.MashStep[mashsteps].Temperature);
748 // Zero any higher steps to diable them. 753 // Zero any higher steps to diable them.
749 for (int i = (mashsteps + 1); i < 7; i++) 754 for (int i = (mashsteps + 1); i < 7; i++)
750 recipe.MashStep[i].Resttime = 0; 755 recipe.MashStep[i].Resttime = 0;
751 756
752 EditUint16("Kook tijd in minuten", &recipe.BoilTime, 3, 480); 757 EditUint16((char *)"Kook tijd in minuten", &recipe.BoilTime, 3, 480);
753 EditUint8("Hop/kruiden toevoegingen", &recipe.Additions, 1, 10); 758 EditUint8((char *)"Hop/kruiden toevoegingen", &recipe.Additions, 1, 10);
754 for (uint8_t i = 0; i < recipe.Additions; i++) { 759 for (uint8_t i = 0; i < recipe.Additions; i++) {
755 sprintf(tmp, "Toevoeging %d maam", i+1); 760 sprintf(tmp, "Toevoeging %d naam", i+1);
756 if (strlen(recipe.Addition[i].Name) == 00) { 761 if (strlen(recipe.Addition[i].Name) == 00) {
757 sprintf(recipe.Addition[i].Name, "Hop %d", (int)i+1); 762 sprintf(recipe.Addition[i].Name, "Hop %d", (int)i+1);
758 } 763 }
759 EditText(tmp, recipe.Addition[i].Name, 40); 764 EditText(tmp, recipe.Addition[i].Name, 40);
760 sprintf(tmp, "Toevoeging %d tijd", i+1); 765 sprintf(tmp, "Toevoeging %d tijd", i+1);
764 EditUint16(tmp, &recipe.Addition[i].Time, 0, recipe.Addition[i-1].Time - 1); 769 EditUint16(tmp, &recipe.Addition[i].Time, 0, recipe.Addition[i-1].Time - 1);
765 } 770 }
766 recipe.Addition[i].Type = ADDITION_HOP; 771 recipe.Addition[i].Type = ADDITION_HOP;
767 } 772 }
768 773
769 EditFloat("Koel temperatuur", &recipe.CoolTemp, 10, 30, 2); 774 EditFloat((char *)"Koel temperatuur", &recipe.CoolTemp, 10, 30, 2);
770 recipe.CoolTemp = ((int)(recipe.CoolTemp * 4)) / 4.0; 775 recipe.CoolTemp = ((int)(recipe.CoolTemp * 4)) / 4.0;
771 EditFloat("Spoelwater temperatuur", &recipe.SpargeTemp, 75, 98, 2); 776 EditFloat((char *)"Spoelwater temperatuur", &recipe.SpargeTemp, 75, 98, 2);
772 recipe.SpargeTemp = ((int)(recipe.SpargeTemp * 4)) / 4.0; 777 recipe.SpargeTemp = ((int)(recipe.SpargeTemp * 4)) / 4.0;
773 EditUint16("Whirlpool 88..100 graden, 0 = niet", &recipe.Whirlpool9, 0, 120); 778 EditUint16((char *)"Whirlpool 88..100 graden, 0 = niet", &recipe.Whirlpool9, 0, 120);
774 EditUint16("Whirlpool 71..77 graden, 0 = niet", &recipe.Whirlpool7, 0, 120); 779 EditUint16((char *)"Whirlpool 71..77 graden, 0 = niet", &recipe.Whirlpool7, 0, 120);
775 EditUint16("Whirlpool 60..66 graden, 0 = niet", &recipe.Whirlpool6, 0, 120); 780 EditUint16((char *)"Whirlpool 60..66 graden, 0 = niet", &recipe.Whirlpool6, 0, 120);
776 EditUint16("Whirlpool koud, 0 = niet", &recipe.Whirlpool2, 0, 120); 781 EditUint16((char *)"Whirlpool koud, 0 = niet", &recipe.Whirlpool2, 0, 120);
777 782
778 crc2 = crc32_le(0, dst, sizeof(recipe)); 783 crc2 = crc32_le(0, dst, sizeof(recipe));
779 if ((crc1 != crc2) && Confirm("Gewijzigd, opslaan?", "Ja", "Nee")) { 784 if ((crc1 != crc2) && Confirm((char *)"Gewijzigd, opslaan?", (char *)"Ja", (char *)"Nee")) {
780 write_recipe(r_CurrentRec); 785 write_recipe(r_CurrentRec);
781 } 786 }
782 Main_Screen = MAIN_TOOLS_RECIPE; 787 Main_Screen = MAIN_TOOLS_RECIPE;
783 break; 788 break;
784 789

mercurial