Example #1
0
 static Applet()
 {
     LgLcd.Init();
     // Queue DeInit to be called on application exit
     AppDomain.CurrentDomain.ProcessExit += delegate {
         LgLcd.DeInit();
     };
 }
Example #2
0
        public void Disconnect()
        {
            if (!Connected)
            {
                throw new Exception("Not connected.");
            }
            var error = LgLcd.Disconnect(Handle);

            if (error != LgLcd.ReturnValue.ErrorSuccess)
            {
                throw new Win32Exception((int)error);
            }
            // Reset the handle
            _handle = LgLcd.InvalidConnection;
        }
Example #3
0
        public void Connect(string friendlyName, bool autostartable, AppletCapabilities appletCaps)
        {
            if (Connected)
            {
                throw new Exception("Already connected.");
            }
            FriendlyName          = friendlyName;
            Autostartable         = autostartable;
            CapabilitiesSupported = appletCaps;
            var ctx = new LgLcd.ConnectContextEx {
                AppFriendlyName             = friendlyName,
                AppletCapabilitiesSupported = (LgLcd.AppletCapabilities)appletCaps,
                IsAutostartable             = autostartable,
                IsPersistent = true,                 // deprecated and ignored as of 3.00
                OnConfigure  = new LgLcd.ConfigureContext {
                    Context     = IntPtr.Zero,
                    OnConfigure = _configurationDelegate,
                },
                OnNotify = new LgLcd.NotificationContext {
                    Context        = IntPtr.Zero,
                    OnNotification = _notificationDelegate,
                },
                Reserved1 = 0,
            };
            var error = LgLcd.ConnectEx(ref ctx);

            if (error != LgLcd.ReturnValue.ErrorSuccess)
            {
                if (error == LgLcd.ReturnValue.ErrorInvalidParameter)
                {
                    throw new ArgumentException("FriendlyName must not be null.");
                }
                if (error == LgLcd.ReturnValue.ErrorFileNotFound)
                {
                    throw new Exception("LCDMon is not running on the system.");
                }
                if (error == LgLcd.ReturnValue.ErrorAlreadyExists)
                {
                    throw new Exception("The same client is already connected.");
                }
                if (error == LgLcd.ReturnValue.RcpXWrongPipeVersion)
                {
                    throw new Exception("LCDMon does not understand the protocol.");
                }
                throw new Win32Exception((int)error);
            }
            _handle = ctx.Connection;
        }
Example #4
0
        public void SetAsLCDForegroundApp(bool yesNo)
        {
            if (!Opened)
            {
                throw new Exception("Not opened.");
            }
            var error = LgLcd.SetAsLCDForegroundApp(Handle, yesNo);

            if (error != LgLcd.ReturnValue.ErrorSuccess)
            {
                if (error == LgLcd.ReturnValue.ErrorLockFailed)
                {
                    throw new Exception("The operation could not be completed.");
                }
                throw new Win32Exception((int)error);
            }
        }
Example #5
0
        public void UpdateBitmap(
            Bitmap bitmap,
            Priority priority,
            bool syncUpdate = false,
            bool syncCompleteWithinFrame = false)
        {
            if (!Opened)
            {
                throw new Exception("Not opened.");
            }
            if (bitmap.Width != BitmapWidth || bitmap.Height != BitmapHeight)
            {
                throw new ArgumentException("The bitmaps dimensions do not conform.");
            }
            var lgBitmap = new LgLcd.Bitmap {
                Format = _bitmapFormat,
                Pixels = new byte[BitmapWidth * BitmapHeight * BitmapBpp],
            };
            var bitmapData = bitmap.LockBits(
                new Rectangle(0, 0, BitmapWidth, BitmapHeight),
                ImageLockMode.ReadOnly,
                _pixelFormat);

            Marshal.Copy(bitmapData.Scan0, lgBitmap.Pixels, 0, lgBitmap.Pixels.Length);
            bitmap.UnlockBits(bitmapData);
            var error = LgLcd.UpdateBitmap(
                Handle,
                lgBitmap,
                (uint)priority
                | (syncUpdate ? LgLcd.SyncUpdate : 0)
                | (syncCompleteWithinFrame ? LgLcd.SyncCompleteWithinFrame : 0));

            if (error != LgLcd.ReturnValue.ErrorSuccess)
            {
                if (error == LgLcd.ReturnValue.ErrorDeviceNotConnected)
                {
                    throw new InvalidOperationException("The specified device has been disconnected.");
                }
                if (error == LgLcd.ReturnValue.ErrorAccessDenied)
                {
                    throw new InvalidAsynchronousStateException("Synchronous operation was not displayed on the LCD within the frame interval (30 ms).");
                }
                throw new Win32Exception((int)error);
            }
        }
Example #6
0
        public SoftButtonFlags ReadSoftButtons()
        {
            if (!Opened)
            {
                throw new Exception("Not opened.");
            }
            LgLcd.SoftButtonFlags buttonFlags;
            var error = LgLcd.ReadSoftButtons(Handle, out buttonFlags);

            if (error != LgLcd.ReturnValue.ErrorSuccess)
            {
                if (error == LgLcd.ReturnValue.ErrorDeviceNotConnected)
                {
                    throw new Exception("The specified device has been disconnected.");
                }
                throw new Win32Exception((int)error);
            }
            return((SoftButtonFlags)buttonFlags);
        }
Example #7
0
        private int NotifyHandler(
			int connection,
			IntPtr context,
			LgLcd.NotificationCode notificationCode,
			int notifyParam1,
			int notifyParam2,
			int notifyParam3,
			int notifyParam4)
        {
            switch (notificationCode) {
                case LgLcd.NotificationCode.DeviceArrival:
                    OnDeviceArrival((DeviceType)notifyParam1);
                    break;
                case LgLcd.NotificationCode.DeviceRemoval:
                    // All devices of the given type got disabled
                    OnDeviceRemoval((DeviceType)notifyParam1);
                    break;
                case LgLcd.NotificationCode.AppletEnabled:
                    OnAppletEnabled();
                    break;
                case LgLcd.NotificationCode.AppletDisabled:
                    OnAppletDisabled();
                    break;
                case LgLcd.NotificationCode.CloseConnection:
                    OnCloseConnection();
                    break;
            }
            return 0;
        }
Example #8
0
 private int OnSoftButtons(int device, LgLcd.SoftButtonFlags buttons, IntPtr context)
 {
     EventHandler e = null;
     switch (buttons)
     {
         case LgLcd.SoftButtonFlags.Left:
             e = Left;
             break;
         case LgLcd.SoftButtonFlags.Right:
             e = Right;
             break;
         case LgLcd.SoftButtonFlags.Ok:
             e = Ok;
             break;
         case LgLcd.SoftButtonFlags.Cancel:
             e = Cancel;
             break;
         case LgLcd.SoftButtonFlags.Up:
             e = Up;
             break;
         case LgLcd.SoftButtonFlags.Down:
             e = Down;
             break;
         case LgLcd.SoftButtonFlags.Menu:
             e = Menu;
             break;
     }
     if (e != null)
     {
         e(this, EventArgs.Empty);
     }
     return 0;
 }