Tiny Core Linux
Tiny Core Base => Raspberry Pi => Topic started by: AlexM on September 18, 2023, 04:37:25 AM
-
Hello!
I need to disable the blinking cursor in the text console from my C program to work directly with the framebuffer.
I'm using this code:
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/kd.h>
#include <unistd.h>
#include <stdio.h>
//...
char *tty_n;
int console_fd;
if ((tty_n = ttyname(0)) == NULL){
fprintf(stderr,"ttyname() error.\n");
exit(1);
}
console_fd = open(tty_n, O_RDWR);
if (!console_fd) {
fprintf(stderr,"Could not open console.\n");
exit(1);
}
if (ioctl( console_fd, KDSETMODE, KD_GRAPHICS))
{
fprintf(stderr,"Could not set console to KD_GRAPHICS mode.\n");
exit(1);
}
close(console_fd);
//...
It works on Tiny Core with TC.tcz installed, but does not work on minimal piCore. The error is returned by ioctl( console_fd, KDSETMODE, KD_GRAPHICS).
Installing TC.tcz increases the loading time, which I would like to avoid and I do not need graphical desctop. But I don’t have enough knowledge of which component is missing for the code to work and whether it can be installed separately from TC.tcz.
Perhaps there is some other way to solve this problem?
OS version piCore 13, board - Raspberry Pi Zero W.
-
Hi AlexM
Welcome to the forum.
Try this:
system("echo -e \e[?25l");
-
Hi AlexM
Sorry, I forgot to include stdlib.h.
Hide.c:
#include <stdio.h>
#include <stdlib.h>
int main ()
{
system("echo -e \e[?25l");
return(0);
}
Show.c:
#include <stdio.h>
#include <stdlib.h>
int main ()
{
system("echo -e \e[?25h");
return(0);
}
Compile:
gcc Hide.c -o Hide
gcc Show.c -o Show
./Hide will hide the cursor. This works in both a virtual terminal
as provided by TC.tcz as well as the console which you want
to be running in.
./Show will of course make the cursor visible again.
-
If you have a framebuffer available, it could be as simple as a permission error. Check the errno code after that ioctl.
-
Try this:
system("echo -e \e[?25l");
Thanks, it work!
If you have a framebuffer available, it could be as simple as a permission error. Check the errno code after that ioctl.
ioctl return error "Bad file descriptor"
-
Hi AlexM
This looks wrong:
console_fd = open(tty_n, O_RDWR);
if (!console_fd) {
fprintf(stderr,"Could not open console.\n");
exit(1);
}
According to the man page:
RETURN VALUE
On success, open(), openat(), and creat() return the new file
descriptor (a nonnegative integer). On error, -1 is returned and
errno is set to indicate the error.
Found here:
https://man7.org/linux/man-pages/man2/open.2.html#RETURN_VALUE
Your error test should probably look something like this:
if (console_fd < 0)
{
printf("Could not open console.\n%s\n", strerror(errno));
exit(1);
}
By the way, ttyname and ioctl both set errno when they fail if you want
a little more detail in your error messages:
https://man7.org/linux/man-pages/man3/ttyname.3.html#RETURN_VALUE
https://man7.org/linux/man-pages/man2/ioctl.2.html#RETURN_VALUE
-
This looks wrong:
console_fd = open(tty_n, O_RDWR);
if (!console_fd) {
fprintf(stderr,"Could not open console.\n");
exit(1);
}
Yes, you are absolutely right. Problem is in permissions and error code checking.