grininmonkey
Posts: 115
Joined: Mon Jul 30, 2018 3:44 pm

Disable/Enable tty cursor blinking

Tue Oct 23, 2018 1:08 pm

I am not sure which approach to take, yet.... but so far I am finding multiple ways to go about disabling the console cursor blinking. I am working on a full screen frame buffer "graphics" project as a new UI for my Pi thermostat display and need to turn off the blinking while the app is running and turn it back on when closing.

From what I gather, you can either figure out the right escape sequences to echo to console, or ioctl(tty, KDSETMODE, KD_GRAPHICS) or include curses and use curs_set...

I am leaning a wee bit towards using curses.... but have some hesitation due to including another dependency just for this blink switching....

Has anyone else messed with this and has any suggestions?

grininmonkey
Posts: 115
Joined: Mon Jul 30, 2018 3:44 pm

Re: Disable/Enable tty cursor blinking

Mon Oct 29, 2018 6:25 pm

I tried adding ncurses, however the issue there is.... curses blanks the screen which overwrites what I am drawing to the framebuffer... so that's a bust...

So now I am trying to find out how, curses does what it does to prevent user input from echoing and not showing the blinking cursor... which is what I need to do to preserve my activity to the framebuffer...

So far I am not having much luck with ioctl(tty, KDSETMODE, KD_GRAPHICS) either...

grininmonkey
Posts: 115
Joined: Mon Jul 30, 2018 3:44 pm

Re: Disable/Enable tty cursor blinking

Mon Oct 29, 2018 7:03 pm

Ahhhh.... So yet another lesson learned.... I should have been working against tty0 and not actual tty[n]... so this seems to produce the results I am looking for and in case someone down the road learning like me.. asks the same question...



Code: Select all


#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/kd.h>

- - - - - -

static void
set_tty(const int mode)
{
    int console_fd;
    console_fd = open("/dev/tty0", O_RDWR);
    if (!console_fd) {
        fprintf(stderr,"Could not open console.\n");
        exit(1);
    }

    if (mode)
	{
		if (ioctl( console_fd, KDSETMODE, KD_GRAPHICS))
		{
			fprintf(stderr,"Could not set console to KD_GRAPHICS mode.\n");
			exit(1);
		}
	} else {
		if (ioctl( console_fd, KDSETMODE, KD_TEXT))
		{
			fprintf(stderr,"Could not set console to KD_TEXT mode.\n");
			exit(1);
		}
	}

    close(console_fd);
}

quick system("clear"); after calling set_tty(0).... and all good ;-)

Return to “C/C++”