4 #include "mwindowgui.h"
5 #include "androidcontrol.h"
6 #include "preferences.h"
9 int AndroidControl::open(unsigned short port)
11 sockfd = socket(PF_INET,SOCK_DGRAM,0);
12 if( sockfd < 0 ) { perror("socket:"); return -1; }
18 if( setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &lgr, sizeof(lgr)) < 0 ) {
23 struct sockaddr_in sadr;
24 memset(&sadr,0,sizeof(sadr));
25 sadr.sin_family = AF_INET;
26 sadr.sin_port = htons(port);
27 sadr.sin_addr.s_addr = 0;
29 if( bind(sockfd,(struct sockaddr *)&sadr,sizeof(sadr)) < 0 ) {
37 void AndroidControl::close()
45 AndroidControl::AndroidControl(MWindowGUI *mwindow_gui)
48 this->mwindow_gui = mwindow_gui;
52 bool AndroidControl::is_msg(const char *cp)
54 if( msg_len != (int)strlen(cp) ) return false;
55 if( strncmp(cp, msg, msg_len) ) return false;
59 void AndroidControl::press(int key)
61 // printf("press 0x%04x\n",key);
62 if( mwindow_gui->key_listener(key) ) return;
63 mwindow_gui->remote_control->remote_key(key);
66 void AndroidControl::run()
68 unsigned short port = mwindow_gui->mwindow->preferences->android_port;
69 done = open(port) >= 0 ? 0 : 1;
75 int ret = recvfrom(sockfd, buf, sizeof(buf), 0, &sadr, &sadr_len);
77 perror("AndroidControl::run: recvfrom");
82 msg = buf; msg_len = ret;
83 // cinelerra android remote magic number
84 if( msg[0] != 'C' || msg[1] != 'A' || msg[2] != 'R' ) continue;
86 if( msg[3] != 1 ) continue;
87 msg += 4; msg_len -= 4;
89 const char *pin = mwindow_gui->mwindow->preferences->android_pin;
90 int len = sizeof(mwindow_gui->mwindow->preferences->android_pin);
91 while( len > 0 && msg_len > 0 && *pin != 0 && *msg != 0 ) {
92 if( *pin != *msg ) break;
96 if( !len || !msg_len || *pin != *msg ) continue;
98 if( msg_len <= 0 ) continue;
99 if( is_msg("stop") ) press(KPSTOP);
100 else if( is_msg("play") ) press(KPPLAY);
101 else if( is_msg("rplay") ) press(KPREV);
102 else if( is_msg("pause") ) press(' ');
103 else if( is_msg("fast_lt") ) press(KPBACK);
104 else if( is_msg("media_up") ) press(UP);
105 else if( is_msg("fast_rt") ) press(KPFWRD);
106 else if( is_msg("menu") ) press(KPMENU);
107 else if( is_msg("media_lt") ) press(LEFT);
108 else if( is_msg("media_rt") ) press(RIGHT);
109 else if( is_msg("slow_lt") ) press(KPRECD);
110 else if( is_msg("media_dn") ) press(DOWN);
111 else if( is_msg("slow_rt") ) press(KPAUSE);
112 else if( is_msg("key 0") ) press('0');
113 else if( is_msg("key 1") ) press('1');
114 else if( is_msg("key 2") ) press('2');
115 else if( is_msg("key 3") ) press('3');
116 else if( is_msg("key 4") ) press('4');
117 else if( is_msg("key 5") ) press('5');
118 else if( is_msg("key 6") ) press('6');
119 else if( is_msg("key 7") ) press('7');
120 else if( is_msg("key 8") ) press('8');
121 else if( is_msg("key 9") ) press('9');
122 else if( is_msg("key A") ) press('a');
123 else if( is_msg("key B") ) press('b');
124 else if( is_msg("key C") ) press('c');
125 else if( is_msg("key D") ) press('d');
126 else if( is_msg("key E") ) press('e');
127 else if( is_msg("key F") ) press('f');
128 else if( is_msg("suspend") ) {
129 system("sync; sleep 1; acpitool -s");
131 else if( is_msg("power") ) {
132 system("sync; sleep 1; poweroff");
135 printf("AndroidControl::run: unkn msg: %s\n", msg);
141 AndroidControl::~AndroidControl()
143 if( Thread::running() ) {