Пример #1
0
 public Lglcd()
 {
     if (m_Initialized)
         throw new InitializationException("Library already initialized");
     MethodsWrapper.Init();
     m_Initialized = true;
 }
Пример #2
0
        /// <summary>
        /// Return the buttons state of the device, it uses a sort of small cache to reduce memory consumption.
        /// </summary>
        /// <returns></returns>
        public ButtonsState GetState()
        {
            EnsureAttached();

            Interop.Buttons buttons = Interop.Buttons.None;
            uint            result  = MethodsWrapper.ReadSoftButtons(openByTypeContext.device, ref buttons);

            switch (result)
            {
            case (uint)Errors.ERROR_SUCCESS:
                break;

            case (uint)Errors.ERROR_SERVICE_NOT_ACTIVE:
                throw new DeviceException(result, "Lglcd.Initialize() has not been called yet");

            case (uint)Errors.ERROR_INVALID_PARAMETER:
                throw new DeviceException(result, "Device handle is invalid");

            case (uint)Errors.ERROR_DEVICE_NOT_CONNECTED:
                // Not connected means it has been usb-removed, that's why I don't use "detached"
                throw new DeviceException(result, "Device not connected");

            default:
                throw new DeviceException(result, "Problems getting device buttons state");
            }

            if ((uint)buttons != m_LastButtonsState)
            {
                m_LastButtonsState = (uint)buttons;
                m_ButtonsState     = new ButtonsState(m_LastButtonsState);
            }

            return(m_ButtonsState);
        }
Пример #3
0
        public void Attach()
        {
            EnsureNotDisposed();
            EnsureNotAttached();

            openByTypeContext.connection = Applet.connectContextEx.connection;
            openByTypeContext.deviceType = (DeviceTypes)Enum.ToObject(typeof(DeviceTypes), DeviceType);

            uint result = MethodsWrapper.OpenByType(ref openByTypeContext);

            switch (result)
            {
            case (uint)Errors.ERROR_SUCCESS:
                break;

            case (uint)Errors.ERROR_SERVICE_NOT_ACTIVE:
                throw new DeviceException(result, "Lglcd.Initialize() has not been called yet");

            case (uint)Errors.ERROR_INVALID_PARAMETER:
                throw new DeviceException(result, "Invalid applet connection or device type");

            case (uint)Errors.ERROR_ALREADY_EXISTS:
                throw new DeviceException(result, "Device already activated for used applet");

            default:
                throw new DeviceException(result, "Problems attaching the device");
            }

            Attached = true;
        }
Пример #4
0
        protected virtual void Dispose(bool disposing)
        {
            if (Disposed) return;

            if (disposing)
            {
                // Managed resources
            }

            // Unmanaged resources
            if (Initialized)
            {
                MethodsWrapper.DeInit();
                m_Initialized = false;
            }

            Disposed = true;
        }
Пример #5
0
        public void Connect()
        {
            EnsureNotDisposed();
            EnsureNotConnected();

            if (Configurable)
            {
                connectContextEx.onConfigure.configCallback = new lgLcdOnConfigureCB(ConfigureHandler);
            }
            connectContextEx.onNotify.notificationCallback = new lgLcdOnNotificationCB(NotificationHandler);
            connectContextEx.dwAppletCapabilitiesSupported = (AppletCapabilities)Enum.ToObject(typeof(AppletCapabilities), SupportedDevices);

            uint result = MethodsWrapper.ConnectEx(ref connectContextEx);

            switch (result)
            {
            case (uint)Errors.ERROR_SUCCESS:
                break;

            case (uint)Errors.ERROR_SERVICE_NOT_ACTIVE:
                throw new AppletException(result, "Lglcd.Initialize() has not been called yet");

            case (uint)Errors.ERROR_INVALID_PARAMETER:
                throw new AppletException(result, "Title not set");

            case (uint)Errors.ERROR_FILE_NOT_FOUND:
                throw new AppletException(result, "Lglcd not running on the system");

            case (uint)Errors.ERROR_ALREADY_EXISTS:
                throw new AppletException(result, "Client already connected");

            case (uint)Errors.RPC_X_WRONG_PIPE_VERSION:
                throw new AppletException(result, "Problems detecting protocol");

            default:
                throw new AppletException(result, "Problems estabilishing connection");
            }

            Connected = true;
        }
Пример #6
0
        public void Disconnect()
        {
            EnsureConnected();

            uint result = MethodsWrapper.Disconnect(connectContextEx.connection);

            switch (result)
            {
            case (uint)Errors.ERROR_SUCCESS:
                break;

            case (uint)Errors.ERROR_SERVICE_NOT_ACTIVE:
                throw new AppletException(result, "Lglcd.Initialize() has not been called yet");

            case (uint)Errors.ERROR_INVALID_PARAMETER:
                throw new AppletException(result, "Invalid connection");

            default:
                throw new AppletException(result, "Problems disconnecting");
            }

            FireDisconnect();
        }
Пример #7
0
        public void Detach()
        {
            EnsureAttached();

            uint result = MethodsWrapper.Close(openByTypeContext.device);

            switch (result)
            {
            case (uint)Errors.ERROR_SUCCESS:
                break;

            case (uint)Errors.ERROR_SERVICE_NOT_ACTIVE:
                throw new DeviceException(result, "Lglcd.Initialize() has not been called yet");

            case (uint)Errors.ERROR_INVALID_PARAMETER:
                throw new DeviceException(result, "Device handle is invalid");

            default:
                throw new DeviceException(result, "Problems detaching the device");
            }

            FireDetach();
        }
Пример #8
0
        public bool Update(UpdatePriorities updatePriority = UpdatePriorities.Normal, UpdateStyles updateStyle = UpdateStyles.Async, bool avoidNotConnectedExceptions = true)
        {
            EnsureAttached();
            EnsureImageUpdaterNotNull();

            uint result = MethodsWrapper.UpdateBitmap(openByTypeContext.device, ImageUpdater.UnmanagedBitmapHeaderPointer, ((uint)updateStyle) | ((uint)updatePriority));

            switch (result)
            {
            case (uint)Errors.ERROR_SUCCESS:
                break;

            case (uint)Errors.ERROR_SERVICE_NOT_ACTIVE:
                throw new DeviceException(result, "Lglcd.Initialize() has not been called yet");

            case (uint)Errors.ERROR_INVALID_PARAMETER:
                throw new DeviceException(result, "Device handle is invalid or image is invalid");

            case (uint)Errors.ERROR_DEVICE_NOT_CONNECTED:
                // We try to avoid throwing this exception type because it happens really often
                if (avoidNotConnectedExceptions)
                {
                    return(false);
                }
                // Not connected means it has been usb-removed, that's why I don't use "detached"
                throw new DeviceException(result, "Device not connected");

            case (uint)Errors.ERROR_ACCESS_DENIED:
                throw new DeviceException(result, "Synchronous operation was not displayed on the LCD within the frame interval (30 ms). Error happens only with UpdateStyles.SyncComplete");

            default:
                throw new DeviceException(result, "Problems updating device image");
            }

            return(true);
        }