コード例 #1
0
ファイル: keyboard.cpp プロジェクト: NickPepper/scummvm
int AgiEngine::waitAnyKey() {
	int key = 0;

	clearKeyQueue();

	debugC(3, kDebugLevelInput, "waiting... (any key)");
	while (!(shouldQuit() || _restartGame)) {
		wait(10);
		key = doPollKeyboard();
		if (key)
			break;
	}
	return key;
}
コード例 #2
0
ファイル: keyboard.cpp プロジェクト: NickPepper/scummvm
int AgiEngine::waitKey() {
	int key = 0;

	clearKeyQueue();

	debugC(3, kDebugLevelInput, "waiting...");
	while (!(shouldQuit() || _restartGame || getFlag(VM_FLAG_RESTORE_JUST_RAN))) {
		wait(10);
		key = doPollKeyboard();
		if (key == AGI_KEY_ENTER || key == AGI_KEY_ESCAPE || key == AGI_MOUSE_BUTTON_LEFT)
			break;
	}
	return key;
}
コード例 #3
0
ファイル: keyboard.cpp プロジェクト: 0xf1sh/scummvm
int AgiEngine::waitAnyKey() {
	int key = 0;

	clearKeyQueue();

	debugC(3, kDebugLevelInput, "waiting... (any key)");
	while (!(shouldQuit() || _restartGame)) {
		pollTimer();
		key = doPollKeyboard();
		if (key)
			break;
		_gfx->doUpdate();
	}

	// Have to clear it as original did not set this variable, and we do it in doPollKeyboard()
	_game.keypress = 0;

	return key;
}
コード例 #4
0
ファイル: keyboard.cpp プロジェクト: 0xf1sh/scummvm
int AgiEngine::waitKey() {
	int key = 0;

	clearKeyQueue();

	debugC(3, kDebugLevelInput, "waiting...");
	while (!(shouldQuit() || _restartGame || getflag(fRestoreJustRan))) {
		pollTimer();
		key = doPollKeyboard();
		if (key == KEY_ENTER || key == KEY_ESCAPE || key == BUTTON_LEFT)
			break;

		pollTimer();
		updateTimer();

		_gfx->doUpdate();
	}

	// Have to clear it as original did not set this variable, and we do it in doPollKeyboard()
	// Fixes bug #2823759
	_game.keypress = 0;

	return key;
}
コード例 #5
0
ファイル: predictive.cpp プロジェクト: St0rmcrow/scummvm
bool AgiEngine::predictiveDialog() {
	int key = 0, active = -1, lastactive = 0;
	bool rc = false;
	uint8 x;
	int y;
	int bx[17], by[17];
	Common::String prefix;
	char temp[MAXWORDLEN + 1], repeatcount[MAXWORDLEN];
	AgiBlock tmpwindow;
	bool navigationwithkeys = false;
	bool processkey;

	const char *buttonStr[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };
	const char *buttons[] = {
		"(1)'-.&",  "(2)abc", "(3)def",
		"(4)ghi",  "(5)jkl", "(6)mno",
		"(7)pqrs", "(8)tuv", "(9)wxyz",
		"(#)next",    "add",
		"<",
		"Cancel",  "OK",
		"Pre", "(0) ", NULL
	};
	const int colors[] = {
		15, 0, 15, 0, 15, 0,
		15, 0, 15, 0, 15, 0,
		15, 0, 15, 0, 15, 0,
		15, 12, 15, 12,
		15, 0,
		15, 0, 15, 0,
		14, 0, 15, 0, 0, 0
	};
	const char *modes[] = { "(*)Pre", "(*)123", "(*)Abc" };

	// FIXME: Move this to a more appropriate place.
	if (!_predictiveDictText) {
		loadDict();
		if (!_predictiveDictText)
			return false;
	}
	_predictiveDictActLine = NULL;
	uint8 numMatchingWords = 0;

	_predictiveDialogRunning = true;
	_system->setFeatureState(OSystem::kFeatureDisableKeyFiltering, true);

	memset(repeatcount, 0, sizeof(repeatcount));

	// show the predictive dialog.
	// if another window is already in display, save its state into tmpwindow
	memset(&tmpwindow, 0, sizeof(tmpwindow));
	tmpwindow.active = false;
	if (_game.window.active)
		memcpy(&tmpwindow, &(_game.window), sizeof(AgiBlock));
	drawWindow(50, 40, 269, 159);
	_gfx->drawRectangle(62, 54, 249, 66, MSG_BOX_TEXT);
	_gfx->flushBlock(62, 54, 249, 66);

	bx[15] = 73; // Zero/space
	by[15] = 120;
	bx[9] = 110; // next
	by[9] = 120;
	bx[10] = 172; // add
	by[10] = 120;
	bx[14] = 200; // Mode
	by[14] = 120;
	bx[11] = 252; // Backspace
	by[11] = 57;
	bx[12] = 180; // Cancel
	by[12] = 140;
	bx[13] = 240; // OK
	by[13] = 140;

	x = 73;
	y = 75;
	for (int i = 0; i < 9; i++) {
		bx[i] = x;
		by[i] = y;
		x += 60;
		if (i % 3 == 2) {
			y += 15;
			x = 73;
		}
	}

	clearKeyQueue();

	prefix.clear();
	_currentCode.clear();
	_currentWord.clear();
	_wordNumber = 0;

	int mode = kModePre;

	bool needRefresh = true;

	for (;;) {
		if (needRefresh) {
			for (int i = 0; buttons[i]; i++) {
				int color1 = colors[i * 2];
				int color2 = colors[i * 2 + 1];

				if (i == 9 && !((mode != kModeAbc && _predictiveDictActLine && numMatchingWords > 1)
							|| (mode == kModeAbc && _currentWord.size() && _currentWord.lastChar() != ' '))) { // Next
					color2 = 7;
				}

				// needs fixing, or remove it!
				bool _addIsActive = false; // FIXME: word adding is not implemented
				if (i == 10 && !_addIsActive) { // Add
					color2 = 7;
				}
				if (i == 14) {
					_gfx->drawDefaultStyleButton(bx[i], by[i], modes[mode], i == active, 0, color1, color2);
				} else {
					_gfx->drawDefaultStyleButton(bx[i], by[i], buttons[i], i == active, 0, color1, color2);
				}
			}

			Common::strlcpy(temp, prefix.c_str(), sizeof(temp));
			Common::strlcat(temp, _currentWord.c_str(), sizeof(temp));

			for (int i = prefix.size() + _currentCode.size(); i < MAXWORDLEN; i++)
				temp[i] = ' ';
			temp[MAXWORDLEN] = 0;

			printText(temp, 0, 8, 7, MAXWORDLEN, 15, 0);
			_gfx->flushBlock(62, 54, 249, 66);

			if (active >= 0 && !navigationwithkeys) {
				// provide visual feedback only when not navigating with the arrows
				// so that the user can see the active button.
				active = -1;
				needRefresh = true;
			} else
				needRefresh = false;

			_gfx->doUpdate();
		}

		pollTimer();
		key = doPollKeyboard();
		processkey = false;
		switch (key) {
		case KEY_ENTER:
			if (navigationwithkeys) {
				// when the user has utilized arrow key navigation,
				// interpret enter as 'click' on the active button
				active = lastactive;
			} else {
				// else it is a shortcut for 'Ok'
				active = 13;
			}
			processkey = true;
			break;
		case KEY_ESCAPE:
			rc = false;
			goto getout;
		case BUTTON_LEFT:
			navigationwithkeys = false;
			for (int i = 0; buttons[i]; i++) {
				if (_gfx->testButton(bx[i], by[i], buttons[i])) {
					active = i;
					processkey = true;
					break;
				}
			}
			break;
		case KEY_BACKSPACE:
			active = 11;
			processkey = true;
			break;
		case '#':
			active = 9;
			processkey = true;
			break;
		case '*':
			active = 14;
			processkey = true;
			break;
		case 0x09:	// Tab
			navigationwithkeys = true;
			debugC(3, kDebugLevelText, "Focus change");
			lastactive = active = lastactive + 1;
			active %= ARRAYSIZE(buttons) - 1;
			needRefresh = true;
			break;
		case KEY_LEFT:
			navigationwithkeys = true;
			if (lastactive == 0 || lastactive == 3 || lastactive == 6)
				active = lastactive + 2;
			else if (lastactive == 9)
				active = 15;
			else if (lastactive == 11)
				active = 11;
			else if (lastactive == 12)
				active = 13;
			else if (lastactive == 14)
				active = 10;
			else
				active = lastactive - 1;
			lastactive = active;
			needRefresh = true;
			break;
		case KEY_RIGHT:
			navigationwithkeys = true;
			if (lastactive == 2 || lastactive == 5 || lastactive == 8)
				active = lastactive - 2;
			else if (lastactive == 10)
				active = 14;
			else if (lastactive == 11)
				active = 11;
			else if (lastactive == 13)
				active = 12;
			else if (lastactive == 15)
				active = 9;
			else
				active = lastactive + 1;
			lastactive = active;
			needRefresh = true;
			break;
		case KEY_UP:
			navigationwithkeys = true;
			if (lastactive <= 2)
				active = 11;
			else if (lastactive == 9 || lastactive == 10)
				active = lastactive - 2;
			else if (lastactive == 11)
				active = 13;
			else if (lastactive == 14)
				active = 8;
			else if (lastactive == 15)
				active = 6;
			else
				active = lastactive - 3;
			lastactive = active;
			needRefresh = true;
			break;
		case KEY_DOWN:
			navigationwithkeys = true;
			if (lastactive == 6)
				active = 15;
			else if (lastactive == 7 || lastactive == 8)
				active = lastactive + 2;
			else if (lastactive == 11)
				active = 0;
			else if (lastactive == 12 || lastactive == 13)
				active = 11;
			else if (lastactive == 14 || lastactive == 15)
				active = lastactive - 2;
			else
				active = lastactive + 3;
			lastactive = active;
			needRefresh = true;
			break;
		default:
			// handle numeric buttons
			if (key >= '1' && key <= '9') {
				active = key - '1';
				processkey = true;
			} else if (key == '0') {
				active = 15;
				processkey = true;
			}
			break;
		}

		if (processkey) {
			if (active >= 0) {
				needRefresh = true;
				lastactive = active;
				if (active == 15 && mode != kModeNum) { // Space
					// bring MRU word at the top of the list when changing words
					if (mode == kModePre && _predictiveDictActLine && numMatchingWords > 1 && _wordNumber != 0)
						bringWordtoTop(_predictiveDictActLine, _wordNumber);
					strncpy(temp, _currentWord.c_str(), _currentCode.size());
					temp[_currentCode.size()] = 0;
					prefix += temp;
					prefix += " ";
					_currentCode.clear();
					_currentWord.clear();
					numMatchingWords = 0;
					memset(repeatcount, 0, sizeof(repeatcount));
				} else if (active < 9 || active == 11 || active == 15) { // number or backspace
					if (active == 11) { // backspace
						if (_currentCode.size()) {
							repeatcount[_currentCode.size() - 1] = 0;
							_currentCode.deleteLastChar();
						} else {
							if (prefix.size())
								prefix.deleteLastChar();
						}
					} else if (prefix.size() + _currentCode.size() < MAXWORDLEN - 1) { // don't overflow the dialog line
						if (active == 15) { // zero
							_currentCode += buttonStr[9];
						} else {
							_currentCode += buttonStr[active];
						}
					}

					switch (mode) {
					case kModeNum:
						_currentWord = _currentCode;
						break;
					case kModePre:
						if (!matchWord() && _currentCode.size()) {
							_currentCode.deleteLastChar();
							matchWord();
						}
						numMatchingWords = countWordsInString(_predictiveDictActLine);
						break;
					case kModeAbc:
						for (x = 0; x < _currentCode.size(); x++)
							if (_currentCode[x] >= '1')
								temp[x] = buttons[_currentCode[x] - '1'][3 + repeatcount[x]];
						temp[_currentCode.size()] = 0;
						_currentWord = temp;
					}
				} else if (active == 9) { // next
					if (mode == kModePre) {
						if (_predictiveDictActLine && numMatchingWords > 1) {
							_wordNumber = (_wordNumber + 1) % numMatchingWords;
							char tmp[MAXLINELEN];
							strncpy(tmp, _predictiveDictActLine, MAXLINELEN);
							tmp[MAXLINELEN - 1] = 0;
							char *tok = strtok(tmp, " ");
							for (uint8 i = 0; i <= _wordNumber; i++)
								tok = strtok(NULL, " ");
							_currentWord = Common::String(tok, _currentCode.size());
						}
					} else if (mode == kModeAbc){
						x = _currentCode.size();
						if (x) {
							if (_currentCode.lastChar() == '1' || _currentCode.lastChar() == '7' || _currentCode.lastChar() == '9')
								repeatcount[x - 1] = (repeatcount[x - 1] + 1) % 4;
							else
								repeatcount[x - 1] = (repeatcount[x - 1] + 1) % 3;
							if (_currentCode.lastChar() >= '1')
								_currentWord.setChar(buttons[_currentCode[x - 1] - '1'][3 + repeatcount[x - 1]], x-1);
						}
					}
				} else if (active == 10) { // add
					debug(0, "add");
				} else if (active == 13) { // Ok
					// bring MRU word at the top of the list when ok'ed out of the dialog
					if (mode == kModePre && _predictiveDictActLine && numMatchingWords > 1 && _wordNumber != 0)
						bringWordtoTop(_predictiveDictActLine, _wordNumber);
					rc = true;
					goto press;
				} else if (active == 14) { // Mode
					mode++;
					if (mode > kModeAbc)
						mode = kModePre;

					// truncate current input at mode change
					strncpy(temp, _currentWord.c_str(), _currentCode.size());
					temp[_currentCode.size()] = 0;
					prefix += temp;
					_currentCode.clear();
					_currentWord.clear();
					memset(repeatcount, 0, sizeof(repeatcount));
				} else {
					goto press;
				}
			}
		}
	}

 press:
	Common::strlcpy(_predictiveResult, prefix.c_str(), sizeof(_predictiveResult));
	Common::strlcat(_predictiveResult, _currentWord.c_str(), sizeof(_predictiveResult));

 getout:
	// if another window was shown, bring it up again
	if (!tmpwindow.active)
		closeWindow();
	else {
		_gfx->restoreBlock(_game.window.x1, _game.window.y1,
				_game.window.x2, _game.window.y2, _game.window.buffer);

		free(_game.window.buffer);
		memcpy(&(_game.window), &tmpwindow, sizeof(AgiBlock));
		_gfx->doUpdate();
	}

	_system->setFeatureState(OSystem::kFeatureDisableKeyFiltering, false);
	_predictiveDialogRunning = false;

	return rc;
}
コード例 #6
0
ファイル: text.cpp プロジェクト: St0rmcrow/scummvm
/**
 * Display a message box with buttons.
 * This function displays the specified message in a text box
 * centered in the screen and waits until a button is pressed.
 * @param p The text to be displayed
 * @param b NULL-terminated list of button labels
 */
