Exemple #1
0
 public void QueueMessage(LCDMessage msg)
 {
     Log.WriteLine("UARTDevice Qmsg");
     _msgq.Add(msg);
 }
Exemple #2
0
        public async Task InitAsync()
        {
            // reset display
            // configure display
            await SendCmdAsync(LCD_CMD_SET_SAVE_SIZE);
            await WriteByteAsync(LCD_COLS);
            await WriteByteAsync(LCD_ROWS);
            await SendCmdAsync(LCD_CMD_DISPLAY_ON);
            await WriteByteAsync(0); // unclear why display on needs an extra 0 byte. but, it does -- see firmware source.
            await AsAsync(_write.StoreAsync());

            Log.WriteLine("display on cmd sent, pausing");
            Thread.Sleep(TimeSpan.FromMilliseconds(300));
            await SendCmdAsync(LCD_CMD_DISPLAY_OFF); // display off doesn't need the mystery 0

            Log.WriteLine("display off cmd sent, pausing");
            Thread.Sleep(TimeSpan.FromMilliseconds(1000));
            await SendCmdAsync(LCD_CMD_DISPLAY_ON);
            await WriteByteAsync(0);            // unclear why display on needs an extra 0 byte. but, it does -- see firmware source.
            await AsAsync(_write.StoreAsync()); //flush before pause

            Thread.Sleep(TimeSpan.FromMilliseconds(300));
            Log.WriteLine("display on again pausing");
            await SendCmdAsync(LCD_CMD_BLOCK_CURSOR_OFF);
            await SendCmdAsync(LCD_CMD_UNDERLINE_CURSOR_ON);
            await Clear();

            Log.WriteLine("cleared screen with underline cursor");
            await SetContrast(220); // 220 is what the device reference code python test uses
            await SetBrightness(0xff);
            await SetBackgroundAsync(Colors.Red);

            _msgTask = Task.Factory.StartNew(async() =>
            {
                try
                {
                    while (!_msgCancel.Token.IsCancellationRequested)
                    {
                        LCDMessage msg = _msgq.Take();
                        Log.WriteLineVerbose("msgq processing {0}, {1} clear, msg {2}", msg.bgcolor, msg.clear ? "do" : "do net", msg.msg);
                        await SetBackgroundAsync(msg.bgcolor);
                        if (msg.clear)
                        {
                            await Clear();
                        }
                        if ((msg.msg != null) && (msg.msg.Length > 0))
                        {
                            await WriteStringAsync(msg.msg);
                        }
                    }
                } catch (Exception e)
                {
                    Log.WriteLineError("UART msgq consumer exception {0}", e.ToString());
                }
            },
                                             _msgCancel.Token,
                                             TaskCreationOptions.LongRunning,
                                             TaskScheduler.Default
                                             );

            Log.WriteLine("init complete");

            return;
        }