void UpdateBitmap(int priority) { if (!IsOpen) { return; } var bitdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb); lgLcdBitmap160x43x1 bmp = lgLcdBitmap160x43x1.New; unsafe { for (int y = 0; y < bitdata.Height; y++) { byte *row = (byte *)bitdata.Scan0.ToPointer() + (y * bitdata.Stride); for (int x = 0; x < bitdata.Width; x++) { byte *p = &row[x * 4]; byte val = *p; val |= *(p + 1); val |= *(p + 2); byte pixel = val < (byte)0x80 ? (byte)0x00 : (byte)0xff; bmp.pixels[(y * bitdata.Width) + x] = pixel; } } lgLcdUpdateBitmapBW(openContext.device, ref bmp, priority); } bitmap.UnlockBits(bitdata); }
DWORD lgLcdUpdateBitmapBW(int device, ref lgLcdBitmap160x43x1 bitmap, DWORD priority);
/// <summary> /// The lgLcdUpdateBitmap() function updates the bitmap of the device. /// </summary> /// <remarks> /// The bitmap header parameter should point to an actual bitmap. The current revision of the /// library defines a structure called lgLcdBitmap160x43x1 which holds as a first member a /// bitmap header. You would typically instantiate once of these structures, set the hdr.Format /// to LGLCD_BMP_FORMAT_160x43x1, then fill in the bitmap to be displayed in the pixels[] member. /// Finally, you call lgLcdUpdateBitmap(… &yourBitmap.hdr …) to issue the bitmap update. Future /// versions of the SDK could have additional bitmap types declared, but all of them will have /// the same header at the beginning. /// /// At any given time there may be multiple applications attempting to display a bitmap on the LCD. /// The priority parameter is a hint for LCDMon’s display scheduling algorithm. In a scenario /// where there is contention for screen display time, LCDMon needs to determine which application’s /// bitmap to display. In order to aid this scheduling, it can (but depending on user settings /// might not) take into account the hints that an application gives through the priority parameter. /// It is highly advisable that your application gives the appropriate priority for any given screen /// update to improve the user experience. A well-behaved LCD-enabled application should not use /// high priorities except for alerts. /// /// The difference between asynchronous and synchronous updates is as follows: an asynchronous /// update will place the bitmap to be displayed into LCDMon and return immediately, before the /// bitmap is actually sent out to the device. For synchronous updates, the call to /// lgLcdUpdateBitmap() will only return after the bitmap has been sent out to the device, /// which takes 30 milliseconds or more. In case the application currently does not show on /// the LCD because another application is displayed, the synchronous update returns after a /// time that is similar to an update when the application is visible. If the macro /// LGLCD_SYNC_COMPLETE_WITHIN_FRAME() is used, an error is returned to the calling /// application when this condition arises. /// /// The benefit of using the synchronous update is that your application will run “locked” with /// the LCD updates. It will be suspended for the entire duration of writing to the screen, /// and only get to run when the display is ready to accept a new screen. A “mini-game” on the /// LCD would profit from this behavior in order to get the highest possible frame rates while /// minimizing CPU usage. /// /// The asynchronous updates are beneficial to applications that don’t care about the exact /// sequence and timing of screen updates and have many other things to do. They just deposit /// a bitmap to be sent to the device every once in a while and don’t worry about it actually /// going out and being in sync with this event. /// </remarks> /// <param name="device">Specifies the device handle for which to update the display.</param> /// <param name="bitmap">Specifies a pointer to a bitmap header structure. See comments for details.</param> /// <param name="priority"> /// Specifies a priority hint for this screen update, as well as whether the update should /// take place synchronously or asynchronously. See comments for details. /// The following priorities are defined: /// /// LGLCD_PRIORITY_IDLE_NO_SHOW /// Lowest priority, disable displaying. Use this priority when you don’t have /// anything to show. /// LGLCD_PRIORITY_BACKGROUND /// Priority used for low priority items. /// LGLCD_PRIORITY_NORMAL /// Normal priority, to be used by most applications most of the time. /// LGLCD_PRIORITY_ALERT /// Highest priority. To be used only for critical screens, such as “your CPU /// temperature is too high” /// /// In addition, there are three macros that can be used to indicate whether the screen /// should be updated synchronously (LGLCD_SYNC_UPDATE()) or asynchronously (LGLCD_ASYNC_UPDATE()). /// When using synchronous update the LCD library can notify the calling application of whether /// the bitmap was displayed or not on the LCD, using the macro (LGLCD_SYNC_COMPLETE_WITHIN_FRAME()). /// Use these macros to indicate the behavior of the library. /// </param> /// <returns> /// If the function succeeds, the return value is ERROR_SUCCESS. /// If the function fails, the return value can be one of the following: /// /// ERROR_SERVICE_NOT_ACTIVE /// lgLcdInit() has not been called yet. /// ERROR_INVALID_PARAMETER /// The specified device handle, the bitmap header /// pointer or the type of bitmap is invalid. /// ERROR_DEVICE_NOT_CONNECTED /// The specified device has been disconnected. /// ERROR_ACCESS_DENIED /// Synchronous operation was not displayed on the LCD within the frame interval /// (30 ms). This error code is only returned when the priority field of the /// lgLCDUpdateBitmap uses the macro LGLCD_SYNC_COMPLETE_WITHIN_FRAME(). /// Xxx /// Other (system) error with appropriate error code. /// </returns> [DllImport("LgLcd.dll")] private static extern int lgLcdUpdateBitmap(int device, ref lgLcdBitmap160x43x1 bitmap, uint priority);