/// <summary>
        /// This method restore to initial state (main menu)
        /// </summary>
        private void RestoreInitialState()
        {
            _menu              = 0;
            _menuState         = MENU_STATE.initial;
            _servoState        = SERVO_STATE.close;
            _secretState       = SECRET_CODE.up1;
            _scanCardState     = SCAN_CARD_STATE.waitRFID;
            _addCardState      = ADD_CARD_STATE.waitRFID;
            _displayCardsState = DISPLAY_CARDS_STATE.listIsEmpty;
            _deleteCardState   = DELETE_CARD_STATE.listIsEmpty;

            // Refresh the LCD text fields
            LCDTextFields.Content         = Card.DEFAULT_NAME;
            LCDTextFields.CursorPosition  = 0;
            LCDTextFields.ShouldBeRefresh = true;

            DeleteCurrentBadgescan();
            LCD.GetInstance().Clear();
            DisplayMainMenu(_menu);
        }
        /// <summary>
        /// When the menu to unlock the box with the secret code is selected
        /// </summary>
        private void UnlockSecretCode()
        {
            int nbrClue   = 0;  // This is for the number of * that we're going to wrote on the LCD
            int positionX = 10; // Position X ont the LCD

            LCD.GetInstance().DisplayText(GT.Color.Black, "Progression :", positionX, LCD.GetInstance().LcdHeight / 2);

            LCD.GetInstance().DisplayText(GT.Color.Gray, "Pour quitter, appuyer sur le joystick", positionX, LCD.GetInstance().LcdHeight - 20);
            bool oldJoystickread = ((_joystickX.Read() > JOYSTICK_UP_RIGHT && _joystickX.Read() < JOYSTICK_DOWN_LEFT) && // True if the joystick is int the center
                                    (_joystickY.Read() > JOYSTICK_UP_RIGHT && _joystickY.Read() < JOYSTICK_DOWN_LEFT));

            Thread.Sleep(200);                                                                                        // Wait 0.2 seconds to allow time to move the joystick
            bool joystickRead = ((_joystickX.Read() < JOYSTICK_UP_RIGHT || _joystickX.Read() > JOYSTICK_DOWN_LEFT) || // True if the joystick isn't at the center
                                 (_joystickY.Read() < JOYSTICK_UP_RIGHT || _joystickY.Read() > JOYSTICK_DOWN_LEFT));

            if ((oldJoystickread && joystickRead) || _secretState == SECRET_CODE.success || _secretState == SECRET_CODE.error) // If the joystick was in the center and then move
            {                                                                                                                  // or if the code is success || error
                LCD.GetInstance().Clear();
                switch (_secretState)
                {
                case SECRET_CODE.up1:
                    if (_joystickX.Read() <= JOYSTICK_UP_RIGHT)     // If joystick is up
                    {
                        _secretState = SECRET_CODE.up2;
                        nbrClue      = 1;
                        Debug.Print("1");
                    }
                    else
                    {
                        _secretState = SECRET_CODE.error;
                    }
                    break;

                case SECRET_CODE.up2:
                    if (_joystickX.Read() <= JOYSTICK_UP_RIGHT)     // If joystick is up
                    {
                        _secretState = SECRET_CODE.down1;
                        nbrClue      = 2;
                        Debug.Print("2");
                    }
                    else
                    {
                        _secretState = SECRET_CODE.error;
                    }
                    break;

                case SECRET_CODE.down1:
                    if (_joystickX.Read() >= JOYSTICK_DOWN_LEFT)     // If joystick is down
                    {
                        _secretState = SECRET_CODE.down2;
                        nbrClue      = 3;
                        Debug.Print("3");
                    }
                    else
                    {
                        _secretState = SECRET_CODE.error;
                    }
                    break;

                case SECRET_CODE.down2:
                    if (_joystickX.Read() >= JOYSTICK_DOWN_LEFT)     // If joystick is down
                    {
                        _secretState = SECRET_CODE.left1;
                        nbrClue      = 4;
                        Debug.Print("4");
                    }
                    else
                    {
                        _secretState = SECRET_CODE.error;
                    }
                    break;

                case SECRET_CODE.left1:
                    if (_joystickY.Read() >= JOYSTICK_DOWN_LEFT)     // If joystick is left
                    {
                        _secretState = SECRET_CODE.right1;
                        nbrClue      = 5;
                        Debug.Print("5");
                    }
                    else
                    {
                        _secretState = SECRET_CODE.error;
                    }
                    break;

                case SECRET_CODE.right1:
                    if (_joystickY.Read() <= JOYSTICK_UP_RIGHT)     // If joystick is right
                    {
                        _secretState = SECRET_CODE.left2;
                        nbrClue      = 6;
                        Debug.Print("6");
                    }
                    else
                    {
                        _secretState = SECRET_CODE.error;
                        nbrClue      = 1;
                    }
                    break;

                case SECRET_CODE.left2:
                    if (_joystickY.Read() >= JOYSTICK_DOWN_LEFT)     // If joystick is left
                    {
                        _secretState = SECRET_CODE.right2;
                        nbrClue      = 7;
                        Debug.Print("7");
                    }
                    else
                    {
                        _secretState = SECRET_CODE.error;
                    }
                    break;

                case SECRET_CODE.right2:
                    if (_joystickY.Read() <= JOYSTICK_UP_RIGHT)     // If joystick is right
                    {
                        _secretState = SECRET_CODE.success;
                        Debug.Print("8");
                    }
                    else
                    {
                        _secretState = SECRET_CODE.error;
                    }
                    break;

                case SECRET_CODE.success:
                    RestoreInitialState();
                    _servoState = SERVO_STATE.open;
                    break;

                case SECRET_CODE.error:
                    _secretState = SECRET_CODE.up1;
                    LCD.GetInstance().DisplayText(GT.Color.Red, "Code faux, veuillez recommencer");
                    Thread.Sleep(1000);
                    break;

                default:
                    _secretState = SECRET_CODE.up1;
                    break;
                }

                for (int i = 0; i < nbrClue; i++)
                {
                    LCD.GetInstance().DisplayText(GT.Color.Black, "*", 100 + positionX, LCD.GetInstance().LcdHeight / 2 + 5);
                    positionX += 10;
                }
            }

            if (!_joystickButton.Read()) // If the joystick button is press
            {
                RestoreInitialState();
            }
        }
        /// <summary>
        /// When no menu is selected
        /// </summary>
        private void InitialState()
        {
            switch (_scanCardState)
            {
            case SCAN_CARD_STATE.waitRFID:
                if (RFIDReader.GetInstance().IsBadgeScan)
                {
                    _scanCardState = SCAN_CARD_STATE.RFIDDetected;
                }
                break;

            case SCAN_CARD_STATE.RFIDDetected:
                if (_servoState == SERVO_STATE.close)     // If the servo is lock
                {
                    bool isValid = ListOfCards.GetInstance().FindCardInlist(RFIDReader.GetInstance().CurrentUid);
                    if (isValid)
                    {
                        _scanCardState = SCAN_CARD_STATE.RFIDValid;
                    }
                    else
                    {
                        _scanCardState = SCAN_CARD_STATE.RFIDInvalid;
                    }
                }
                else
                {
                    _scanCardState = SCAN_CARD_STATE.RFIDInvalid;
                }
                break;

            case SCAN_CARD_STATE.RFIDValid:
                _servoState    = SERVO_STATE.open;
                _scanCardState = SCAN_CARD_STATE.waitRFID;
                DeleteCurrentBadgescan();
                break;

            case SCAN_CARD_STATE.RFIDInvalid:
                _servoState    = SERVO_STATE.close;
                _scanCardState = SCAN_CARD_STATE.waitRFID;
                DeleteCurrentBadgescan();
                break;

            default:
                _scanCardState = SCAN_CARD_STATE.waitRFID;
                break;
            }

            switch (_servoState)
            {
            case SERVO_STATE.open:
                ServoMotor.GetInstance().Unlock();
                _secuTimer.Start();
                break;

            case SERVO_STATE.close:
                ServoMotor.GetInstance().Lock();
                _secuTimer.Stop();
                break;

            default:
                _servoState = SERVO_STATE.close;
                break;
            }

            if (_joystickX.Read() > JOYSTICK_DOWN_LEFT) // If the joystick is down
            {
                _menu++;
                if (_menu > 4)
                {
                    _menu = 0;
                }
                DisplayMainMenu(_menu);                     // It is not removed from the test to prevent the lcd flashing
                Thread.Sleep(100);                          // Wait 0.1 second to prevent the menu from scrolling too fast
            }
            else if (_joystickX.Read() < JOYSTICK_UP_RIGHT) // The joystick is up
            {
                _menu--;
                if (_menu < 0)
                {
                    _menu = 4;
                }
                DisplayMainMenu(_menu); // It is not removed from the test to prevent the lcd flashing
                Thread.Sleep(100);      // Wait 0.1 second to prevent the menu from scrolling too fast
            }
        }
 private void _secuTimer_Tick(GT.Timer pbTimer)
 {
     _servoState = SERVO_STATE.close;
 }