//============================================================================ // Name : EDLS.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include "EDLS.h" int main() { PowerStatus = true; sq = -1; ClosedSensorInput = -1; ManualLockInput = -1; KeyInput = -1; NumberButtonInput = -1; CoverInput = -1; for (int i = 0; i < 5; i++) { InputData[i] = -1; } for (int i = 0; i < 4; i++) { Saved[i] = -1; } StartCS = -1; StartNB = -1; StartCvr = -1; StartPW = -1; AlarmCS = false; AlarmNB = false; AlarmCvr = false; AlarmPW = false; Passed = false; Passedpw = false; while ( true ) { if ( PowerStatus == true ) { cout << "¼ýÀÚÅ° ÀÔ·Â : "; cin >> NumberButtonInput; } else { cout << "´ÝÈû¼¾¼­ÀνÄ(1¿­¸²,0´ÝÈû,-1¹«½Ã) : "; cin >> ClosedSensorInput; cout << "¼öµ¿Àá±Ý¹öÆ°(1Àá±Ý,-1¹«½Ã) : "; cin >> ManualLockInput; cout << "¿­¼èÀνÄ(1°³¹æ,-1¹«½Ã) : "; cin >> KeyInput; cout << "¼ýÀÚÅ°ÀÔ·Â(0~9ÀÔ·Â,-1¹«½Ã) : "; cin >> NumberButtonInput; cout << "Ä¿¹ö»óÅÂÀνÄ(1¿­¸²,0´ÝÈû,-1¹«½Ã) : "; cin >> CoverInput; } LockUnlockControl(); AlertControl(); BacklightControl(); } return 0; } /****************** ÇÏÀ§ ÇÔ¼ö *******************/ void LockUnlockControl() { int Input = DetermineLockUnlock(); if ( Input == 0 ) { UnlockInterface(); } else if ( Input == 1 ) { LockInterface(); } } void AlertControl() { int Input_1 = DetermineAlert(); int Input_2 = PasswordTimeover(); if ( Input_1 == 1 ) { Alert1Interface(); } else if ( Input_1 == 2 ) { Alert2Interface(); } else if ( Input_1 == 3 || Input_2 == 3 ) { Alert3Interface(); } } void BacklightControl() { int Input_1 = DetermineBacklight(); int Input_2 = BacklightOnPW(); int Input_3 = BacklightOffPW(); if ( Input_1 == 0 || Input_3 == 1 ) { LightOffInterface(); for (int i = 0; i < 5; i++) { InputData[i] = -1; } } else if ( Input_1 == 1 || Input_2 == 1) { LightOnInterface(); for (int i = 0; i < 5; i++) { InputData[i] = -1; } } sq = -1; } void LockInterface() { cout << "\nÀá±ÝÀåÄ¡ Àá±è\n" << endl; } void UnlockInterface() { cout << "\nÀá±ÝÀåÄ¡ ¿­¸²\n" << endl; } void Alert1Interface() { cout << "\n°æ°íÀ½1\n" << endl; } void Alert2Interface() { cout << "\n°æ°íÀ½2\n" << endl; } void Alert3Interface() { cout << "\n°æ°íÀ½3\n" << endl; } void LightOnInterface() { cout << "\n¹é¶óÀÌÆ® ÄÑÁü\n" << endl; } void LightOffInterface() { cout << "\n¹é¶óÀÌÆ® ²¨Áü\n" << endl; } int DetermineLockUnlock() { ClosedSensorOpened(); ClosedSensorClosed(); int Lock_1 = ClosedSensorLock(); int Lock_2 = ManualLockReceiver(); int Unlock_1 = KeyReceiver(); int Unlock_2 = NumberCheck(true); if ( Lock_1 == 1 || Lock_2 == 1) { return 1; } else if ( Unlock_1 == 1 || Unlock_2 == 1 ) { return 0; } else { return -1; } } int DetermineAlert() { int Input_1 = NumberCheck(false); int Input_2 = NumberTimeover(); if ( Input_1 == 1 ) { return 1; } else if ( Input_1 == 2 ) { return 2; } else if ( Input_2 == 3) { return 3; } else { return -1; } } int DetermineBacklight() { int On_1 = BacklightOn(); int On_2 = LightOn(); int Off_1 = BacklightOff(); int Off_2 = LightOff(); if ( On_1 == 1 || On_2 == 1 ) { return 1; } else if ( Off_1 == 1 || Off_2 == 1 ) { return 0; } else { return -1; } } int PasswordTimeover() { if ( PowerStatus == false ) { return -1; } if ( AlarmPW == true ) { return 3; } else { return -1; } } int BacklightOnPW() { if ( Passedpw == true ) { return -1; } if ( PowerStatus == false ) { return -1; } int Input = PasswordSetup(); if ( Input == 1 ) { return 1; } else { return -1; } } int BacklightOffPW() { if ( Passedpw == true ) { Passedpw = false; return 1; } if ( PowerStatus == false ) { return -1; } if ( AlarmPW == true ) { return 1; } else { return -1; } } int ClosedSensorLock() { if (AlarmCS == true) { return 1; } else { return -1; } } int ManualLockReceiver() { int Input = InputFilter(false, 1); if ( Input == 1 ) { return 1; } else { return -1; } } int NumberCheck(bool lu) { static int result; int *Input = new int[4]; if ( lu == false ) { return result; } NumberRecord(&Input); if ( Input == NULL ) // ÀÔ·ÂÀÌ ¾øÀ¸¸é -1 ¸®ÅÏ { result = -1; return -1; } for (int i = 0; i < 4; i++) { if ( Saved[i] != Input[i] ) { //StartNB = -1; // ºÒÇÕ°ÝÀ̹ǷΠ¾Ë¶÷ Á¦°Å NPassed = true; result = 2; return 2; } } //StartNB = -1; // ÇÕ°ÝÀ̹ǷΠ¾Ë¶÷ Á¦°Å Passed = true; result = 1; return 1; } int KeyReceiver() { int Input = InputFilter(false, 2); if ( Input == 1 ) { return 1; } else { return -1; } } void ClosedSensorOpened() { if ( ClosedSensorReceiver() == 1 ) { StartCS = -1; } } void ClosedSensorClosed() { if ( ClosedSensorReceiver() == 0) { if ( StartCS == -1 ) { TIMER(TimerCS); // TimerCS ½º·¹µå ÀÛµ¿ } else { StartCS = clock(); } } } int NumberTimeover() { if ( AlarmNB == true ) // ¹ö±×ÇØ°áÀ» À§ÇØ º¯¼öÃß°¡ { if ( Passed ) { Passed = false; return -1; } if ( NPassed == true ) { NPassed = false; return -1; } return 3; } else { return -1; } } int BacklightOn() { int Input = NumberButtonReceiver(false); if ( Input >= 0 && Input <= 9) { if ( StartCvr != -1 ) // ¹é¶óÀÌÆ®°¡ ÄÑÁú °ÍÀ̹ǷΠĿ¹öµµ °»½Å { StartCvr = -1; } return 1; } else { return -1; } } int BacklightOff() { if ( AlarmNB == true) { return 1; } else { return -1; } } int LightOn() { int Input = CoverReceiver(); if ( Input == 1 ) { if ( StartCvr == -1 ) { TIMER(TimerCvr); // TimerCvr ½º·¹µå ÀÛµ¿ } else { StartCvr = clock(); } return 1; } else { return -1; } } int LightOff() { int Input = CoverReceiver(); if ( Input == 0 || AlarmCvr == true ) { return 1; } else { return -1; } } int PasswordSetup() { static int Temp[4] = {-1, -1, -1, -1}; int Input = InputFilter(true, 3); if ( Input >= 0 && Input <= 9 ) // ÀԷ¹ÞÀº °ªÀÌ 0 ~ 9 ÀÏ °æ¿ì { if ( StartPW == -1 ) { TIMER(TimerPW); // TimerPW ½º·¹µå ÀÛµ¿ } else { StartPW = clock(); } if ( AlarmPW == true ) // ¾Ë¶÷ÀÌ ¿ï·ÈÀ» °æ¿ì ÃʱâÈ­ÇÏ°í ¹öÆ°´­¸² ¾Ë¸² { for (int i = 0; i < 4; i++) { Temp[i] = -1; } return 1; } else if ( Temp[0] == -1 ) // Àӽðø°£ ù¹ø°ĭÀÌ ºñ¾úÀ» °æ¿ì { Temp[0] = Input; return 1; } else if ( Temp[1] == -1 ) // Àӽðø°£ µÎ¹ø°ĭÀÌ ºñ¾úÀ» °æ¿ì { Temp[1] = Input; return 1; } else if ( Temp[2] == -1 ) // Àӽðø°£ ¼¼¹ø°ĭÀÌ ºñ¾úÀ» °æ¿ì { Temp[2] = Input; return 1; } else if ( Temp[3] == -1 ) // Àӽðø°£ ³×¹ø°ĭÀÌ ºñ¾úÀ» °æ¿ì ÀúÀåÇÏ°í ÃʱâÈ­ { Temp[3] = Input; int Result[4]; for (int i = 0; i < 4; i++) { Result[i] = Temp[i]; Temp[i] = -1; } PasswordSave(Result); // Æнº¿öµå ÀúÀå return 1; } } if ( AlarmPW == true ) // ¾Ë¶÷ÀÌ ¿ï·ÈÀ» °æ¿ì ÃʱâÈ­ { for (int i = 0; i < 4; i++) { Temp[i] = -1; } } return -1; } int ClosedSensorReceiver() { int Input = InputFilter(false, 0); if ( Input == 0 ) { return 0; } else if ( Input == 1 ) { return 1; } else { return -1; } } void NumberRecord(int** Result) { static int Temp[4] = {-1, -1, -1, -1}; int Input = NumberButtonReceiver(true); if ( Input >= 0 && Input <= 9 ) // ÀԷ¹ÞÀº °ªÀÌ 0 ~ 9 ÀÏ °æ¿ì { if ( AlarmNB == true ) // ¾Ë¶÷ÀÌ ¿ï·ÈÀ» °æ¿ì ÃʱâÈ­ÇÏ°í ¹öÆ°´­¸² ¾Ë¸² { for (int i = 0; i < 4; i++) { Temp[i] = -1; } *Result = NULL; return; } else if ( Temp[0] == -1 ) // Àӽðø°£ ù¹ø°ĭÀÌ ºñ¾úÀ» °æ¿ì { Temp[0] = Input; *Result = NULL; return; } else if ( Temp[1] == -1 ) // Àӽðø°£ µÎ¹ø°ĭÀÌ ºñ¾úÀ» °æ¿ì { Temp[1] = Input; *Result = NULL; return; } else if ( Temp[2] == -1 ) // Àӽðø°£ ¼¼¹ø°ĭÀÌ ºñ¾úÀ» °æ¿ì { Temp[2] = Input; *Result = NULL; return; } else if ( Temp[3] == -1 ) // Àӽðø°£ ³×¹ø°ĭÀÌ ºñ¾úÀ» °æ¿ì ÀúÀåÇÏ°í ÃʱâÈ­ { Temp[3] = Input; for (int i = 0; i < 4; i++) // ÇöÀç Àӽøñ·ÏÀ» Á¦°Å { *(*Result+i) = Temp[i]; Temp[i] = -1; } return; } } else { if ( AlarmNB == true ) // ¾Ë¶÷ÀÌ ¿ï·ÈÀ» °æ¿ì ÃʱâÈ­ { for (int i = 0; i < 4; i++) { Temp[i] = -1; } } *Result = NULL; } } int NumberButtonReceiver(bool nr) { if ( PowerStatus == true ) { return -1; } static int result; if ( nr == false ) { return result; } int Input = InputFilter(false, 3); if ( Input >= 0 && Input <= 9 ) { if ( StartNB == -1 ) { TIMER(TimerNB); // TimerNB ½º·¹µå ÀÛµ¿ } else { StartNB = clock(); } result = Input; return Input; } else { result = -1; return -1; } } void PasswordSave(int* Input) { if ( Input == NULL ) { return; } else { for (int i = 0; i < 4; i++) { Saved[i] = Input[i]; } PowerStatus = false; StartPW = -1; // ¾ÏÈ£¼³Á¤ÀÌ ³¡³µ´Ù¸é ¾Ë¶÷À» Ãë¼Ò Passedpw = true; } } int CoverReceiver() { int Input = InputFilter(false, 4); if ( Input == 0 ) { return 0; } else if ( Input == 1 ) { return 1; } else { return -1; } } int InputFilter(bool pw, int sq_I) { if ( PowerStatus == true ) // ¾ÏÈ£ÃʱâÈ­°¡ ¾È µÇ¾î ÀÖÀ¸¸é ¹«Á¶°Ç ¼ýÀÚÅ°¹öÆ°¸¸ ¹Ýȯ { if ( pw == false ) { return -1; } if ( sq == -1 ) { return NumberButtonInput; } else { return -1; } } else { if ( sq == -1) // Ãʱâ»óÅÂ(sq == -1)¿¡¼­¸¸ ¼¾¼­ÀÎ½Ä ¼öÇà { sq = sq_I; // ¼¾¼­ÀÎ½Ä ¼öÇàÇÔÀ» ¾Ë¸² InputData[0] = ClosedSensorInput; ClosedSensorInput = -1; InputData[1] = ManualLockInput; ManualLockInput = -1; InputData[2] = KeyInput; KeyInput = -1; InputData[3] = NumberButtonInput; NumberButtonInput = -1; InputData[4] = CoverInput; CoverInput = -1; } else { sq = sq_I; } return InputData[sq]; } } DWORD WINAPI TimerCS(LPVOID arg) { if ( AlarmCS == true ) { return 0; } StartCS = clock(); clock_t end; while (true) { end = clock(); if ( StartCS == -1 ) { return 0; } else if (end - StartCS >= 3000) { break; } } AlarmCS = true; LockUnlockControl(); AlertControl(); BacklightControl(); AlarmCS = false; StartCS = -1; return 0; } DWORD WINAPI TimerNB(LPVOID arg) { if ( AlarmNB == true ) { return 0; } StartNB = clock(); clock_t end; while (true) { end = clock(); if ( StartNB == -1 ) { return 0; } else if (end - StartNB >= 10000) { break; } } AlarmNB = true; LockUnlockControl(); AlertControl(); BacklightControl(); AlarmNB = false; StartNB = -1; return 0; } DWORD WINAPI TimerCvr(LPVOID arg) { if ( AlarmCvr == true ) { return 0; } StartCvr = clock(); clock_t end; while (true) { end = clock(); if ( StartCvr == -1 ) { return 0; } else if (end - StartCvr >= 10000) { break; } } AlarmCvr = true; LockUnlockControl(); AlertControl(); BacklightControl(); AlarmCvr = false; StartCvr = -1; return 0; } DWORD WINAPI TimerPW(LPVOID arg) { if ( AlarmPW == true ) { return 0; } StartPW = clock(); clock_t end; while (true) { end = clock(); if ( StartPW == -1 ) { return 0; } else if (end - StartPW >= 10000) { break; } } AlarmPW = true; LockUnlockControl(); AlertControl(); BacklightControl(); AlarmPW = false; StartPW = -1; return 0; }