brewco/setup.c

changeset 459
1f88be70f253
parent 458
43a8ecb53637
child 461
482bab226340
equal deleted inserted replaced
458:43a8ecb53637 459:1f88be70f253
25 #include "setup.h" 25 #include "setup.h"
26 #include "prompt.h" 26 #include "prompt.h"
27 #include "xutil.h" 27 #include "xutil.h"
28 #include "keyboard.h" 28 #include "keyboard.h"
29 #include "rdconfig.h" 29 #include "rdconfig.h"
30 #include "rdrecipes.h"
30 31
31 32
32 extern int my_shutdown; 33 extern int my_shutdown;
33 extern int debug; 34 extern int debug;
34 extern sys_config Config; 35 extern sys_config Config;
35 extern int lcdHandle; 36 extern int lcdHandle;
36 extern int slcdHandle; 37 extern int slcdHandle;
38 extern a_recipe *recipes;
37 39
38 40
39 41
40 void editFloat(float *value, float low, float high, char *text) 42 void editFloat(float *value, float low, float high, char *text)
41 { 43 {
753 fprintf(stdout, "Brewsystem %d added to the configuration\n", number); 755 fprintf(stdout, "Brewsystem %d added to the configuration\n", number);
754 } 756 }
755 757
756 758
757 759
760 /*
761 * Edit a single recipe
762 */
763 void editRecipe(a_recipe *recipe)
764 {
765 int idx = 1, key;
766 char pmpt[81];
767 uLong ocrc, ncrc;
768
769 if (debug)
770 fprintf(stdout, "Start edit recipe `%s' %s\n", recipe->name, recipe->uuid);
771
772 prompt(0, NULL);
773 ncrc = ocrc = crc32(0L, Z_NULL, 0);
774 ocrc = crc32(ocrc, (const Bytef *) recipe, sizeof(a_recipe));
775
776 for (;;) {
777
778 prompt(0, NULL);
779 prompt(139, NULL);
780
781 if (idx == 1)
782 prompt(402, NULL);
783 else if (idx == 21)
784 prompt(404, NULL);
785 else
786 prompt(403, NULL);
787
788 switch (idx) { // 12345678901234567890
789 case 1: snprintf(pmpt, Config.lcd_cols + 1, "Recipe name:");
790 prompt(200, pmpt);
791 snprintf(pmpt, Config.lcd_cols + 1, "%s", recipe->name);
792 prompt(300, pmpt);
793 break;
794 case 2: snprintf(pmpt, Config.lcd_cols + 1, "Recipe code:");
795 prompt(200, pmpt);
796 snprintf(pmpt, Config.lcd_cols + 1, "%s", recipe->code);
797 prompt(300, pmpt);
798 break;
799 case 3: snprintf(pmpt, Config.lcd_cols + 1, "Boil time: %3d mins", recipe->boiltime);
800 prompt(200, pmpt);
801 break;
802 }
803
804 key = keywait();
805 if ((key == KEY_RETURN) || my_shutdown) {
806 ncrc = crc32(ncrc, (const Bytef *)recipe, sizeof(a_recipe));
807 if (ocrc != ncrc)
808 wrrecipes();
809 if (debug)
810 fprintf(stdout, "End edit recipe `%s' %s\n", recipe->name, recipe->uuid);
811 return;
812 }
813
814 if ((key == KEY_UP) && (idx > 1))
815 idx--;
816 if ((key == KEY_DOWN) && (idx < 6))
817 idx++;
818
819 if (key == KEY_ENTER) {
820 switch(idx) {
821 case 1: // name
822 break;
823 case 2: // code
824 break;
825 case 3: editInteger(&recipe->boiltime, 60, 240, 5, (char *)"Boil time:", (char *)"mins");
826 break;
827 }
828 }
829 }
830 }
831
832
833
834 void addRecipe(int number)
835 {
836 a_recipe *tmpu, *recipe = (a_recipe *)malloc(sizeof(a_recipe));
837 char name[81];
838 uuid_t uu;
839 int i;
840
841 if (debug)
842 fprintf(stdout, "Adding new recipe %d\n", number);
843 recipe->next = NULL;
844 recipe->uuid = malloc(37);
845 uuid_generate(uu);
846 uuid_unparse(uu, recipe->uuid);
847 snprintf(name, 21, "New recipe %d", number);
848 recipe->name = xstrcpy(name);
849 snprintf(name, 21, "%04d", number);
850 recipe->code = xstrcpy(name);
851 recipe->boiltime = 90;
852 recipe->starttime = recipe->endtime = (time_t)0;
853 /*
854 * Initial mash schedule, set a single-step 67 degr. mash
855 */
856 recipe->mash[0].name = xstrcpy((char *)"Mash-in");
857 recipe->mash[0].min = 20;
858 recipe->mash[0].max = 80;
859 recipe->mash[0].canskip = 0;
860 recipe->mash[0].setpoint = 68.0;
861 recipe->mash[0].skip = 0;
862 recipe->mash[0].duration = 1;
863 recipe->mash[1].name = xstrcpy((char *)"Phytase");
864 recipe->mash[1].min = 25;
865 recipe->mash[1].max = 55;
866 recipe->mash[1].canskip = 1;
867 recipe->mash[1].setpoint = 40.0;
868 recipe->mash[1].skip = 1;
869 recipe->mash[1].duration = 10;
870 recipe->mash[2].name = xstrcpy((char *)"Glucanase");
871 recipe->mash[2].min = 35;
872 recipe->mash[2].max = 50;
873 recipe->mash[2].canskip = 1;
874 recipe->mash[2].setpoint = 45.0;
875 recipe->mash[2].skip = 1;
876 recipe->mash[2].duration = 10;
877 recipe->mash[3].name = xstrcpy((char *)"Protease");
878 recipe->mash[3].min = 45;
879 recipe->mash[3].max = 60;
880 recipe->mash[3].canskip = 1;
881 recipe->mash[3].setpoint = 55.0;
882 recipe->mash[3].skip = 1;
883 recipe->mash[3].duration = 10;
884 recipe->mash[4].name = xstrcpy((char *)"B-Amylase");
885 recipe->mash[4].min = 50;
886 recipe->mash[4].max = 70;
887 recipe->mash[4].canskip = 1;
888 recipe->mash[4].setpoint = 62.0;
889 recipe->mash[4].skip = 1;
890 recipe->mash[4].duration = 30;
891 recipe->mash[5].name = xstrcpy((char *)"A-Amylase 1");
892 recipe->mash[5].min = 60;
893 recipe->mash[5].max = 76;
894 recipe->mash[5].canskip = 1;
895 recipe->mash[5].setpoint = 67.0;
896 recipe->mash[5].skip = 1;
897 recipe->mash[5].duration = 30;
898 recipe->mash[6].name = xstrcpy((char *)"A-Amylase 2");
899 recipe->mash[6].min = 60;
900 recipe->mash[6].max = 76;
901 recipe->mash[6].canskip = 0;
902 recipe->mash[6].setpoint = 67.0;
903 recipe->mash[6].skip = 0;
904 recipe->mash[6].duration = 60;
905 recipe->mash[7].name = xstrcpy((char *)"Mash-out");
906 recipe->mash[7].min = 75;
907 recipe->mash[7].max = 80;
908 recipe->mash[7].canskip = 0;
909 recipe->mash[7].setpoint = 78.0;
910 recipe->mash[7].skip = 0;
911 recipe->mash[7].duration = 10;
912
913 /*
914 * Add 2 hop additions, maximum 10
915 */
916 recipe->hops[0].name = xstrcpy((char *)"Hops 1");
917 recipe->hops[0].boiltime = 90;
918 recipe->hops[1].name = xstrcpy((char *)"Hops 2");
919 recipe->hops[1].boiltime = 5;
920 for (i = 2; i < 10; i++) {
921 recipe->hops[i].name = NULL;
922 recipe->hops[i].boiltime = 0;
923 }
924
925
926 /*
927 * Add 3 hopstands, disabled by default.
928 */
929 recipe->hopstand[0].name = xstrcpy((char *)"Hopstand hot");
930 recipe->hopstand[0].min = 88;
931 recipe->hopstand[0].max = 100;
932 recipe->hopstand[0].hold = 0;
933 recipe->hopstand[0].setpoint = 93.0;
934 recipe->hopstand[0].skip = 1;
935 recipe->hopstand[0].duration = 30;
936 recipe->hopstand[1].name = xstrcpy((char *)"Hopstand default");
937 recipe->hopstand[1].min = 72;
938 recipe->hopstand[1].max = 77;
939 recipe->hopstand[1].hold = 0;
940 recipe->hopstand[1].setpoint = 75.0;
941 recipe->hopstand[1].skip = 1;
942 recipe->hopstand[1].duration = 60;
943 recipe->hopstand[2].name = xstrcpy((char *)"Hopstand cool");
944 recipe->hopstand[2].min = 60;
945 recipe->hopstand[2].max = 66;
946 recipe->hopstand[2].hold = 0;
947 recipe->hopstand[2].setpoint = 63.0;
948 recipe->hopstand[2].skip = 1;
949 recipe->hopstand[2].duration = 60;
950
951 editRecipe(recipe);
952
953 if (recipes == NULL) {
954 recipes = recipe;
955 } else {
956 for (tmpu = recipes; tmpu; tmpu = tmpu->next) {
957 if (tmpu->next == NULL) {
958 tmpu->next = recipe;
959 break;
960 }
961 }
962 }
963 syslog(LOG_NOTICE, "Recipe %d added", number);
964 if (debug)
965 fprintf(stdout, "Recipe %d added\n", number);
966 }
967
968
969
970 void editRecipes(void)
971 {
972 int total, i, key, choice = 1;;
973 a_recipe *recipe;
974 char pmpt[81];
975
976 prompt(0, NULL);
977 for (;;) {
978 total = 0;
979 for (recipe = recipes; recipe; recipe = recipe->next) {
980 total++;
981 }
982
983 if (debug)
984 fprintf(stdout, "editRecipes total=%d choice=%d\n", total, choice);
985
986 i = 0;
987 if (total) {
988 for (recipe = recipes; recipe; recipe = recipe->next) {
989 i++;
990 if (i == choice)
991 break;
992 }
993 }
994
995 prompt(102, NULL); /* " SETUP MENU " */
996 prompt(221, NULL); /* " Select Recipe " */
997 if (total) {
998 snprintf(pmpt, Config.lcd_cols + 1, "%s", recipe->name);
999 prompt(300, pmpt);
1000 }
1001 if (total == 0)
1002 prompt(416, NULL); /* "add --- quit --- " */
1003 else if (total == 1)
1004 prompt(415, NULL); /* "add --- quit ok " */
1005 else if (total && (choice == 1))
1006 prompt(414, NULL); /* "add dwn quit ok " */
1007 else if (total && (choice == total))
1008 prompt(404, NULL); /* " up --- quit ok " */
1009 else
1010 prompt(403, NULL); /* " up dwn quit ok " */
1011
1012 key = keywait();
1013 if ((key == KEY_RETURN) || my_shutdown)
1014 return;
1015 if (total && (key == KEY_ENTER)) {
1016 editRecipe(recipe);
1017 prompt(0, NULL);
1018 }
1019 if (key == KEY_UP) {
1020 if ((total == 1) || (choice == 1))
1021 addRecipe(total + 1);
1022 else if (choice > 1)
1023 choice--;
1024 }
1025 if ((key == KEY_DOWN) && (total > 1) && (choice < total))
1026 choice++;
1027 }
1028 }
1029
1030
1031
1032 void editUnits(void)
1033 {
1034 int total, i, key, choice = 1;;
1035 units_list *unit;
1036 char pmpt[81];
1037
1038 prompt(0, NULL);
1039 for (;;) {
1040 total = 0;
1041 for (unit = Config.units; unit; unit = unit->next) {
1042 total++;
1043 }
1044
1045 if (debug)
1046 fprintf(stdout, "editUnits total=%d choice=%d\n", total, choice);
1047
1048 if (total == 0) {
1049 /*
1050 * Impossible unless first setup was skipped
1051 */
1052 addUnit(1);
1053 total = 1;
1054 } else {
1055 i = 0;
1056 for (unit = Config.units; unit; unit = unit->next) {
1057 i++;
1058 if (i == choice)
1059 break;
1060 }
1061 prompt(102, NULL); /* " SETUP MENU " */
1062 prompt(222, NULL); /* " Select Brewsystem " */
1063 snprintf(pmpt, Config.lcd_cols + 1, "%s", unit->name);
1064 prompt(300, pmpt);
1065 if (total == 1)
1066 prompt(415, NULL); /* "add --- quit ok " */
1067 else if (choice == 1)
1068 prompt(414, NULL); /* "add dwn quit ok " */
1069 else if (choice == total)
1070 prompt(404, NULL); /* " up --- quit ok " */
1071 else
1072 prompt(403, NULL); /* " up dwn quit ok " */
1073
1074 key = keywait();
1075 if ((key == KEY_RETURN) || my_shutdown)
1076 return;
1077 if (key == KEY_ENTER) {
1078 editUnit(unit);
1079 prompt(0, NULL);
1080 }
1081 if (key == KEY_UP) {
1082 if ((total == 1) || (choice == 1))
1083 addUnit(total + 1);
1084 else if (choice > 1)
1085 choice--;
1086 }
1087 if ((key == KEY_DOWN) && (total > 1) && (choice < total))
1088 choice++;
1089 }
1090 }
1091 }
1092
1093
1094
758 void setup(void) 1095 void setup(void)
759 { 1096 {
760 int key, option = 202; 1097 int key, option = 202;
761 1098
762 for (;;) { 1099 for (;;) {
763 if (debug) 1100 if (debug)
764 fprintf(stdout, "setup() option=%d\n", option); 1101 fprintf(stdout, "setup() option=%d\n", option);
765 prompt(0, NULL); 1102 prompt(0, NULL);
766 prompt(102, NULL); 1103 prompt(102, NULL); /* " SETUP MENU " */
767 prompt(option, NULL); 1104 prompt(option, NULL);
768 if (option == 202) 1105 if (option == 202)
769 prompt(402, NULL); 1106 prompt(402, NULL); /* "--- dwn quit ok " */
770 #ifdef USE_SIMULATOR 1107 #ifdef USE_SIMULATOR
771 else if (option == 205) 1108 else if (option == 205)
772 #else 1109 #else
773 else if (option == 204) 1110 else if (option == 204)
774 #endif 1111 #endif
775 prompt(404, NULL); 1112 prompt(404, NULL); /* " up --- quit ok " */
776 else 1113 else
777 prompt(403, NULL); 1114 prompt(403, NULL); /* " up dwn quit ok " */
778 1115
779 key = keywait(); 1116 key = keywait();
780 1117
781 if ((key == KEY_RETURN) || my_shutdown) 1118 if ((key == KEY_RETURN) || my_shutdown)
782 return; 1119 return;
791 option++; 1128 option++;
792 } 1129 }
793 1130
794 if (key == KEY_ENTER) { 1131 if (key == KEY_ENTER) {
795 switch(option) { 1132 switch(option) {
796 case 202: // recipes 1133 case 202: editRecipes();
797 break; 1134 break;
798 case 203: editUnit(Config.units); /* If more units, via a selector */ 1135 case 203: editUnits();
799 break; 1136 break;
800 case 204: // devices 1137 case 204: // devices
801 break; 1138 break;
802 #ifdef USE_SIMULATOR 1139 #ifdef USE_SIMULATOR
803 case 205: // simulator 1140 case 205: // simulator

mercurial