Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// When the menu to delete a card is selected
        /// </summary>
        private void DeleteCard()
        {
            switch (_deleteCardState)
            {
            case DELETE_CARD_STATE.listIsEmpty:
                LCD.GetInstance().Clear();
                if (ListOfCards.GetInstance().IsEmpty())
                {
                    LCD.GetInstance().DisplayText(GT.Color.Red, "/!\\ Aucun badge n'est enregistre /!\\", 10, LCD.GetInstance().LcdHeight / 2);
                    Thread.Sleep(2000);
                    RestoreInitialState();
                }
                else
                {
                    _deleteCardState = DELETE_CARD_STATE.selectCard;
                }
                break;

            case DELETE_CARD_STATE.selectCard:
                int positionY = 10;     // The Y position on the LCD
                int i         = 0;
                foreach (Card card in ListOfCards.GetInstance().CardsList)
                {
                    if (LCDTextFields.CursorPosition == i)     // If the cursorposition is at this char
                    {
                        LCD.GetInstance().DisplayText(GT.Color.Blue, card.Name, 10, positionY);
                    }
                    else
                    {
                        LCD.GetInstance().DisplayText(GT.Color.Black, card.Name, 10, positionY);
                    }
                    positionY += 15;     // Increment the Y position
                    i++;
                }
                LCD.GetInstance().DisplayText(GT.Color.Gray, "Pour selectionner le badge, appuyer sur le joystick", 10, LCD.GetInstance().LcdHeight - 30);

                if (_joystickX.Read() > JOYSTICK_DOWN_LEFT)                                           // If joystick is down
                {
                    LCDTextFields.CursorPosition++;                                                   // Move the cursor to the next name
                    if (LCDTextFields.CursorPosition > ListOfCards.GetInstance().CardsList.Count - 1) // If the cursor get out of the range of the list of cards array
                    {
                        LCDTextFields.CursorPosition = 0;                                             // Move to the first position of the list of cards array
                    }
                    Thread.Sleep(100);                                                                // Wait 0.1 second to prevent the cursor from moving too fast
                }
                else if (_joystickX.Read() < JOYSTICK_UP_RIGHT)                                       // If joystick is up
                {
                    LCDTextFields.CursorPosition--;                                                   // Move the cursor to the previous name
                    if (LCDTextFields.CursorPosition < 0)                                             // If the cursor get out of the range of the list array
                    {
                        LCDTextFields.CursorPosition = ListOfCards.GetInstance().CardsList.Count - 1; // Move to the last position of the list of cards array
                    }
                    Thread.Sleep(100);                                                                // Wait 0.1 second to prevent the cursor from moving too fast
                }
                if (!_joystickButton.Read())                                                          // If joystick button is press
                {
                    _deleteCardState = DELETE_CARD_STATE.save;
                }
                break;

            case DELETE_CARD_STATE.save:
                try
                {
                    ListOfCards.GetInstance().DeleteCardFromList(LCDTextFields.CursorPosition);
                    SDCard.GetInstance().SaveCards(ListOfCards.GetInstance().CardsList);
                    _deleteCardState = DELETE_CARD_STATE.success;
                }
                catch (Exception e)
                {
                    _deleteCardState = DELETE_CARD_STATE.errorMSG;
                }
                break;

            case DELETE_CARD_STATE.errorMSG:
                DisplayError();
                Thread.Sleep(2000);
                RestoreInitialState();
                break;

            case DELETE_CARD_STATE.success:
                DisplaySave();
                LCD.GetInstance().DisplayText(GT.Color.Green, "Le badge a bien ete supprime", 10, LCD.GetInstance().LcdHeight / 2);
                Thread.Sleep(2000);
                RestoreInitialState();
                break;

            default:
                _deleteCardState = DELETE_CARD_STATE.listIsEmpty;
                break;
            }
        }