Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <sys/ioctl.h>
- #include <linux/types.h>
- #include <linux/i2c-dev.h>
- struct i2c_msg {
- __u16 addr;
- __u16 flags;
- __u16 len;
- __u8 *buf;
- };
- int i, fd;
- void send(const char* data, int len){
- struct i2c_rdwr_ioctl_data msg_rdwr;
- struct i2c_msg i2cmsg;
- msg_rdwr.msgs = &i2cmsg;
- msg_rdwr.nmsgs = 1;
- i2cmsg.addr = 0x37;
- i2cmsg.flags = 0;
- i2cmsg.len = len;
- i2cmsg.buf = (__u8*)data;
- if ((i = ioctl(fd, I2C_RDWR, &msg_rdwr)) < 0 )
- {
- perror("ioctl()");
- fprintf(stderr,"ioctl returned %d\n",i);
- exit(-1);
- }
- }
- void init(){
- fd = open("/dev/i2c-6",O_RDWR);
- if(fd < 0){
- printf("Failed to open bus 6\n");
- exit(-1);
- }
- send("\x00",1);
- }
- void print_usage(char* name){
- printf("USAGE: %s h1 - switches to HDMI1 input\n", name);
- printf(" %s h2 - switches to HDMI2 input\n", name);
- }
- int main(int argc, char** argv){
- if(argc < 2){
- print_usage(argv[0]);
- return -2;
- }else{
- char c = argv[1][0];
- if(c != 'h1' && c != 'h2'){
- print_usage(argv[0]);
- return -2;
- }else{
- init();
- if(c == 'h1'){
- printf("Switching to HDMI1\n");
- send("\x51\x84\x03\x60\x00\x11\xc9\x00", 7);
- }else if(c == 'h2'){
- printf("Switching to HDMI2\n");
- send("\x51\x84\x03\x60\x00\x10\xc8\x00", 7);
- }
- close(fd);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement