Ejemplo n.º 1
0
        public void ProgramStarted()
        {
            DebugOnly.Print("Program started!");

            // Initialize screen
            WindowManager.Init();

            // Set scan window
            scanWindow.SetText("Please scan your NFC card now...");
            scanWindow.SetNegativeButton("Cancel", delegate { scanWindow.Dismiss(); });

            // Windows and window manager
            pinWindow.Id  = WindowPinId;
            scanWindow.Id = WindowScanId;

            // Button
            button.ButtonPressed  += DoorOpen;
            button.ButtonReleased += DoorClosed;

            doorOpen = button.Pressed;
            if (doorOpen)
            {
                pinWindow.SetText("Door open");
            }
            else
            {
                pinWindow.SetText("Door closed");
            }

            unlockedTimer       = new GT.Timer(unlockPeriod);
            unlockedTimer.Tick += UnlockTimeout;

            pinWindow.Show();

            // Event Setup
            adafruit_PN532.TagFound      += TagFound;
            adafruit_PN532.Error         += NfcError;
            pinWindow.PinFound           += PinFound;
            DataHelper.DataSourceChanged += DataSourceChanged;
            WindowManager.WindowChanged  += WindowChanged;

            // Start NFC
            adafruit_PN532.StartScan(NfcScanPeriod, NfcScanTimeout);

            //Init
            CacheManager.Init(sdCard);
            SettingsManager.Init();
            DataHelper.Init(ethernetJ11D);

            adafruit_PN532.Init();
        }
Ejemplo n.º 2
0
        /*
         * PIN FOUND EVENT:
         * This event occurs when the user inserts a pin code. It checks if the pin is valid and unlock the door if so.
         * If the pin has no related CardId it prompts the user to add it.
         */
        private void PinFound(string pin)
        {
            string masterPin = SettingsManager.Get(SettingsManager.MasterPin);

            // Check master pin
            if (String.Compare(masterPin, pin) == 0)
            {
                maintenanceWindow.Show();
                return;
            }

            // Check authorization
            var authorized = DataHelper.CheckPin(pin);
            var nullCardId = DataHelper.PinHasNullCardId(pin);

            // Log the event
            string logText;
            Log    log;

            if (authorized)
            {
                // Access granted
                UnlockDoor();
                logText = "Pin \"" + pin + "\" inserted. Authorized access.";
                log     = new Log(Log.TypeAccess, pin, logText);
            }
            else
            {
                // Access denied
                logText = "Pin \"" + pin + "\" inserted. Access denied!";
                log     = new Log(Log.TypeInfo, logText);
            }

            DebugOnly.Print(logText);

            // Add log to loglist
            DataHelper.AddLog(log);

            if (nullCardId && authorized)
            {
                // Null CardID detected, prompt the user to set one
                var nullCardIdAlert = new AlertWindow(WindowAlertPeriod);
                nullCardIdAlert.SetText(
                    "It happears that this user has no related NFC card.\nDo you want to scan it now?");
                nullCardIdAlert.SetPositiveButton("Yes", delegate
                {
                    // User wants to add a new NFC card
                    pendingPin = pin;
                    scanWindow.Show();
                });
                nullCardIdAlert.SetNegativeButton("No", delegate
                {
                    // User doesn't want to add a new NFC card
                    nullCardIdAlert.Dismiss();
                });
                nullCardIdAlert.Show();
            }
            else
            {
                // Everything is fine
                accessWindow.Show(authorized);
            }
        }