1 //WindowMaker DVB frontend monitor dock applet version 1. MaxCompress
15 #include <X11/Xutil.h>
16 #include <X11/extensions/shape.h>
20 #include <sys/ioctl.h>
22 #include <linux/dvb/frontend.h>
23 #define FRONTENDDEVICE "/dev/dvb/adapter%d/frontend%d"
25 static Atom delete_win
;
31 unsigned int d
[7][4]={{22, 2,19,9},{2, 2,19,9},{2,12,19,9},
32 {2,22,19,9},{22,12,19,9},{2,32,19,9},{32,32,42,9}};
36 unsigned long getcolor(char *color_name
)
38 /* getcolor("darkblue") veya getcolor("rgb:52/55/52") olabilir. */
41 if (!XParseColor(XD
, DefaultColormap(XD
, DefaultScreen(XD
)), color_name
, &color
))
42 fprintf(stderr
, "can't parse color %s\n", color_name
), exit(1);
44 if (!XAllocColor(XD
, DefaultColormap(XD
, DefaultScreen(XD
)), &color
)) {
45 fprintf(stderr
, "can't allocate color %s. Using black\n", color_name
);
46 return BlackPixel(XD
, DefaultScreen(XD
)); }
54 uint16_t snr
, signal
, level
;
55 //uint32_t ber, uncorrected_blocks;
56 struct dvb_frontend_parameters dfp
;
57 XWindowAttributes xwattr
;
62 ioctl(fefd
, FE_READ_STATUS
, &status
);
63 ioctl(fefd
, FE_READ_SIGNAL_STRENGTH
, &signal
);
64 ioctl(fefd
, FE_READ_SNR
, &snr
);
65 //ioctl(fefd, FE_READ_BER, &ber);
66 //ioctl(fefd, FE_READ_UNCORRECTED_BLOCKS, &uncorrected_blocks);
67 ioctl(fefd
, FE_GET_FRONTEND
, &dfp
);
68 if (dfp
.frequency
+10600000 >= 11700000) freq
=dfp
.frequency
+10600000;
69 else freq
=dfp
.frequency
+ 9750000;
70 XGetWindowAttributes(XD
,Wicon
,&xwattr
);
72 level
=(signal
)*(xwattr
.width
-1)/(0xffff);
73 XSetForeground(XD
,xgc
,getcolor("gray70"));
74 XFillRectangle(XD
,Wicon
,xgc
,0,0,xwattr
.width
,xwattr
.height
);
75 if (status
& FE_HAS_LOCK
) XSetForeground(XD
,xgc
,getcolor("rgb:ff/00/00"));
76 else XSetForeground(XD
,xgc
,getcolor("wheat4"));
77 XFillRectangle(XD
,Wicon
,xgc
,0,15,level
,20);
78 level
=(snr
)*(xwattr
.width
-1)/(0xffff);
79 XFillRectangle(XD
,Wicon
,xgc
,0,38,level
,20);
81 XSetForeground(XD
,xgc
,getcolor("white"));
82 XDrawRectangle(XD
,Wicon
,xgc
,0,14,59,21);
83 XDrawRectangle(XD
,Wicon
,xgc
,0,37,59,21);
84 XSetForeground(XD
,xgc
,getcolor("black"));
85 XDrawLine(XD
,Wicon
,xgc
,0,14,59,14); XDrawLine(XD
,Wicon
,xgc
,0,14,0,35);
86 XDrawLine(XD
,Wicon
,xgc
,0,37,59,37); XDrawLine(XD
,Wicon
,xgc
,0,37,0,58);
88 level
=(signal
)*100/(0xffff);
89 sprintf(a
,"sig %%%d",level
);
90 XSetForeground(XD
,xgc
,getcolor("black"));
91 /* ascent font un dikey uzunlugu imis. */
96 XDrawText(XD
,Wicon
,xgc
,2,29,&xti
,1);
97 level
=(snr
)*100/(0xffff);
98 sprintf(a
,"snr %%%d",level
);
100 xti
.nchars
=strlen(a
);
103 XDrawText(XD
,Wicon
,xgc
,2,52,&xti
,1);
104 //sprintf(a,"stat %02x|sig %04x|snr %04x|ber %08x|unc %08x|if %08d|sym %d|f %d", status, signal, snr, ber, uncorrected_blocks, dfp.frequency,dfp.u.qpsk.symbol_rate,freq);
105 sprintf(a
,"f %d", freq
);
107 xti
.nchars
=strlen(a
);
110 XDrawText(XD
,Wicon
,xgc
,1,11,&xti
,1);
111 XFlush(XD
); /*Flush etmeden ekrana bok gibi yaziyor.*/
114 void xmon_W2(int fefd
)
117 uint16_t snr
, signal
, level
;
118 uint32_t ber
, uncorrected_blocks
;
119 struct dvb_frontend_parameters dfp
;
120 XWindowAttributes xwattr
;
125 ioctl(fefd
, FE_READ_STATUS
, &status
);
126 ioctl(fefd
, FE_READ_SIGNAL_STRENGTH
, &signal
);
127 ioctl(fefd
, FE_READ_SNR
, &snr
);
128 ioctl(fefd
, FE_READ_BER
, &ber
);
129 ioctl(fefd
, FE_READ_UNCORRECTED_BLOCKS
, &uncorrected_blocks
);
130 ioctl(fefd
, FE_GET_FRONTEND
, &dfp
);
131 if (dfp
.frequency
+10600000 >= 11700000) freq
=dfp
.frequency
+10600000;
132 else freq
=dfp
.frequency
+ 9750000;
133 XGetWindowAttributes(XD
,W2
,&xwattr
);
135 level
=(signal
)*(xwattr
.width
-1)/(0xffff);
136 XSetForeground(XD
,xgc
,getcolor("gray70"));
137 XFillRectangle(XD
,W2
,xgc
,0,0,xwattr
.width
,xwattr
.height
);
138 if (status
& FE_HAS_LOCK
) XSetForeground(XD
,xgc
,getcolor("rgb:ff/00/00"));
139 else XSetForeground(XD
,xgc
,getcolor("wheat4"));
140 XFillRectangle(XD
,W2
,xgc
,0,15,level
,20);
141 level
=(snr
)*(xwattr
.width
-1)/(0xffff);
142 XFillRectangle(XD
,W2
,xgc
,0,38,level
,20);
144 XSetForeground(XD
,xgc
,getcolor("white"));
145 XDrawRectangle(XD
,W2
,xgc
,0,14,xwattr
.width
-1,21);
146 XDrawRectangle(XD
,W2
,xgc
,0,37,xwattr
.width
-1,21);
147 XSetForeground(XD
,xgc
,getcolor("black"));
148 XDrawLine(XD
,W2
,xgc
,0,14,xwattr
.width
-1,14); XDrawLine(XD
,Wicon
,xgc
,0,14,0,35);
149 XDrawLine(XD
,W2
,xgc
,0,37,xwattr
.width
-1,37); XDrawLine(XD
,Wicon
,xgc
,0,37,0,58);
151 level
=(signal
)*100/(0xffff);
152 sprintf(a
,"sig %%%d",level
);
153 XSetForeground(XD
,xgc
,getcolor("black"));
154 /* ascent font un dikey uzunlugu imis. */
156 xti
.nchars
=strlen(a
);
159 XDrawText(XD
,W2
,xgc
,2,29,&xti
,1);
160 level
=(snr
)*100/(0xffff);
161 sprintf(a
,"snr %%%d",level
);
163 xti
.nchars
=strlen(a
);
166 XDrawText(XD
,W2
,xgc
,2,52,&xti
,1);
167 sprintf(a
,"stat %02x|sig %04x|snr %04x|ber %08x|unc %08x|if %08d|sym %d|f %d", status
, signal
, snr
, ber
, uncorrected_blocks
, dfp
.frequency
,dfp
.u
.qpsk
.symbol_rate
,freq
);
168 //sprintf(a,"f %d", freq);
170 xti
.nchars
=strlen(a
);
173 XDrawText(XD
,W2
,xgc
,1,11,&xti
,1);
174 XFlush(XD
); /*Flush etmeden ekrana bok gibi yaziyor.*/
178 int main(int argc
, char **argv
)
180 XClassHint classhint
;
183 unsigned int adapter
= 0, frontend
= 0;
187 struct dvb_frontend_info fe_info
;
188 int bekle
=0, bekle2
=0;
191 fprintf(stderr,"Option Sayisi=%d\n",argc);
192 for (sayac2=2;sayac2<=argc;sayac2++)
194 fprintf(stderr,"Option %d=%s\n",sayac2,argv[sayac2-1]);
198 while ((opt=getopt(argc, argv, "h:d:"))!=-1) {
201 fprintf(stderr, "Help: [-h] [-d device] [-t aralik]\n");
207 fprintf(stderr, "\nUsage: %s %s", argv[0], USAGE);
212 XD
= XOpenDisplay("");
213 if (!XD
) { fprintf(stderr
, "Default Display acilamadi.\n"); return 1; }
214 W1
= XCreateSimpleWindow(XD
, DefaultRootWindow(XD
),0, 0, 64, 64, 1, 50, getcolor("yellow"));
215 Wicon
= XCreateSimpleWindow(XD
, W1
, 0, 0, 60, 60, 1, 50, getcolor("darkgreen"));
217 wmhints
.initial_state
= WithdrawnState
;
218 wmhints
.icon_window
= Wicon
;
221 wmhints
.window_group
= W1
;
222 wmhints
.flags
= StateHint
| IconWindowHint
| IconPositionHint
| WindowGroupHint
;
223 XSetWMHints(XD
, W1
, &wmhints
);
227 classhint
.res_name
= "wmfemon";
228 classhint
.res_class
= "wmfemon";
229 XSetClassHint(XD
, W1
, &classhint
);
230 XSelectInput(XD
, W1
, ExposureMask
| ButtonPressMask
| ButtonReleaseMask
| StructureNotifyMask
| PointerMotionMask
);
231 XSelectInput(XD
, Wicon
, ExposureMask
| ButtonPressMask
| ButtonReleaseMask
| StructureNotifyMask
| PointerMotionMask
);
232 XStoreName(XD
, W1
, "wmfemon");
233 XSetIconName(XD
, W1
, "wmfemon");
235 gcval
.foreground
= 50;
236 gcval
.background
= 150;
237 gcval
.graphics_exposures
= False
;
238 gcval
.font
= XLoadFont(XD
,"-*-fixed-medium-r-normal-*-10-*-*-*-*-*-*-1");
239 xgc
= XCreateGC(XD
, W1
, GCForeground
| GCBackground
| GCGraphicsExposures
| GCFont
, &gcval
);
241 //f1=XLoadFont(XD,"-*-fixed-medium-r-normal-*-10-*-*-*-*-*-*-1");
242 f1
=XLoadFont(XD
,"-*-clean-medium-r-*-*-12-*-*-*-*-*-*-*");
243 f2
=XLoadFont(XD
,"-*-helvetica-*-r-*-*-12-*-*-*-*-*-*-*");
244 snprintf(fedev
, sizeof(fedev
), FRONTENDDEVICE
, adapter
, frontend
);
245 printf("Device: '%s'\n", fedev
);
246 if ((fefd
= open(fedev
, O_RDONLY
| O_NONBLOCK
)) < 0) { perror("opening frontend failed"); return 0;}
247 z
= ioctl(fefd
, FE_GET_INFO
, &fe_info
);
248 if (z
< 0) { perror("ERR ioctl FE_GET_INFO:"); close(fefd
); return 0;}
256 XNextEvent(XD
, &event
);
261 fprintf(stderr
,"Expose (Update) event geldi.\n");
262 fprintf(stderr
,"xexpose.window=%ld\n",event
.xexpose
.window
);
267 fprintf(stderr
,"xmotion x=%d,y=%d\n",event
.xmotion
.x
,event
.xmotion
.y
);
268 fprintf(stderr
,"xmotion window=%ld\n",event
.xmotion
.window
);
269 fprintf(stderr
,"W1 window=%ld\n",W1
);
270 fprintf(stderr
,"Wicon window=%ld\n",Wicon
);
271 fprintf(stderr
,"-----------------------\n");
275 fprintf(stderr
,"UnmapNotify geldi.\n");
278 fprintf(stderr
,"DestroyNotify geldi.\n");
283 //Kapat tusu icin amma yarak isler lazim ulan. wmclockmon dockapp.c'den alinti.
284 //printf("ClientMessage\n");fflush(stdout);
285 if (event
.xclient
.data
.l
[0] == delete_win
) {
286 if (event
.xclient
.window
==W2
)
287 { XDestroyWindow(XD
,W2
); W2
=0;
292 //fprintf(stderr,"x=%d,y=%d\n",event.xbutton.x,event.xbutton.y);
295 fprintf(stderr
,"x=%d,y=%d\n",event
.xbutton
.x
,event
.xbutton
.y
);
297 { W2
= XCreateSimpleWindow(XD
, DefaultRootWindow(XD
),100,100,600,60,1,50,getcolor("blue"));
298 if (!W2
) { perror("Error: W2"); }
299 delete_win
= XInternAtom(XD
, "WM_DELETE_WINDOW", False
); //DIKKAT: Kapatma tusunun cikmasi icin bu yarak gerekiyor.
300 XSetWMProtocols (XD
, W2
, &delete_win
, 1);
301 XStoreName(XD
, W2
, "DVB Frontend Monitor for WindowMaker");
302 XSetIconName(XD
, W2
, "DVB Signal");
305 { XDestroyWindow(XD
,W2
); W2
=0;
310 if (bekle
== 0) xmon(fefd
);
312 bekle
%= 10; // 10 modulu. W1 1000 ms.
314 { if (bekle2
== 0) xmon_W2(fefd
);
316 bekle2
%= 3; // 3 modulu. W2 biraz daha hizli gostersin. 300 ms.