#ifndef FD_xtuner_h_ #include "xtuner.h" #endif #include "pixmaps/happy.xpm" #include "pixmaps/led.xpm" #include "pixmaps/radio.xpm" extern flags_t flags; extern xtuner_data_t xtuner_data; extern mixer_data_t mixer_data; extern FD_xtuner *mainui; extern Display *dpy; extern GC canvasGC; extern GC toneGC; extern Window window; /* ======================================================================= */ /* update: Clear the LED display and redraw according to new freq */ /* ======================================================================= */ void update() { int i; int seg; int shim; int fq; int digit; int shift; int temp[6]; char buf[5]; float temp_freq; time_t now; struct tm *now_tm; /* Clear window to see our changes */ XClearWindow(dpy, window); /* If radio is on display LED */ if (flags.radio_f) { fq = 0; digit = 0; shim = -5; temp_freq = xtuner_data.freq; memset(buf,0,5); memset(temp,0,6); if (temp_freq >= 100) { temp[0] = temp_freq / 100; temp_freq -= 100; } temp[1] = temp_freq / 10; temp_freq -= (temp[1]*10); temp[2] = temp_freq / 1; temp_freq -= temp[2]; temp[3] = temp_freq / .1; temp_freq -= (temp[3]*.1); temp[4] = temp_freq / .01; temp_freq -= (temp[4]*.01); temp[5] = temp_freq / .001; for(digit=0; digit < 6; digit++) { shift = shim+(digit*25); fq = temp[digit]; if (fq == 0 && digit == 0) continue; for(seg=0; seg<7; seg++) { if (LCD[fq][seg] == 1) { switch (seg) { case 0: XDrawLine(dpy, window, canvasGC, 100+shift, 11, 100+shift, 21); break; case 1: XDrawLine(dpy, window, canvasGC, 100+shift, 26, 100+shift, 38); break; case 2: XDrawLine(dpy, window, canvasGC, 105+shift, 11, 110+shift, 11); break; case 3: XDrawLine(dpy, window, canvasGC, 105+shift, 25, 110+shift, 25); break; case 4: XDrawLine(dpy, window, canvasGC, 105+shift, 38, 110+shift, 38); break; case 5: XDrawLine(dpy, window, canvasGC, 115+shift, 11, 115+shift, 21); break; case 6: XDrawLine(dpy, window, canvasGC, 115+shift, 26, 115+shift, 38); break; default: break; } } } } XDrawLine(dpy, window, canvasGC, 165, 38, 166, 38); if (flags.preset_f && (flags.disp_type_f == NORM)) XCopyArea(dpy, happypixmap, window, canvasGC, 0,0, 20,20, 55,9); if ((flags.tuned_f == TRUE) && (flags.disp_type_f == NORM)) XDrawString(dpy, window, canvasGC, 10, 40, "(((stereo)))", 12); /* Change the title to current freq */ sprintf(buf, "%.1f", xtuner_data.freq); fl_set_form_title(mainui->xtuner, buf); } else fl_set_form_title(mainui->xtuner, "Xtuner - OFF"); if (flags.disp_type_f == NORM) { /* Display the clock */ now = time(NULL); now_tm = localtime(&now); if(!flags.miltime_f) { if (now_tm->tm_hour > 12) now_tm->tm_hour -= 12; if (now_tm->tm_hour == 0) now_tm->tm_hour = 12; } sprintf(buf,"%2i:%02i",now_tm->tm_hour,now_tm->tm_min); XDrawString(dpy, window, canvasGC, 10, 20, buf, 5); } else { XDrawString(dpy, window, canvasGC, 0,19, "T", 1); XDrawString(dpy, window, canvasGC, 0,39, "B", 1); /* Draw the treble level meter */ fl_set_foreground(toneGC, FL_GREEN); if (mixer_data.treble_level > 40) XDrawLine(dpy, window, toneGC, 10,15, 40,15); else XDrawLine(dpy, window, toneGC, 10,15, mixer_data.treble_level,15); fl_set_foreground(toneGC, FL_YELLOW); if (mixer_data.treble_level >= 70) XDrawLine(dpy, window, toneGC, 40,15, 70,15); else if ((mixer_data.treble_level > 40) && (mixer_data.treble_level < 70)) XDrawLine(dpy, window, toneGC, 40,15, mixer_data.treble_level,15); fl_set_foreground(toneGC, FL_RED); if (mixer_data.treble_level >= 90) XDrawLine(dpy, window, toneGC, 70,15, 90,15); else if ((mixer_data.treble_level >= 70) && (mixer_data.treble_level < 90)) XDrawLine(dpy, window, toneGC, 70,15, mixer_data.treble_level,15); /* Draw the bass level meter */ fl_set_foreground(toneGC, FL_GREEN); if (mixer_data.bass_level > 40) XDrawLine(dpy, window, toneGC, 10,35, 40,35); else XDrawLine(dpy, window, toneGC, 10,35, mixer_data.bass_level,35); fl_set_foreground(toneGC, FL_YELLOW); if (mixer_data.bass_level >= 70) XDrawLine(dpy, window, toneGC, 40,35, 70,35); else if ((mixer_data.bass_level > 40) && (mixer_data.bass_level < 70)) XDrawLine(dpy, window, toneGC, 40,35, mixer_data.bass_level,35); fl_set_foreground(toneGC, FL_RED); if (mixer_data.bass_level >= 90) XDrawLine(dpy, window, toneGC, 70,35, 90,35); else if ((mixer_data.bass_level >= 70) && (mixer_data.bass_level < 90)) XDrawLine(dpy, window, toneGC, 70,35, mixer_data.bass_level,35); } } /* ========================================================================= */ int canvas_expose(FL_OBJECT *ob, Window win, int w, int h, XEvent *ev, void *d) { update(); } /* ========================================================================= */ int canvas_but(FL_OBJECT *ob, Window win, int w, int h, XEvent *ev, void *d) { if (ev->type == ButtonPress) { if (flags.disp_type_f == NORM) { flags.disp_type_f = TONE; fl_set_object_label(mainui->fine_text, "Bass"); fl_draw_object_label(mainui->fine_text); fl_set_object_label(mainui->vol_text, "Treble"); fl_draw_object_label(mainui->vol_text); fl_redraw_object(mainui->fine_frame); fl_redraw_object(mainui->vol_frame); fl_set_object_callback(mainui->fine_down, mixer, BASS_DOWN); fl_set_object_callback(mainui->fine_up, mixer, BASS_UP); fl_set_object_callback(mainui->volumedn, mixer, TREBLE_DOWN); fl_set_object_callback(mainui->volumeup, mixer, TREBLE_UP); } else { flags.disp_type_f = NORM; fl_set_object_label(mainui->fine_text, "Fine"); fl_draw_object_label(mainui->fine_text); fl_set_object_label(mainui->vol_text, "Volume"); fl_draw_object_label(mainui->vol_text); fl_redraw_object(mainui->fine_frame); fl_redraw_object(mainui->vol_frame); fl_set_object_callback(mainui->fine_down, tuner,0); fl_set_object_callback(mainui->fine_up,tuner,2); fl_set_object_callback(mainui->volumedn, adjust_volume, 1); fl_set_object_callback(mainui->volumeup, adjust_volume, 0); } } update(); } /* ========================================================================= */ void init_canvasGC(FD_xtuner *fdui) { int width,height,hotx,hoty; Pixmap iconpixmap; /* Assign callbacks for canvas events */ fl_add_canvas_handler(fdui->canvas, Expose, canvas_expose,fdui); fl_add_canvas_handler(fdui->canvas, ButtonPress, canvas_but,fdui); fl_add_canvas_handler(fdui->canvas, ButtonRelease,canvas_but,fdui); /* Create the default GC */ canvasGC = XCreateGC(dpy, fl_state[fl_vmode].trailblazer,0,0); toneGC = XCreateGC(dpy, fl_state[fl_vmode].trailblazer,0,0); /* Read in the pixmap for the icon iconpixmap = fl_read_pixmapfile(fl_default_window(), "radio.xpm", &width, &height, NULL, &hotx, &hoty, FL_BLACK);*/ iconpixmap = fl_create_from_pixmapdata(fl_default_window(), radio_xpm, &width, &height, NULL, &hotx, &hoty, FL_BLACK); /* set our icon */ fl_set_form_icon(mainui->xtuner, iconpixmap, 0); /* Start the clock timer */ fl_set_timer(fdui->update_timer,2); } /* ========================================================================= */ void init_LED(FD_xtuner *fdui) { int err; int hotx = 0; int hoty = 0; unsigned width = 0; unsigned height = 0; unsigned long valuemask; XImage *temp; Pixmap backpixmap; XSetWindowAttributes setwinattr; /* Initialize some Xlib and XPM stuff */ window = FL_ObjWin(mainui->canvas); valuemask = CWBackPixmap | CWBorderPixel; /* Set our text color and line width */ fl_set_foreground(canvasGC, FL_GREEN); fl_set_foreground(toneGC, FL_GREEN); XSetLineAttributes(dpy, canvasGC, 3, LineSolid, CapRound, JoinBevel); XSetLineAttributes(dpy, toneGC, 10, LineSolid, CapButt, JoinBevel); /* Read in the pixmap for the LCD panel */ happypixmap = fl_create_from_pixmapdata(window, happy_xpm, &width, &height, NULL, &hotx, &hoty, FL_BLACK); /* Read in the pixmap for the LCD panel */ backpixmap = fl_create_from_pixmapdata(window, led_xpm, &width, &height, NULL, &hotx, &hoty, FL_BLACK); /* Set our background image */ setwinattr.background_pixmap = backpixmap; XChangeWindowAttributes(dpy, window, valuemask, &setwinattr); /* Clear window to see our changes */ XClearWindow(dpy, window); }