#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #define BOOL int #define TRUE 1 #define FALSE 0 #include #include #include "getch.h" #include "kbhit.h" #include #include DWORD startTickCount;//ƽ Ä«¿îÆ® Ãß°¡ DWORD currentTickCount; int maincnt = 0; typedef enum mode { nothing = 0, idle_mode = 1, pulverizing_mode = 2, heat_mode = 3, temperature_setting_mode = 11, reservation_mode = 12, clean_mode = 13, concentration_mode = 14, power_mode = 15, extraction_mode = 16, supply_mode = 17 }mode; typedef struct reservation_button { BOOL take_button; int time; }reservation_button; typedef struct button_data { int temperature_button;//on off struct reservation_button book;//on off BOOL clean_button;//on off int concentration_button;//on off BOOL power_button;//on off BOOL coffee_extraction;//on off }button_data; typedef struct amount_data { int water_amount; int coffee_amount; int powder_amount; }amount_data; typedef struct status { button_data button; amount_data amount; int trash; //1ÀÌ ¾²·¹±â Á¸Àç 0ÀÌ ¾²·¹±â ¾øÀ½ mode mod; int take_button; int temperature; int concentration; int re_time;//¿¹¾à½Ã°£ int re_work;//ÇؾßÇÒ ÀÏ }status; status s_data = { { 1,{ FALSE,0 },FALSE,100,TRUE,FALSE },{ 100,15,0 },1,nothing,0 ,1,2,0,0 }; //±âº» ¼ÂÆà ¹öÆ° : BUTTON_data{¿Âµµ:FALSE(¿Â),¹öÆ° ´Ù ´­·ÁÁ® ÀÖÁö ¾Ê°í(FALSE), ³óµµ:200,power:on} amount_Data{¹°=1000,Ä¿ÇÇ°¡·ç15,Ä¿ÇÇ°¡·ç=0} trash=¾øÀ½, mode=nothing char getKey(); int water_sensor(); int coffee_sensor(); int powder_sensor(); int temperature_button_interface(); int reservation_button_interface(); int clean_button_interface(); int concentration_button_interface(); int power_button_interface(); int coffee_extraction_interface(); void water_sensor_interface(); void coffee_sensor_interface(); void powder_sensor_interface(); void determine_button_data(int a); int determine_sensor_data(); void main_controller(); void idle(); void pulverizing(); void heat(); void extraction(); void clean(); void reservation(); void concentration_setting(); void temperature_setting(); void supply(); void display_interface(); void alarm_controller(); void water_lack();; void coffee_lack(); void trash_lack(); void motor_interface(char* motorcommand); void cleaner_interface(); void setting(int a); void supply_interface(int temp1,int temp2); void alarm_display_interface(int temp); void speaker_interface(int temp); int main(void) { main_controller(); return 0; } int water_sensor() { return s_data.amount.water_amount; } int coffee_sensor() { return s_data.amount.coffee_amount; } int powder_sensor() { return s_data.amount.powder_amount; } int temperature_button_interface() { int temp = 0; printf("temperature_button_interface() Á¤»ó ÀÛµ¿\n"); if (s_data.button.temperature_button==2) { temp = 1; } else if (s_data.button.temperature_button == 1) { temp = 2; } s_data.button.temperature_button = temp; return s_data.button.temperature_button; } int reservation_button_interface() { char key; int temp = 0; int act = 0; printf("reservation_button_interface() Á¤»ó ÀÛµ¿\n"); printf("¿øÇÏ´Â ¿¹¾à ½Ã°£À» ÀÔ·ÂÇϼ¼¿ä\n"); scanf("%d", &temp); s_data.button.book.time = temp; printf("¿øÇÏ´Â ¿¹¾à µ¿ÀÛÀ» °í¸£¼¼¿ä E. û¼Ò Y. Ä¿ÇÇÃßÃâ\n"); while (1) { key = (int)getKey(); if (key == 101 || key == 69) { act = 1; break; } else if (key == 121 || key == 89) { act = 2; break; } if (key == 116 || key == 84) { s_data.mod = idle_mode; s_data.button.power_button = FALSE; main_controller(); } } //scanf_s("%d", &act); s_data.button.book.take_button = act; return s_data.button.book.time; } int clean_button_interface() { printf("clean_button_interface() Á¤»ó ÀÛµ¿\n"); return TRUE; } int concentration_button_interface() { char key; int temp; printf("concentration_button_interface() Á¤»ó ÀÛµ¿\n"); printf("¹Ù²Ü·Á´Â ³óµµ¸¦ ÀÔ·ÂÇϼ¼¿ä\n A. 100mL, S. 200mL, D. 300mL \n"); while (1) { key = getKey(); if (key == 97 || key == 65) { temp = 1; break; } else if (key == 115 || key == 83) { temp = 2; break; } else if (key == 100 || key == 68) { temp = 3; break; } if (key == 116 || key == 84) { s_data.mod = idle_mode; s_data.button.power_button = FALSE; main_controller(); } } return temp; } int power_button_interface() { //printf("power_button_interface() Á¤»ó ÀÛµ¿\n"); return FALSE; } int coffee_extraction_interface() { //printf("coffee_extraction_interface() Á¤»ó ÀÛµ¿\n"); return TRUE; } void water_sensor_interface() { int temp = water_sensor(); if (temp < s_data.button.concentration_button) printf("¹°ÀÌ ºÎÁ·ÇÕ´Ï´Ù."); } void coffee_sensor_interface() { int temp = coffee_sensor(); if (temp < 10) printf("Ä¿ÇÇ°¡·ç°¡ ºÎÁ·ÇÕ´Ï´Ù"); } void powder_sensor_interface() { int temp = powder_sensor(); if (temp == 1) printf("û¼Ò°¡ ÇÊ¿äÇÕ´Ï´Ù."); } void determine_button_data(int temp) { if (temp == 1) // ¿Âµµ temperature_button_interface(); else if (temp == 2) reservation_button_interface(); else if (temp == 3) s_data.button.clean_button = clean_button_interface(); else if (temp == 4) s_data.button.concentration_button = concentration_button_interface(); else if (temp == 5) s_data.button.power_button = power_button_interface(); else if (temp == 6) s_data.button.coffee_extraction = coffee_extraction_interface(); else if (temp == 7) supply(); } int determine_sensor_data() { int temp = water_sensor() + coffee_sensor() + powder_sensor(); if (temp >= 1) return 0; else return 1; } void main_controller() { //char strFolderPath[] = { "C:\\SE\\T4" }; mkdir("C:\\SE", 0755); mkdir("C:\\SE\\T4",0755); char key; FILE *f; f = fopen("C:\\SE\\T4\\s_data.txt", "r"); if (maincnt == 0 && f != NULL) { fscanf(f, "%d %d %d %d %d %d %d", &s_data.amount.coffee_amount, &s_data.amount.powder_amount, &s_data.amount.water_amount, &s_data.concentration, &s_data.temperature, &s_data.trash); fclose(f); maincnt += 1; } printf("main_controller µ¿ÀÛ\n"); while (1) { system("clear"); display_interface(); if (s_data.mod == nothing) { alarm_controller(); } printf("¿øÇÏ´Â ¹öÆ° ÀÔ·Â Q.¿Âµµ¼³Á¤ W.¿¹¾à E.û¼Ò R.³óµµ T.Àü¿ø Y.Ä¿ÇÇÃßÃâ U.º¸±Þ I.Ä¿ÇÇ°¡·ç Á¦°Å\n"); while (s_data.mod == nothing) { s_data.button.power_button = TRUE; key = (int)getKey(); /*if(key!='\0') { printf("%c", key); printf("%d", key); } */ if (key == 113 || key == 81) { s_data.mod = temperature_setting_mode; break; } else if (key == 119 || key == 87) { s_data.mod = reservation_mode; break; } else if (key == 101 || key == 69) { s_data.mod = clean_mode; break; } else if (key == 114 || key == 82) { s_data.mod = concentration_mode; break; } else if (key == 121 || key == 89) { s_data.mod = idle_mode; break; } else if (key == 117 || key == 85) { s_data.mod = supply_mode; system("clear"); display_interface(); break; } else if (key == 116 || key == 84) { s_data.button.power_button = FALSE; s_data.mod = power_mode; break; } else if (key == 73 || key == 105) { s_data.trash = 0; s_data.mod = nothing; break; } } // motor_interface(); cleaner_interface(); setting(); supply_interface(); determine_button_data(s_data.mod - 10); if (s_data.mod == clean_mode) { system("clear"); display_interface(); clean(); } if (s_data.mod == temperature_setting_mode) temperature_setting(); if (s_data.mod == concentration_mode) concentration_setting(); if (s_data.mod == heat_mode) heat(); if (s_data.mod == pulverizing_mode) pulverizing(); if (s_data.mod == extraction_mode) extraction(); if (s_data.mod == idle_mode) { idle(); } else if (s_data.mod == reservation_mode) { reservation(); startTickCount = GetTickCount(); system("clear"); display_interface(); while (1) { key = (int)getKey(); if (key == 116 || key == 84) { s_data.mod = idle_mode; s_data.button.power_button = FALSE; main_controller(); return; } currentTickCount = GetTickCount(); if ((currentTickCount - startTickCount) >= 1000) { startTickCount = GetTickCount(); s_data.re_time = s_data.re_time - 1; system("clear"); display_interface(); } if (s_data.re_time <= 0) { s_data.re_time = 0; if (s_data.re_work == 1) { s_data.mod = clean_mode; } else if (s_data.re_work == 2) { s_data.mod = idle_mode; } break; } } } if (s_data.button.power_button == FALSE) { printf("Ä¿ÇÇ ¸Ó½Å off \n"); f = fopen("C:\\SE\\T4\\s_data.txt", "w"); fprintf(f, "%d %d %d %d %d %d", s_data.amount.coffee_amount, s_data.amount.powder_amount, s_data.amount.water_amount, s_data.concentration, s_data.temperature, s_data.trash); fclose(f); exit(0); } } } void idle() { char* motorcommand = "idle ½ÇÇà"; motor_interface(motorcommand); startTickCount = GetTickCount(); printf("idle ÀÛµ¿ \n"); if (s_data.button.power_button == FALSE) { s_data.mod = power_mode; main_controller(); return; } if (s_data.amount.water_amount >= s_data.concentration*100 && s_data.mod == idle_mode && s_data.trash == FALSE) { if (s_data.amount.powder_amount == FALSE && s_data.amount.coffee_amount >= 10) { s_data.mod = pulverizing_mode; } else if (s_data.amount.powder_amount == TRUE && s_data.temperature == 2) { s_data.mod = heat_mode; } else if (s_data.amount.powder_amount == TRUE && s_data.temperature == 1) { s_data.mod = extraction_mode; } else { s_data.mod = nothing; } main_controller(); return; } else { s_data.mod = nothing; main_controller(); return; } } void pulverizing() { char key; char* motorcommand = "ºÐ¼â ½ÇÇà"; motor_interface(motorcommand); s_data.amount.coffee_amount -= 10; s_data.amount.powder_amount = TRUE; while (1) { key = (int)getKey(); currentTickCount = GetTickCount(); if (s_data.temperature == 2 && currentTickCount - startTickCount >= 5000) { startTickCount = GetTickCount(); s_data.mod = heat_mode; main_controller(); return; } if (s_data.temperature == 1 && currentTickCount - startTickCount >= 5000) { startTickCount = GetTickCount(); s_data.mod = extraction_mode; main_controller(); return; } if (key == 116 || key == 84) { s_data.mod = idle_mode; s_data.button.power_button = FALSE; main_controller(); return; } } } void heat() { char key; char* motorcommand = "°¡¿­ ½ÇÇà"; motor_interface(motorcommand); while (1) { key = (int)getKey(); currentTickCount = GetTickCount(); if (currentTickCount - startTickCount >= 10000) { startTickCount = GetTickCount(); s_data.mod = extraction_mode; main_controller(); return; } if (key == 116 || key == 84) { s_data.mod = idle_mode; s_data.button.power_button = FALSE; main_controller(); return; } } } void extraction() { char key; int temp = 0; //s_data.mod=extraction_mode; char* motorcommand = "ÃßÃâ ½ÇÇà"; motor_interface(motorcommand); s_data.amount.water_amount -= s_data.concentration*100; s_data.amount.powder_amount = FALSE; s_data.trash = TRUE; while (1) { key = (int)getKey(); currentTickCount = GetTickCount(); if (currentTickCount - startTickCount >= 10000&&temp==0) { printf("Ä¿ÇÇ°¡ ÃßÃâµÇ¾ú½À´Ï´Ù.\n"); temp = 1; } if (currentTickCount - startTickCount >= 11000) { startTickCount = GetTickCount(); s_data.mod = nothing; main_controller(); return; } if (key == 116 || key == 84) { s_data.mod = idle_mode; s_data.button.power_button = FALSE; main_controller(); return; } } } void clean() { //printf("clean() ÀÛµ¿\n"); if (s_data.amount.water_amount >= 500) { cleaner_interface(); return; } else { printf("¹°ÀÌ ºÎÁ·Çؼ­ û¼Ò¸¦ ÇÒ ¼ö ¾ø½À´Ï´Ù.\n"); s_data.mod = nothing; return; } } void reservation() { setting(2); //s_data.mod = nothing; } void concentration_setting() { setting(4); s_data.mod = nothing; } void temperature_setting() { setting(1); s_data.mod = nothing; } void supply() { int temp1 = 0; int temp2 = 0; printf("º¸±ÞÇÒ °ÍÀ» ÀÔ·ÂÇϼ¼¿ä. 1.Ä¿ÇÇ°¡·ç, 2.¹°, 3.¿øµÎ\n"); scanf("%d", &temp1); if (temp1 == 1) { if (s_data.amount.powder_amount == 1) { printf("Ä¿ÇÇ°¡·ç°¡ ÀÌ¹Ì ÃÖ´ëÀÔ´Ï´Ù.\n"); s_data.mod = nothing; return; } } else if (temp1 == 2) { if (s_data.amount.water_amount >= 1000) { printf("¹°ÀÌ ÀÌ¹Ì ÃÖ´ëÀÔ´Ï´Ù.\n"); s_data.mod = nothing; return; } printf("¾ó¸¶³ª ³ÖÀ»±î¿ä? ÃÖ´ë:1000\n"); scanf("%d", &temp2); } else if (temp1 == 3) { if (s_data.amount.coffee_amount >= 20) { printf("¿øµÎ°¡ ÀÌ¹Ì ÃÖ´ëÀÔ´Ï´Ù.\n"); s_data.mod = nothing; return; } printf("¾ó¸¶³ª ³ÖÀ»±î¿ä? ÃÖ´ë:100\n"); scanf("%d", &temp2); } supply_interface(temp1,temp2); return; } void display_interface() { int re_t = 0; time_t timer; struct tm *t; timer = time(NULL); t = localtime(&timer); re_t = s_data.re_time; printf("ÇöÀç½Ã°£: %02d:%02d:%02d\n",t->tm_hour,t->tm_min,t->tm_sec); if (s_data.mod == nothing || s_data.mod == idle_mode) printf("ÇöÀç »óÅÂ: ´ë±âÁß \n"); else if (s_data.mod == pulverizing_mode) printf("ÇöÀç »óÅÂ: ºÐ¼âÁß \n"); else if (s_data.mod == heat_mode) printf("ÇöÀç »óÅÂ: °¡¿­Áß \n"); else if (s_data.mod == extraction_mode) printf("ÇöÀç »óÅÂ: ÃßÃâÁß \n"); else if (s_data.mod == clean_mode) printf("ÇöÀç »óÅÂ: û¼ÒÁß \n"); else if (s_data.mod == reservation_mode) printf("ÇöÀç »óÅÂ: ¿¹¾àÁß \n"); else if (s_data.mod == supply_mode) printf("ÇöÀç »óÅÂ: º¸ÃæÁß \n"); printf("Ä¿ÇÇÀÇ ¾ç: %d g\n", s_data.amount.coffee_amount); if (s_data.amount.powder_amount == TRUE) { printf("Ä¿ÇÇ°¡·ç Á¸ÀçÀ¯¹«: Á¸Àç\n"); } else { printf("Ä¿ÇÇ°¡·ç Á¸ÀçÀ¯¹«: Á¸ÀçÇÏÁö ¾ÊÀ½\n"); } printf("¹°ÀÇ ¾ç: %d mL\n", s_data.amount.water_amount); printf("¿¹¾à ³²Àº ½Ã°£: %d½Ã ", re_t / 3600); re_t = re_t % 3600; printf("%dºÐ ", re_t / 60); re_t = re_t % 60; printf("%dÃÊ \n", re_t); if (s_data.temperature == 1) printf("¿Âµµ: ³Ã \n"); else if (s_data.temperature == 2) printf("¿Âµµ: ¿Â \n"); printf("³óµµ: %dmL \n", s_data.concentration * 100); //printf("display_interface() ÀÛµ¿\n"); } void alarm_controller() { //printf("alarm_controller() Á¤»ó ÀÛµ¿\n"); water_lack(); coffee_lack(); trash_lack(); } void water_lack() { if (s_data.amount.water_amount= temp) { system("clear"); display_interface(); temp += 1000; } if (currentTickCount - startTickCount >= 10000) { startTickCount = GetTickCount(); s_data.mod = nothing; main_controller(); return; } } //printf("cleaner_interface() ÀÛµ¿\n"); } void setting(int a) { if (a == 1) s_data.temperature = s_data.button.temperature_button; if (a == 2) { s_data.re_work = s_data.button.book.take_button; s_data.re_time = s_data.button.book.time; } if (a == 4) s_data.concentration = s_data.button.concentration_button; } void supply_interface(int temp1,int temp2) { //printf("supply_interface() Á¤»ó ÀÛµ¿\n"); if (temp1 == 1) { s_data.amount.powder_amount = 1; } else if (temp1 == 2) { s_data.amount.water_amount += temp2; if (s_data.amount.water_amount >= 1000) { s_data.amount.water_amount = 1000; } } else if (temp1 == 3) { s_data.amount.coffee_amount += temp2; if (s_data.amount.coffee_amount >= 100) { s_data.amount.coffee_amount = 100; } } printf("º¸±Þ ¿Ï·á \n"); s_data.mod = nothing; return; } void alarm_display_interface(int temp) { if (temp == 1) { printf("¹° ºÎÁ·(ÀÜ·® %dml)\n",s_data.amount.water_amount); } else if (temp == 2) { printf("¿øµÎ ºÎÁ·(%dg)\n", s_data.amount.coffee_amount); } else if (temp == 3) { printf("Ä¿ÇÇ°¡·çÁ¦°ÅÇÊ¿ä \n"); } //printf("alarm_display_interface(int temp) Á¤»ó ÀÛµ¿\n"); } void speaker_interface(int temp) { if (temp == 1) { printf("\a"); } else if (temp == 2) { printf("\a"); printf("\a"); printf("\a"); } else if (temp == 3) { printf("\a"); printf("\a"); } //printf("spekaer_interface() Á¤»ó ÀÛµ¿\n"); } char getKey() { if (kbhit()) { return getch(); } return '\0'; }