ANSI Console on

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
Post Reply
jafrey
Posts: 33
Joined: Tue Nov 05, 2013 12:15 am

ANSI Console on

Post by jafrey »

Apologies if this is too basic for 'code samples' but it's been a long time since I used C and still in the learning process with Chibi. My development board is a STM32F4Discovery. Hopefully some other beginners can find this useful.

My end goal is to create a ANSI compatible console so that rather than a just a basic 'run command' interface it's more of a 'GUI' (or at least building blocks to do so.

First Milestone: Print the number of the serial port and an incrementing number on ALL serial. I took my Usb<->Serial device and poked around all of the called out pins and, much to my surprise, it worked!

Code: Select all

        
        // Activates the UART driver 1, PA9(TX) and PA10(RX) are routed to USART1.
        // Activates the UART driver 2, PA2(TX) and PA3(RX) are routed to USART2.
        // Activates the UART driver 3, PB10(TX) and PB11(RX) are routed to USART3.
        // Activates the UART driver 4, PC10(TX) and PC11(RX) are routed to UART4.
        // Activates the UART driver 5, PC12(TX) and PD2(RX) are routed to UART5.
        // Activates the UART driver 6, PC6(TX) and PC7(RX) are routed to USART6.


Code: Select all

        
while (TRUE) {
                i++;
                if (SDU1.config->usbp->state == USB_ACTIVE) {
                        chprintf((BaseSequentialStream *)&SDU1, "Serial USB: %d\r\n", i);
                }
                chprintf((BaseSequentialStream *)&SD1, "Serial 1: %d\r\n", i);
                chprintf((BaseSequentialStream *)&SD2, "Serial 2: %d\r\n", i);
                chprintf((BaseSequentialStream *)&SD3, "Serial 3: %d\r\n", i);
                chprintf((BaseSequentialStream *)&SD4, "Serial 4: %d\r\n", i);
                chprintf((BaseSequentialStream *)&SD5, "Serial 5: %d\r\n", i);
                chprintf((BaseSequentialStream *)&SD6, "Serial 6: %d\r\n", i);
                chThdSleepMilliseconds(1000);
        }


Milestone 2: Print out different ANSI escape sequences to change the color, background and font. http://ascii-table.com/ansi-escape-sequences.php

Picture of how it appears in 2 different consoles with default settings. Eclipse terminal is on the left (white background), PuTTY is on the right (black background)
ImageImage
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: ANSI Console on

Post by Giovanni »

Hi,

You mean creating something like curses in UNIX? http://en.wikipedia.org/wiki/Curses_%28 ... library%29

Giovanni
jafrey
Posts: 33
Joined: Tue Nov 05, 2013 12:15 am

Re: ANSI Console on

Post by jafrey »

Giovanni wrote:You mean creating something like curses in UNIX? http://en.wikipedia.org/wiki/Curses_%28 ... library%29


Similar. I plan on using chibiOS to create an engine controller. I would like to make a terminal interface similar to this for some of my tuning work: http://www.youtube.com/watch?feature=pl ... XMqQKf_F3U
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: ANSI Console on

Post by mobyfab »

Really nice, good job! :)
Post Reply