int AgiEngine::selectionBox(const char *m, const char **b) {
	int numButtons = 0;
	int x, y, i, s;
	int key, active = 0;
	int rc = -1;
	int bx[5], by[5];

	_noSaveLoadAllowed = true;

	_sprites->eraseBoth();
	blitTextbox(m, -1, -1, -1);

	x = _game.window.x1 + 5 * CHAR_COLS / 2;
	y = _game.window.y2 - 5 * CHAR_LINES / 2;
	s = _game.window.x2 - _game.window.x1 + 1 - 5 * CHAR_COLS;
	debugC(3, kDebugLevelText, "selectionBox(): s = %d", s);

	// Automatically position buttons
	for (i = 0; b[i]; i++) {
		numButtons++;
		s -= CHAR_COLS * strlen(b[i]);
	}

	if (i > 1) {
		debugC(3, kDebugLevelText, "selectionBox(): s / %d = %d", i - 1, s / (i - 1));
		s /= (i - 1);
	} else {
		x += s / 2;
	}

	for (i = 0; b[i]; i++) {
		bx[i] = x;
		by[i] = y;
		x += CHAR_COLS * strlen(b[i]) + s;
	}

	_sprites->blitBoth();

	clearKeyQueue();

	AllowSyntheticEvents on(this);

	debugC(4, kDebugLevelText, "selectionBox(): waiting...");
	while (!(shouldQuit() || _restartGame)) {
		for (i = 0; b[i]; i++)
			_gfx->drawCurrentStyleButton(bx[i], by[i], b[i], i == active, false, i == 0);

		pollTimer();
		key = doPollKeyboard();
		switch (key) {
		case KEY_ENTER:
			rc = active;
			goto press;
		case KEY_ESCAPE:
			rc = -1;
			goto getout;
		case KEY_RIGHT:
			active++;
			if (active >= numButtons)
				active = 0;
			break;
		case KEY_LEFT:
			active--;
			if (active < 0)
				active = numButtons - 1;
			break;
		case BUTTON_LEFT:
			for (i = 0; b[i]; i++) {
				if (_gfx->testButton(bx[i], by[i], b[i])) {
					rc = active = i;
					goto press;
				}
			}
			break;
		case 0x09:	// Tab
			debugC(3, kDebugLevelText, "selectionBox(): Focus change");
			active++;
			active %= i;
			break;
		}
		_gfx->doUpdate();
	}

press:
	debugC(4, kDebugLevelText, "selectionBox(): Button pressed: %d", rc);

getout:
	closeWindow();
	debugC(2, kDebugLevelText, "selectionBox(): Result = %d", rc);

	_noSaveLoadAllowed = false;

	return rc;
}
コード例 #7
0
ファイル: Lock_Box.c プロジェクト: kanepdx/codakama
int main(void) {
	// initialize
	int rows[] = {ROW1, ROW2, ROW3, ROW4};
	int cols[] = {COL1, COL2, COL3};
	int count;											// counter variable used for loops
	int count_queue;									// Keep track of how many characters are
														// in the queue
	int code_is_correct;								 
	int lock_state = 2;									// initialized lock variable to intermediate status		
	
	// initialize interrupts
	PCICR |= (1 << PCIE0);								// set bit 0 of PCICR
	for(int i = 0; i < NUM_ROWS; i++){
		PCMSK0 |= (1 << rows[i]);						// allow row pins to trigger interrupts
	}
	sei();												// global interrupt enable
	
	// Initializing arrays 
	int enter_code[16] = {'E','N','T','E','R',' ','C','O','D','E',' ',' ',' ',' ',' ',' '};
	int incorrect_code[16] = {'I','N','C','O','R','R','E','C','T',' ','C','O','D','E',' ',' '};
	int unlocked_menu_1[16] = {'#',' ','-',' ','T','O',' ','L','O','C','K',' ',' ',' ',' ',' ',};
	int unlocked_menu_2[16] = {'*',' ','-',' ','S','E','T',' ','N','E','W',' ','C','O','D','E',};
	int new_code_menu[16] = {'S','E','T',' ','N','E','W',' ','C','O','D','E',' ',' ',' ',' ',};
	int cancel_code_change[16] = {' ',' ','-','-','C','A','N','C','E','L','E','D','-','-',' ',' ',};
	int current_code[9];
	
	initRows(rows);										// set keypad rows as inputs
	initColumns(cols);									// set keypad columns as outputs
	initializeLCD();									// set up LCD and initialize in 4 bit mode
	clearKeyQueue();
	count_queue = 0;


	// Ensure we're locked to start with.
	while (lock_state != 1) {
			lock_state = lock(2);
	}

	
	// wait loop
	while(1) {

		// Print greeting
		clearLCD();
		writeLCDline(enter_code,1);
		cursorPosition(2);

		// While box is in locked state
		while (lock_state == 1) {

				// Wait for a key press
				while(key_queue[count_queue] == '\0');
				
				// Now that we have a key press we need to look at what was pressed.
				// Is the first key in the queue a '#'...
				if(key_queue[0] == '#'){
					clearLCD();
					clearKeyQueue();
					count_queue = 0;
				
				// ...or is the first key in the queue a digit?...
				} else if(key_queue[0] >= '0' && key_queue[0] <= '9'){
					// QUESTION: DO WE NEED TO MANUALLY SHIFT THE QUEUE??
					writeLCDcharacter(key_queue[0]);
					++count_queue;
				
				// ...or if first key in the queue isn't a digit or '#' then
				// it must be the '*'
				} else {
					count = 0;
					code_is_correct = 1;
					// Checks the current queue code with the correct code
					while(key_queue[count] != '\0'){
						if(key_queue[count] != current_code[count])
							code_is_correct = 0;				
					}
					if(!code_is_correct){
						clearLCD();
						writeLCDline(incorrect_code,1);
						_delay_ms(5000);
						clearKeyQueue();
						count_queue = 0;
						clearLCD();
					}else{

						// Unlock the box
						lock_state = unlock(lock_state);
					}
				}		
			} // End while (lock_state == 1)

		// While box is in unlocked state
			while (lock_state == 0 ) {

				// Write unlocked menu
				clearLCD();
				writeLCDline(unlocked_menu_1, 1);
				writeLCDline(unlocked_menu_2, 2);

				clearKeyQueue();
				count_queue = 0;

				// Wait for keypress
				while(key_queue[count_queue] == '\0');

				// Now that we have a key press we need to look at what was pressed.
				// Is the first key in the queue a '#'...
				if(key_queue[0] == '#'){
					lock_state = lock(lock_state);
					clearKeyQueue();
					count_queue = 0;

				// ...or is the first key in the queue a '*'?
				} else if(key_queue[0] == '*'){

					clearLCD();
					clearKeyQueue();
					count_queue = 0;
					writeLCDline(new_code_menu, 1);
					cursorPosition(2);

					// Now we start entering the new code. An '*' indicates that we're
					// done entering the code.
					while(key_queue[0] != '*') {
						
						clearKeyQueue();

						// Wait for keypress
						while(key_queue[count_queue] == '\0');

						// Was the latest key pressed between 0 and 9, AND has the user
						// entered less than the max number (8) of digits allowed for the
						// code.
						if(key_queue[0] >= '0' && key_queue[0] <= '9' && count_queue < 9){
							// QUESTION: DO WE NEED TO MANUALLY SHIFT THE QUEUE??
							writeLCDcharacter(key_queue[0]);
							++count_queue;
						
						// If the latest key pressed is '*' then lets write the new
						// code to eeprom
						} else if (key_queue[0] == '*') {
							writeTOeeprom();


						// Otherwise the only key left is '#', so that's what must've been
						// pressed. :)
						} else {
							clearLCD();
							writeLCDline(cancel_code_change,1);
							_delay_ms(5000);
							clearKeyQueue();
							count_queue = 0;
							clearLCD();
						}
				
					}

					
				}		
			} // End while (lock_state == 0 )

	} // End while(1);
} // End main();
コード例 #8
0
ファイル: Lock_Box.c プロジェクト: kanepdx/codakama
 int main(void) {
	 // initialize
	// short int testcode[9] = {'3','2','1','\0','\0','\0','\0','\0','\0'};
	int rows[] = {ROW1, ROW2, ROW3, ROW4};
	int cols[] = {COL1, COL2, COL3};
	
	volatile int count_queue;							// Keep track of how many characters are
														// in the queue
	int code_is_correct;								 
			
	initializeMotorPins();
	initializeKeypadInterrupts(rows);	
	sei();												// global interrupt enable
	
	initRows(rows);										// set keypad rows as inputs
	initColumns(cols);									// set keypad columns as outputs
	initializeLCD();									// set up LCD and initialize in 4 bit mode
	BacklightLCD(1);
	clearKeyQueue();

	//writeLCDcharacter('x');

	
	// Ensure we're locked to start with.
	while (lock_state != 1) {
			lock_state = lock(2);
	}
	initializeTimeout();
	
	
	// wait loop
	while(1) {
		
		
		
		// Print greeting
		clearLCD();
		writeLCDline(enter_code,1);
		cursorPosition(2);
		readFROMeeprom(current_code);
		
		/*
		// TESTING MOTOR
		while(1){
			lock(1);
			_delay_ms(100);
			unlock(1);
			_delay_ms(100);	
		}		
		// END TESTING MOTOR
		*/
		
		// While box is in locked state
		while (lock_state == 1) {
			
			

					
			// Wait for a key press
			while(key_queue[count_queue] == '\0');
			
			// Now that we have a key press we need to look at what was pressed.
			// Is the first key in the queue a '#'...
			if(key_queue[0] == '#'){
				clearLCD();
				writeLCDline(enter_code,1);
				cursorPosition(2);
				clearKeyQueue();
				count_queue = 0;
				//testfun(1);
				
			// ...or is the first key in the queue a digit?...
			} 
			else if((key_queue[0] >= '0') && (key_queue[0] <= '9') && (count_queue < 8)){
				writeLCDcharacter(key_queue[0]);
				count_queue++;	
				
			// ...or if first key in the queue isn't a digit or '#' then
			// it must be the '*'
			} 
			else if(key_queue[0] == '*') {
				count = 0;
				code_is_correct = 1;
				popKey();
				
				clearLCD();
				cursorPosition(1);
				for(int i = 0; i < 10; i++){
					writeLCDcharacter(key_queue[i]);
				}
				cursorPosition(2);
				for(int i = 0; i < 9; i++){
					writeLCDcharacter(current_code[i]);
				}
				_delay_ms(1000);
									
					
				// Checks the current queue code with the correct code
				while(key_queue[count] != '\0'){
					if(key_queue[count] != current_code[count])
						code_is_correct = 0;
					++count;				
				}
				if(!code_is_correct && count > 0){
					clearLCD();
					writeLCDline(incorrect_code,1);
					_delay_ms(5000);
					clearKeyQueue();
					count_queue = 0;
					clearLCD();
					writeLCDline(enter_code,1);
					cursorPosition(2);
				}else if(code_is_correct && count > 0){

					// Unlock the box
					lock_state = unlock(lock_state);
				}
			}					
		} // End while (lock_state == 1)

		// While box is in unlocked state
			while (lock_state == 0 ) {

				// Write unlocked menu
				clearLCD();
				writeLCDline(unlocked_menu_1, 1);
				writeLCDline(unlocked_menu_2, 2);

				clearKeyQueue();
				count_queue = 0;

				// Wait for key press
				while(key_queue[count_queue] == '\0');

				// Now that we have a key press we need to look at what was pressed.
				// Is the first key in the queue a '#'...
				if(key_queue[0] == '#'){
					lock_state = lock(lock_state);
					clearKeyQueue();
					count_queue = 0;
					writeLCDline(enter_code,1);
					cursorPosition(2);

				// ...or is the first key in the queue a '*'?
				} else if(key_queue[0] == '*'){
					
					clearLCD();
					clearKeyQueue();
					count_queue = 0;
					writeLCDline(new_code_menu, 1);
					cursorPosition(2);

					// Now we start entering the new code. An '*' indicates that we're
					// done entering the code.
					while(key_queue[0] != '*') {
						
						// Wait for key press
						while(key_queue[count_queue] == '\0');

						// Was the latest key pressed between 0 and 9, AND has the user
						// entered less than the max number (8) of digits allowed for the
						// code.
						if(key_queue[0] >= '0' && key_queue[0] <= '9' && count_queue < 9){
							// QUESTION: DO WE NEED TO MANUALLY SHIFT THE QUEUE??
							writeLCDcharacter(key_queue[0]);
							++count_queue;
						
						// If the latest key pressed is '*' then lets write the new
						// code to eeprom
						} else if (key_queue[0] == '*') {
							popKey();
							writeTOeeprom(key_queue);
							break;

						// Otherwise the only key left is '#', so that's what must've been
						// pressed. :)
						} else if(key_queue[0] == '#') {
							clearLCD();
							writeLCDline(cancel_code_change,1);
							_delay_ms(5000);
							clearKeyQueue();
							count_queue = 0;
							clearLCD();
							break;
						}
				
					}

					
				}		
			} // End while (lock_state == 0 )

	} // End while(1);
} // End main();