Exemple #1
0
        public void Open(Applet applet, DeviceType type)
        {
            if (Opened)
            {
                throw new Exception("Already opened.");
            }
            if (!applet.Connected)
            {
                throw new Exception("Applet must be connected to LCDMon.");
            }
            if (type != DeviceType.Monochrome && type != DeviceType.Qvga)
            {
                throw new InvalidEnumArgumentException();
            }
            if ((type == DeviceType.Monochrome && applet.CapabilitiesSupported != AppletCapabilities.Monochrome) ||
                (type == DeviceType.Qvga && applet.CapabilitiesSupported != AppletCapabilities.Qvga))
            {
                throw new Exception("The applet does not support the device type \"" + type.ToString() + "\".");
            }
            if (type != DeviceType.Monochrome && type != DeviceType.Qvga)
            {
                throw new InvalidEnumArgumentException();
            }
            Type = type;
            if (type == DeviceType.Monochrome)
            {
                _bitmapFormat = LgLcd.BitmapFormat.Monochrome;
                BitmapWidth   = (int)LgLcd.BwBmp.Width;
                BitmapHeight  = (int)LgLcd.BwBmp.Height;
                BitmapBpp     = (int)LgLcd.BwBmp.Bpp;
            }
            else if (type == DeviceType.Qvga)
            {
                _bitmapFormat = LgLcd.BitmapFormat.QVGAx32;
                BitmapWidth   = (int)LgLcd.QvgaBmp.Width;
                BitmapHeight  = (int)LgLcd.QvgaBmp.Height;
                BitmapBpp     = (int)LgLcd.QvgaBmp.Bpp;
                _pixelFormat  = PixelFormat.Format32bppArgb;
            }
            var ctx = new LgLcd.OpenByTypeContext {
                Connection           = applet.Handle,
                DeviceType           = (LgLcd.DeviceType)Type,
                OnSoftbuttonsChanged = new LgLcd.SoftbuttonsChangedContext {
                    Context = IntPtr.Zero,
                    OnSoftbuttonsChanged = _softButtonsDelegate,
                }
            };

            LgLcd.ReturnValue error = LgLcd.OpenByType(ref ctx);
            if (error != LgLcd.ReturnValue.ErrorSuccess)
            {
                if (error == LgLcd.ReturnValue.ErrorAlreadyExists)
                {
                    throw new Exception("The specified device has already been opened in the given applet.");
                }
                throw new Win32Exception((int)error);
            }
            _handle = ctx.Device;
        }
Exemple #2
0
 public void Open(Applet applet, DeviceType type)
 {
     if (Opened) {
         throw new Exception("Already opened.");
     }
     if (!applet.Connected) {
         throw new Exception("Applet must be connected to LCDMon.");
     }
     if (type != DeviceType.Monochrome && type != DeviceType.Qvga) {
         throw new InvalidEnumArgumentException();
     }
     if ((type == DeviceType.Monochrome && applet.CapabilitiesSupported != AppletCapabilities.Monochrome)
         || (type == DeviceType.Qvga && applet.CapabilitiesSupported != AppletCapabilities.Qvga)) {
         throw new Exception("The applet does not support the device type \"" + type.ToString() + "\".");
     }
     if (type != DeviceType.Monochrome && type != DeviceType.Qvga) {
         throw new InvalidEnumArgumentException();
     }
     Type = type;
     if (type == DeviceType.Monochrome) {
         _bitmapFormat = LgLcd.BitmapFormat.Monochrome;
         BitmapWidth = (int)LgLcd.BwBmp.Width;
         BitmapHeight = (int)LgLcd.BwBmp.Height;
         BitmapBpp = (int)LgLcd.BwBmp.Bpp;
     }
     else if (type == DeviceType.Qvga) {
         _bitmapFormat = LgLcd.BitmapFormat.QVGAx32;
         BitmapWidth = (int)LgLcd.QvgaBmp.Width;
         BitmapHeight = (int)LgLcd.QvgaBmp.Height;
         BitmapBpp = (int)LgLcd.QvgaBmp.Bpp;
         _pixelFormat = PixelFormat.Format32bppArgb;
     }
     var ctx = new LgLcd.OpenByTypeContext {
         Connection = applet.Handle,
         DeviceType = (LgLcd.DeviceType)Type,
         OnSoftbuttonsChanged = new LgLcd.SoftbuttonsChangedContext {
             Context = IntPtr.Zero,
             OnSoftbuttonsChanged = _softButtonsDelegate,
         }
     };
     LgLcd.ReturnValue error = LgLcd.OpenByType(ref ctx);
     if (error != LgLcd.ReturnValue.ErrorSuccess) {
         if (error == LgLcd.ReturnValue.ErrorAlreadyExists) {
             throw new Exception("The specified device has already been opened in the given applet.");
         }
         throw new Win32Exception((int)error);
     }
     _handle = ctx.Device;
 }