예제 #1
0
        internal static byte[] GetBuffer(Ssd1306 display)
        {
            if (BufferFieldInfo == null)
            {
                var properties = typeof(Ssd1306).GetFields(System.Reflection.BindingFlags.Instance
                                                           | System.Reflection.BindingFlags.GetProperty
                                                           | System.Reflection.BindingFlags.SetProperty
                                                           | System.Reflection.BindingFlags.NonPublic);

                for (int index = 0; index < properties.Length; index++)
                {
                    if (properties[index].Name.Contains("buffer"))
                    {
                        BufferFieldInfo = properties[index];
                    }
                }
            }

            if (BufferFieldInfo == null)
            {
                return(null);
            }

            return(BufferFieldInfo.GetValue(display) as byte[]);
        }
예제 #2
0
        internal static void SendCommandsInternal(this Ssd1306 display, byte[] commands)
        {
            if (SendCommandsMethodInfo == null)
            {
                SendCommandsMethodInfo = typeof(Ssd1306).GetMethod("SendCommands", System.Reflection.BindingFlags.Instance
                                                                   | System.Reflection.BindingFlags.InvokeMethod
                                                                   | System.Reflection.BindingFlags.NonPublic);
            }

            if (SendCommandsMethodInfo == null)
            {
                throw new EntryPointNotFoundException("method SendCommands not found on " + nameof(Ssd1306));
            }

            SendCommandsMethodInfo.Invoke(display, new object[] { commands });
        }
예제 #3
0
        public static void DrawBitmap(this Ssd1306 display, byte startColumn, byte startPage, VerticalByteBitmap bitmap, BitmapOp bitmapOp)
        {
            var buffer = GetBuffer(display);

            var width = Math.Min(display.Width, startColumn + bitmap.Width);

            var pageHeight = display.Height / 8;

            var pageWidth = display.Width;

            for (int yPage = 0; yPage < bitmap.Rectangle.YByteHeight; yPage++)
            {
                var singlePage = bitmap.Buffer[yPage];

                if (yPage + startPage < pageHeight)
                {
                    for (int xIndex = 0; xIndex < bitmap.Width; xIndex++)
                    {
                        var offset = xIndex + startColumn + ((yPage + startPage) * pageWidth);

                        if (offset < buffer.Length)
                        {
                            switch (bitmapOp)
                            {
                            case BitmapOp.And:
                                buffer[offset] &= singlePage[xIndex];
                                break;

                            case BitmapOp.Or:
                                buffer[offset] |= singlePage[xIndex];
                                break;

                            case BitmapOp.Replace:
                                buffer[offset] = singlePage[xIndex];
                                break;

                            case BitmapOp.Xor:
                                buffer[offset] ^= singlePage[xIndex];
                                break;
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
 public static byte GetPageCount(this Ssd1306 display)
 {
     return(( byte )(display.Height / 8));
 }
예제 #5
0
 public static void SendUGdash2832HSWEG02Startup(this Ssd1306 display)
 {
     display.SendCommandsInternal(UGdash2832HSWEG02SetupSequence);
 }