#ifndef __fltkmain_cxx #define __fltkmain_cxx #ifdef __cplusplus extern "C" { /* Syntax C */ #endif #include "../../elastro.h" #include "../eltel.h" extern double LAST; extern time_t cCSTadjcurseconds; extern time_t cCSTcurseconds; extern scopevalues scope; extern guidevalues guide; extern programvalues prog; extern servervalues server; extern xephemfifovalues xephem; extern monitorvalues monitor; extern exfifovalues exfifo; extern encodervalues encoder; extern int exend(void); extern int exmain(int argc, char *argv[]); extern void SetMonitorExtern( MONITORCALLBACK cb ); extern void SetMonitorExternAlert( MONITORCALLBACK cb ); extern int monitorwork(unsigned char event ); extern int monitorobjsetobj(char *instr ); #ifdef __cplusplus } /* End Syntax C */ #endif #include "win.cxx" int exmaininit = 0; Fl_Window* objwin = NULL; char objstr[256] = "\0"; char objfile[256] = "\0"; void cb_btn_obj_cancel(Fl_Button* btn, void* d){ if(objwin != NULL){ list_objfiles->clear(); list_objects->clear(); objwin->hide(); } } void cb_btn_obj_goto(Fl_Button* btn, void* d){ monitorwork( IFEVT_GOTORADECKOORS ); } void cb_btn_obj_origin(Fl_Button* btn, void* d){ monitorwork( IFEVT_ORIGINRADECKOORS ); } void cb_btn_obj_mark(Fl_Button* btn, void* d){ if(objwin != NULL){ if( objstr[0] != 0 ){ if(monitorobjsetobj( &objstr[0] )){ list_objfiles->clear(); list_objects->clear(); objwin->hide(); strcpy(prog.objname,monitor.objname); strcpy(prog.objtype,monitor.objtype); monitorwork( PREVT_MARKRADECKOORS ); } } } } void cb_btn_objdb(Fl_Button* btn, void* d){ DIR *dr; struct dirent * sd; char *p; char str[128]; if( monitor.objdbpath[0] == 0 ){ return; } if(objwin != NULL){ objstr[0] = 0; objfile[0] = 0; objwin->show(); list_objfiles->clear(); list_objects->clear(); dr = opendir( (const char *)monitor.objdbpath ); if(dr == NULL){ return; } rewinddir(dr); while( sd = readdir( dr ) ) { if( sd->d_name[0] == '.'){ continue; } strcpy(str,(const char *)sd->d_name); p = strchr(str,0x0a); if(p != NULL){ p[0] = 0; } p = strchr(str,0x0d); if(p != NULL){ p[0] = 0; } list_objfiles->add((const char *)str); } closedir(dr); } } void cb_list_objects(Fl_Browser* br, void* d){ char *p; p = (char *)br->text(br->value()); if(p != NULL){ strcpy(objstr,p); txt_obj_select->value((const char *)p); } } void cb_objfiles(Fl_Browser* br, void* d){ char *p; FILE *f; char str[128]; p = (char *)br->text(br->value()); if(p != NULL){ sprintf(objfile,"%s/%s",monitor.objdbpath,p); f = fopen( objfile, "rt" ); if(f == NULL){ return; } list_objects->clear(); rewind(f); while(feof(f) == 0){ fgets( str, 120, f ); if(str[0] == ';'){ continue; } if(str[0] == '#'){ continue; } if(strlen(str) < 10 ){ continue; } p = strchr(str,0x0a); if(p != NULL){ p[0] = 0; } p = strchr(str,0x0d); if(p != NULL){ p[0] = 0; } list_objects->add( (const char *) str); } fclose(f); } } void cb_btn_guiding(Fl_Light_Button* btn, void* d){ monitorwork( IFEVT_STARTGUIDE ); } void cb_btn_stop(Fl_Light_Button* btn, void* d){ monitorwork( IFEVT_STOPMOTORS ); } void cb_btn_down_fast(Fl_Button* btn, void* d){ monitorwork( IFEVT_FASTDOWN ); } void cb_btn_up_fast(Fl_Button* btn, void* d){ monitorwork( IFEVT_FASTUP ); } void cb_btn_right_fast(Fl_Button* btn, void* d){ monitorwork( IFEVT_FASTRIGHT ); } void cb_btn_left_fast(Fl_Button* btn, void* d){ monitorwork( IFEVT_FASTLEFT ); } void cb_btn_down_slow(Fl_Button* btn, void* d){ monitorwork( IFEVT_SLOWDOWN ); } void cb_btn_up_slow(Fl_Button* btn, void* d){ monitorwork( IFEVT_SLOWUP ); } void cb_btn_right_slow(Fl_Button* btn, void* d){ monitorwork( IFEVT_SLOWRIGHT ); } void cb_btn_left_slow(Fl_Button* btn, void* d){ monitorwork( IFEVT_SLOWLEFT ); } void cb_btn_fr_init(Fl_Light_Button* btn, void* d){ if(scope.fruse){ monitorwork( PREVT_STOPFIELDROTATOR ); } else { monitorwork( PREVT_INITFIELDROTATOR ); } } void cb_btn_fr_left(Fl_Button* btn, void* d){ monitorwork( PREVT_FRTURNLEFT ); } void cb_btn_fr_right(Fl_Button* btn, void* d){ monitorwork( PREVT_FRTURNRIGHT ); } void cb_btn_get_frkoors(Fl_Button* btn, void* d){ monitorwork( PREVT_GETFRKOOR ); } void cb_btn_getkoor(Fl_Button* btn, void* d){ monitorwork( IFEVT_GETKOORS ); } void cb_btn_getkoor_toxephem(Fl_Button* btn, void* d){ monitorwork( PREVT_SENDAZALTKOORSTOXEPHEM ); } void cb_btn_kpspecial(Fl_Light_Button* btn, void* d){ if(xephem.keypadspecial){ monitorwork( PREVT_JOYSTICKKEYPADASPECIALOFF ); } else { monitorwork( PREVT_JOYSTICKKEYPADASPECIALON ); } } void cb_btn_refraction(Fl_Light_Button* btn, void* d){ if(scope.calcrefraction){ monitorwork( PREVT_SWITCHOFFVALIDCALCREFRACTION ); } else { monitorwork( PREVT_SWITCHONVALIDCALCREFRACTION ); } } void cb_btn_xephemfifooutloop(Fl_Light_Button* btn, void* d){ if(xephem.fifooutloop){ monitorwork( PREVT_XEPHEMOUTLOOPOFF ); } else { monitorwork( PREVT_XEPHEMOUTLOOPON ); } } void cb_btn_exfifofollow(Fl_Light_Button* btn, void* d){ if(exfifo.fiforun){ monitorwork( PREVT_TOGGLEEXFIFOFOLLOW ); } } void cb_btn_encoder(Fl_Light_Button* btn, void* d){ if(encoder.type != NOENCODER){ monitorwork( PREVT_TOGGLEENCODERS ); } } void cb_btn_reserved3(Fl_Light_Button* btn, void* d){ } void cb_btn_reserved4(Fl_Light_Button* btn, void* d){ } int timersema = 0; int monitorexloopbusy = 0; int monitorexloop( char * v) { char txt1[40]; char txt2[40]; char txt3[40]; struct tm * _tm; time_t _tsec; if( ! exmaininit ){ return(0); } monitorexloopbusy = 1; if( prog.motorrun == MNORUN ){ btn_stop->value(0); btn_guiding->value(0); txt_motor->value((const char *)"MOTOR: NOT RUNNING"); } else if(prog.motorrun == MGUIDE){ btn_stop->value(1); btn_guiding->value(1); txt_motor->value((const char *)"MOTOR: GUIDING"); } else if(prog.motorrun == MCORRECTION){ if(prog.motorspeed == SPEED_SLOW){ btn_stop->value(1); btn_guiding->value(0); txt_motor->value((const char *)"MOTOR: MOVING (SLOW)"); } else { btn_stop->value(1); btn_guiding->value(0); txt_motor->value((const char *)"MOTOR: MOVING (FAST)"); } } else if(prog.motorrun == MGOTO){ btn_stop->value(1); btn_guiding->value(0); txt_motor->value((const char *)"MOTOR: FAST GOTO"); } else if(prog.motorrun == MFR){ btn_stop->value(1); btn_guiding->value(0); txt_motor->value((const char *)"MOTOR: FIELDROTATOR"); } txt_ra->value((const char *) prog.rastr ); txt_dec->value((const char *) prog.decstr ); txt_az->value((const char *) prog.azstr ); txt_alt->value((const char *) prog.altstr ); txt_fr->value((const char *) prog.frstr ); sprintf(txt1,"%f",LAST); txt_last->value((const char *)txt1); txt_obj->value((const char *) prog.objname ); txt_type->value((const char *) prog.objtype ); if(prog.motorrun == MGUIDE){ _tsec = cCSTcurseconds; } else { _tsec = time(&_tsec); } _tm = localtime( &_tsec ); sprintf(txt2,"%02d:%02d:%02d",_tm->tm_hour,_tm->tm_min,_tm->tm_sec); txt_tim->value((const char *) txt2 ); if(prog.motorrun == MGUIDE){ _tsec = cCSTadjcurseconds; } else { _tsec = time(&_tsec) + scope.utcadjust; } _tm = localtime( &_tsec ); sprintf(txt3,"%02d:%02d:%02d",_tm->tm_hour,_tm->tm_min,_tm->tm_sec); txt_atm->value((const char *) txt3 ); if(xephem.fifooutloop){ btn_xephemfifooutloop->value(1); } else { btn_xephemfifooutloop->value(0); } if(scope.calcrefraction){ btn_refraction->value(1); } else { btn_refraction->value(0); } if(xephem.keypadspecial){ btn_kp_special->value(1); } else { btn_kp_special->value(0); } if(scope.fruse){ btn_fr_init->value(1); } else { btn_fr_init->value(0); } if(exfifo.follow){ btn_exfifofollow->value(1); } else { btn_exfifofollow->value(0); } if(encoder.active){ btn_encoder->value(1); } else { btn_encoder->value(0); } txt_event->value((const char *)prog.eventstr); if(prog.debug && ( ! timersema ) ){ fprintf(stdout,"\nazhs:%.0f alths:%.0f frhs:%.0f guidesec:%ld guidect:%ld\n", scope.lastazhs,scope.lastalths,scope.lastfrhs, guide.updateseconds, guide.updatecounter); } monitorexloopbusy = 0; return(0); } int monitorexalert( char * txt ){ if(txt_err != NULL){ if(txt != NULL){ txt_err->value((const char *)txt); } } else { fprintf(stdout,"\r\n%s\r\n",txt); } return(0); } void cb_mainwin_end(Fl_Window* w, void* d) { exend(); } void timeraction(void *) { if(timersema){ return; } timersema++; if(! monitorexloopbusy){ monitorexloop(NULL); } Fl::add_timeout(1.0,timeraction); timersema--; } int main(int argc, char *argv[]) { SetMonitorExtern(&monitorexloop); SetMonitorExternAlert(&monitorexalert); if(exmain( argc, argv ) == 0){ make_window(); objwin = make_window_objdb(); mainwin->show(argc,argv); exmaininit = 1; Fl::add_timeout(1.0,timeraction); return Fl::run(); } exit(0); } #endif /*__fltkmain_cxx*/