Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OLEDCClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the OLEDc Click board is inserted on MikroBus.Net</param>
        /// <example>Example usage:
        /// <code language = "C#">
        ///	var _oled = new OLEDCClick(Hardware.SocketFour);
        /// </code>
        /// </example>
        public OLEDCClick(Hardware.Socket socket)
        {
            _socket = socket;
            SpiConnectionSettings settings = new SpiConnectionSettings
            {
                ChipSelectType        = SpiChipSelectType.Gpio,
                ChipSelectLine        = GpioController.GetDefault().OpenPin(socket.Cs),
                ChipSelectActiveState = false,
                Mode           = SpiMode.Mode3,
                ClockFrequency = 40 * 1000 * 1000
            };

            _oled = SpiController.FromName(socket.SpiBus).GetDevice(settings);

            _resetPin = GpioController.GetDefault().OpenPin(socket.Rst);
            _resetPin.SetDriveMode(GpioPinDriveMode.Output);
            _resetPin.Write(GpioPinValue.High);

            _dataCommandPin = GpioController.GetDefault().OpenPin(socket.PwmPin);
            _dataCommandPin.SetDriveMode(GpioPinDriveMode.Output);
            _dataCommandPin.Write(GpioPinValue.High);

            _readWritePin = GpioController.GetDefault().OpenPin(socket.AnPin);
            _readWritePin.SetDriveMode(GpioPinDriveMode.Output);
            _readWritePin.Write(GpioPinValue.High);

            Canvas = new MikroBitmap(_canvasWidth, _canvasHeight);

            InitilizeOLED();
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OLEDCClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the OLEDc Click board is inserted on MikroBus.Net</param>
        /// <exception cref="PinInUseException">If some pins are already used by another driver, then the exception is thrown.</exception>
        /// <example>Example usage:
        /// <code language = "C#">
        ///	var _oled = new OLEDCClick(Hardware.SocketFour);
        /// </code>
        /// <code language = "VB">
        ///	Dim _oled as OLEDCClick = New OLEDCClick(Hardware.SocketFour)
        /// </code>
        /// </example>
        public OLEDCClick(Hardware.Socket socket)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Miso, socket.Cs, socket.Sck, socket.Rst, socket.An, socket.Pwm);

                _spiConfig = new SPI.Configuration(socket.Cs, false, 0, 0, true, true, 40000, socket.SpiModule);

                if (Hardware.SPIBus == null)
                {
                    Hardware.SPIBus = new SPI(_spiConfig);
                }

                _resetPin = new OutputPort(socket.Rst, true);
                _dcPin    = new OutputPort(socket.Pwm, true);
                _rwPin    = new OutputPort(socket.An, true);

                _canvas = new MikroBitmap(_canvasWidth, _canvasHeight);

                InitilizeOLED();
            }
            catch (PinInUseException ex)
            {
                throw new PinInUseException(ex.Message);
            }
        }
Beispiel #3
0
 /// <summary>
 /// Flushes the supplied Bitmap object to OLED-C Click Display
 /// </summary>
 /// <param name="bitmap">The MikroBitmap object to flush to the OLED-C display.</param>
 /// <returns>True if the operation was successful or otherwise false. for instance, attempting to flush at a destination that is outside the dimensions of the OLED-C display. </returns>
 /// <example>Example usage:
 /// <code language = "C#">
 ///	MikroBitmap newCanvas = new MikroBitmap(96, 96);
 ///	newCanvas.DrawRectangle(KnownColors.Red, KnownColors.Red, new Rect(0, 0, 96, 16));
 ///	_oled.Flush(newCanvas);
 /// </code>
 /// <code language = "VB">
 ///	Dim newCanvas As MikroBitmap = New MikroBitmap(96, 96)
 ///	newCanvas.DrawRectangle(KnownColors.Red, KnownColors.Red, New Rect(0, 0, 96, 16))
 ///	_oled.Flush(newCanvas)
 /// </code>
 /// </example>
 public void Flush(MikroBitmap bitmap)
 {
     lock (bitmap)
     {
         EnableDDRAMAccess();
         SendData(bitmap.Pixels);
     }
 }
Beispiel #4
0
        public static void Main()
        {
            Debug.GC(true);

            _oled = new OLEDCClick(Hardware.SocketFour)
            {
                FrameRate = OLEDCClick.FrameRates.OCS_140_4Hz
            };

            var img1 = new MikroBitmap(Resources.GetBytes(Resources.BinaryResources.bfly1));
            var img2 = new MikroBitmap(Resources.GetBytes(Resources.BinaryResources.bfly2));
            var img3 = new MikroBitmap(Resources.GetBytes(Resources.BinaryResources.bfly3));
            var img4 = new MikroBitmap(Resources.GetBytes(Resources.BinaryResources.bfly4));
            var img5 = new MikroBitmap(Resources.GetBytes(Resources.BinaryResources.bfly5));
            var img6 = new MikroBitmap(Resources.GetBytes(Resources.BinaryResources.bfly6));

            while (true)
            {
                _oled.Canvas.DrawImage(img1, (_oled.CanvasWidth - img1.Width) / 2, (_oled.CanvasHeight - img1.Height) / 2);
                _oled.Flush();
                //Debug.GC(true);
                Thread.Sleep(100);
                _oled.Canvas.DrawImage(img2, (_oled.CanvasWidth - img2.Width) / 2, (_oled.CanvasHeight - img2.Height) / 2);
                _oled.Flush();
                //Debug.GC(true);
                Thread.Sleep(100);
                _oled.Canvas.DrawImage(img3, (_oled.CanvasWidth - img3.Width) / 2, (_oled.CanvasHeight - img3.Height) / 2);
                _oled.Flush();
                //Debug.GC(true);
                Thread.Sleep(100);
                _oled.Canvas.DrawImage(img4, (_oled.CanvasWidth - img4.Width) / 2, (_oled.CanvasHeight - img4.Height) / 2);
                _oled.Flush();
                //Debug.GC(true);
                Thread.Sleep(100);
                _oled.Canvas.DrawImage(img5, (_oled.CanvasWidth - img5.Width) / 2, (_oled.CanvasHeight - img5.Height) / 2);
                _oled.Flush();
                //Debug.GC(true);
                Thread.Sleep(100);
                _oled.Canvas.DrawImage(img6, (_oled.CanvasWidth - img6.Width) / 2, (_oled.CanvasHeight - img6.Height) / 2);
                _oled.Flush();
                Thread.Sleep(100);
                Debug.GC(true);
            }
        }