Data Sheet
4D SYSTEMS 4DPi-32-II Primary Display – Raspberry Pi Compatible
© 2018 4D SYSTEMS Page 16 of 18 www.4dsystems.com.au
4DPi
-32
-II Primary Display
– Raspberry
Pi
Example for Shutdown and Reset buttons, for C
// test program to Shutdown or Restart Pi using buttons on 4D Systems 4DPi displays
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#define LCD4DPI_GET_KEYS _IOR('K', 1, unsigned char *)
int get_keys(int fd, unsigned char *keys)
{
if (ioctl(fd, LCD4DPI_GET_KEYS, keys) == -1)
{
perror("_apps ioctl get");
return 1;
}
*keys &= 0b11111;
return 0;
}
int main(int argc, char *argv[])
{
char *file_name = "/dev/fb1";
int fd;
unsigned char key_status;
fd = open(file_name, O_RDWR);
if (fd == -1)
{
perror("_apps open");
return 2;
}
key_status = 0b11111;
while(key_status & 0b00001) // press key 1 to exit
{
if(get_keys(fd, &key_status) != 0)
break;
// printf("key_status: %x\n", key_status);
if(!(key_status & 0b10000))
{
system("sudo shutdown -h now");
break;
}
if(!(key_status & 0b01000))
{
system("sudo reboot");
break;
}
sleep(0.1);
}
close(fd);
return 0;
}