Exemplo n.º 1
0
void ReadConfig( void)
{
        char C;
        int I;
        char StrCompare[MaxStr];

        /* defaults */
        DefaultBackground = 0;
        DefaultColor = 7;
        TitleColor = 9;
        BorderColor = 1;
        MenuColor = 12;
        DisplayColor = 12;
        SelectColor = 0;
        CurrentColor = 14;
        SelectBackground = 4;
        ConfirmQuit = 0;
        DisplayOpeningMsgs = 1;
		  HorizonLimitFlag = 0;
		  MoveHsMsgDeg = 10;
		  HotkeyF9 = HotkeyF10 = HotkeyF11 = HotkeyF12 = 0;
		  HotkeyF9Set = HotkeyF10Set = HotkeyF11Set = HotkeyF12Set = False;
		  InterfacePath = "C:\\GUIDE\\";
		  UseMouseFlag = 0;
		  IACA_Flag = 0;
		  WriteInitHistoryFlag = 1;
		  GEMFlipPossible = 0;
		  AutoGEMFlip = 0;
		  AutoGEMFlipOnFuzzDeg = 0;
		  AutoGEMFlipOffFuzzDeg = 0;
		  Siderostat = 0;
		  HomeAltDeg = 0;
		  HomeAzDeg = 0;
		  MsArcsecSec = 300;
		  precessionNutationAberration = 0;
		  RefractFlag = 0;
		  UseAltAzECFlag = 0;
		  UseAltAltECFlag = 0;
		  UseAzAzECFlag = 0;
		  PointingModelFlag = 0;
		  HandpadPresentFlag = 1;
		  StartingHandpadMode = HandpadOff;
		  HandpadDesign = StandardHandpad;
		  UpDownButtonsReversedFlag = Off;
		  HandpadFlipUpDownWithGEMFlip = Off;
		  AltBacklashArcmin = 0;
		  AzBacklashArcmin = 0;
		  ABacklashSignalPPortPin17 = 0;
		  AltLowLimitDeg = 0;
		  AltHighLimitDeg = 0;
		  AzLowLimitDeg = 0;
		  AzHighLimitDeg = 0;
		  GuideArcsecSec = 5;
		  GuideDragAltArcsecPerMin = 10;
		  GuideDragAzArcsecPerMin = 10;
		  GuideDragRaArcsecPerMin = 10;
		  GuideDragDecArcsecPerMin = 10;
		  HPUpdateDriftFlag = Yes;
		  DriftAltArcsecPerMin = 0;
		  DriftAzArcsecPerMin = 0;
		  DriftRaDegPerHr = 0;
		  DriftDecDegPerHr = 0;
		  PECFlag = 0;
		  AutoAltPECPin = 17;
		  AutoAltPECSyncOnFlag = 0;
		  AutoAltPECSyncLowHighFlag = 1;
		  AutoAltPECSyncDirFlag = 0;
		  AutoAltPECDeBounce = 0;
		  AutoAzPECPin = 15;
		  AutoAzPECSyncOnFlag = 0;
		  AutoAzPECSyncLowHighFlag = 1;
		  AutoAzPECSyncDirFlag = 0;
		  AutoAzPECDeBounce = 0;
		  FullstepsPerPECArray = 200;
		  PECIxOffset.A = 0;
		  PECIxOffset.Z = 0;
		  FRStepSizeArcsec = 60;
        SectoredFRDrive = 1;
        FRStepSpeedMilliSec = 20;
        ReverseFRMotor = 0;
        FocusMethod = 0;
        ReverseFocusMotor = 0;
        FocusFastStepsSec = 2;
        FocusSlowStepsSec = 1;
        FocusPosition = 0;
        MotorControlMethod = 0;
        MotorWindings = 4;
        InvertOutput = 1;
        KeepAlivePPortPin = 0;
        AltFullStepSizeArcsec = 3;
        AzFullStepSizeArcsec = 3;
		  AzFullStepSizeArcsecCW = 0;
		  AzFullStepSizeArcsecCCW = 0;
        ReverseAMotor = 0;
        ReverseZMotor = 0;
        HsRampStyle = 1;
        HsTimerFlag = 1;
        MaxDelay = 1000;
        MinDelay = 300;
        HsDelayX = 2;
        HsRampX = 5;
        InterruptHs = 100;
        HoldReps = 20;
        HsOverVoltageControl = 0;
		  MaxConsecutiveSlews = 5;
        MsPowerDownSec = 5;
        PWMRepsTick = 35;
        AvgPWMRepsTickOnFlag = 1;
        MsDelayX = 6;
        MsPause = 500;
        Ms = 10;
        MaxIncrMsPerPWMWasRead = False;
        MsHsToggleIncrMsPerPWMWasRead = False;
        MaxPWM = 100;
        UseComplexPWMFlag = UseComplexPWMZFlag = No;
        /* zero out PWM[] arrays */
        for( Ix = 0; Ix < MaxMs; Ix++)
        {
                PWM[Ix].A = 0;
                PWM[Ix].Z = 0;
                PWMZ[Ix].A = 0;
                PWMZ[Ix].Z = 0;
        }
        PWM[0].A = 100;
        PWM[1].A = 100;
        PWM[2].A = 100;
        PWM[3].A = 100;
        PWM[4].A = 100;
        PWM[5].A = 100;
        PWM[6].A = 85;
        PWM[7].A = 70;
        PWM[8].A = 55;
        PWM[9].A = 35;
        UsePWMZFlag = No;
        SavePWMComp = No;
        /* 5 is max # of motor windings */
        for( Ix = 0; Ix < 5; Ix++)
                PWM_A_Comp[Ix] = PWM_Z_Comp[Ix] = 1.;
        UseQSC = No;
        for( Ix = 0; Ix < sizeofQSC; Ix++)
                QSCvalues[Ix].A = QSCvalues[Ix].Z = 0;
        PPortAddr = 1;
   // add a couple of default eyepieces: must be <= MAX_EYEPIECES
        Eyepieces = 2;
        EPFocusPosition[0].Position = 100;
        strcpy( EPFocusPosition[0].Name, "EyePiece20mm");
        EPFocusPosition[1].Position = 200;
        strcpy( EPFocusPosition[1].Name, "EyePiece9mm");
        CommPort[Com3].Base = 0x3E8;
        CommPort[Com4].Base = 0x2E8;
        CommPort[Com3].IRQ = 4;
        CommPort[Com4].IRQ = 3;
        EncoderString = "NoEncoders";
        EncoderComPort = 0;
        EncoderBaudRate = 9600;
        SerialWriteDelayMs = 50;
        AltEncoderCountsPerRev = 8192;
        AzEncoderCountsPerRev = 8192;
        AltEncoderDir = 1;
        AzEncoderDir = 0;
        EncoderErrorThresholdDeg = 0;
        TrackEncoderErrorThresholdDeg = 0;
        MakeEncoderResetLogFile = No;
        EncoderOffset.A = 0;
        EncoderOffset.Z = 0;
        LX200ComPort = 0;
        LX200BaudRate = 9600;
        LX200MotionTimeoutSec = 5;
        LX200SlewHs = 10000L;
        LX200_LongFormat = 0;
        Current.Alt = 0;
        Current.Az = 0;
        AccumMs.A = 0;
        AccumMs.Z = 0;
        StartInitState = 0;
        One.Init = No;
        Two.Init = No;
        Three.Init = No;
        Z1Deg = 0;
        Z2Deg = 0;
        Z3Deg = 0;
        DataFileCoordYear = 2000;
        LatitudeDeg = 44;
        CMOS_RTC_Access = 0;
        LongitudeDeg = 123;
   Height = 0;
        Tz = 8;
        DST = 1;
        TestString = "NoTest";

        MaxPWMFoundFlag = No;

        Input = fopen( ConfigFile, "r");
        if( Input == NULL)
                if( DisplayOpeningMsgs)
                {
                        printf( "Warning: no %s found, using default values.\n", ConfigFile);
                        ContMsgRoutine();
                }
                else
                        BadExit( strcat( "Could not open ", ConfigFile));
        else
                fscanf( Input, "%s", Name);

        while( Input!=NULL && !feof( Input))
        {
                /* if 1st char is ';' or '[' then goto next line */
                if( Name[0] == ';' || Name[0] == '[')
                        FReadToNewLine( Input);

                if( (strncmpi( Name, "DefaultBackground", sizeof( Name))) == 0)
                        FReadInt( Input, &DefaultBackground);
                if( (strncmpi( Name, "DefaultColor", sizeof( Name))) == 0)
                        FReadInt( Input, &DefaultColor);
                if( (strncmpi( Name, "TitleColor", sizeof( Name))) == 0)
                        FReadInt( Input, &TitleColor);
                if( (strncmpi( Name, "BorderColor", sizeof( Name))) == 0)
                        FReadInt( Input, &BorderColor);
                if( (strncmpi( Name, "MenuColor", sizeof( Name))) == 0)
                        FReadInt( Input, &MenuColor);
                if( (strncmpi( Name, "DisplayColor", sizeof( Name))) == 0)
                        FReadInt( Input, &DisplayColor);
                if( (strncmpi( Name, "SelectColor", sizeof( Name))) == 0)
                        FReadInt( Input, &SelectColor);
                if( (strncmpi( Name, "CurrentColor", sizeof( Name))) == 0)
                        FReadInt( Input, &CurrentColor);
                if( (strncmpi( Name, "SelectBackground", sizeof( Name))) == 0)
                        FReadInt( Input, &SelectBackground);
                if( (strncmpi( Name, "ConfirmQuit", sizeof( Name))) == 0)
                        FReadFlag( Input, &ConfirmQuit);
                if( (strncmpi( Name, "DisplayOpeningMsgs", sizeof( Name))) == 0)
                        FReadFlag( Input, &DisplayOpeningMsgs);
                if( (strncmpi( Name, "HorizonLimitFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &HorizonLimitFlag);
                if( (strncmpi( Name, "MoveHsMsgDeg", sizeof( Name))) == 0)
                        FReadDouble( Input, &MoveHsMsgDeg);
                if( (strncmpi( Name, "HotkeyF9", sizeof( Name))) == 0)
                {
                        FReadInt( Input, &HotkeyF9);
                        HotkeyF9Set = True;
                }
                if( (strncmpi( Name, "HotkeyF10", sizeof( Name))) == 0)
                {
                        FReadInt( Input, &HotkeyF10);
                        HotkeyF10Set = True;
                }
                if( (strncmpi( Name, "HotkeyF11", sizeof( Name))) == 0)
                {
                        FReadInt( Input, &HotkeyF11);
                        HotkeyF11Set = True;
                }
                if( (strncmpi( Name, "HotkeyF12", sizeof( Name))) == 0)
                {
                        FReadInt( Input, &HotkeyF12);
                        HotkeyF12Set = True;
                }
                if( (strncmpi( Name, "InterfacePath", sizeof( Name))) == 0)
								FReadStringToCharCountOrNewLine( Input, InterfacePath, sizeof( Name));
					 if( (strncmpi( Name, "UseMouseFlag", sizeof( Name))) == 0)
								FReadFlag( Input, &UseMouseFlag);
					 if( (strncmpi( Name, "IACA_Flag", sizeof( Name))) == 0)
								FReadFlag( Input, &IACA_Flag);
					 if( (strncmpi( Name, "WriteInitHistoryFlag", sizeof( Name))) == 0)
								FReadFlag( Input, &WriteInitHistoryFlag);
					 if( (strncmpi( Name, "GEMFlipPossible", sizeof( Name))) == 0)
								FReadFlag( Input, &GEMFlipPossible);
					 if( (strncmpi( Name, "AutoGEMFlip", sizeof( Name))) == 0)
								FReadFlag( Input, &AutoGEMFlip);
					 if( (strncmpi( Name, "AutoGEMFlipOnFuzzDeg", sizeof( Name))) == 0)
								FReadDouble( Input, &AutoGEMFlipOnFuzzDeg);
					 if( (strncmpi( Name, "AutoGEMFlipOffFuzzDeg", sizeof( Name))) == 0)
								FReadDouble( Input, &AutoGEMFlipOffFuzzDeg);
					 if( (strncmpi( Name, "Siderostat", sizeof( Name))) == 0)
								FReadFlag( Input, &Siderostat);
                if( (strncmpi( Name, "HomeAltDeg", sizeof( Name))) == 0)
                        FReadDouble( Input, &HomeAltDeg);
                if( (strncmpi( Name, "HomeAzDeg", sizeof( Name))) == 0)
                        FReadDouble( Input, &HomeAzDeg);
                if( (strncmpi( Name, "MsArcsecSec", sizeof( Name))) == 0)
                        FReadInt( Input, &MsArcsecSec);
                if( (strncmpi( Name, "precessionNutationAberration", sizeof( Name))) == 0)
                        FReadFlag( Input, &precessionNutationAberration);
                if( (strncmpi( Name, "RefractFlag", sizeof( Name))) == 0)
                        FReadInt( Input, &RefractFlag);
                if( (strncmpi( Name, "UseAltAzECFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &UseAltAzECFlag);
                if( (strncmpi( Name, "UseAltAltECFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &UseAltAltECFlag);
                if( (strncmpi( Name, "UseAzAzECFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &UseAzAzECFlag);
                if( (strncmpi( Name, "PointingModelFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &PointingModelFlag);
                if( (strncmpi( Name, "HandpadPresentFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &HandpadPresentFlag);
                if( (strncmpi( Name, "StartingHandpadMode", sizeof( Name))) == 0)
                        FReadInt( Input, &StartingHandpadMode);
                if( (strncmpi( Name, "HandpadDesign", sizeof( Name))) == 0)
                        FReadInt( Input, &HandpadDesign);
                if( (strncmpi( Name, "UpDownButtonsReversedFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &UpDownButtonsReversedFlag);
                if( (strncmpi( Name, "HandpadFlipUpDownWithGEMFlip", sizeof( Name))) == 0)
                        FReadFlag( Input, &HandpadFlipUpDownWithGEMFlip);
                if( (strncmpi( Name, "AltBacklashArcmin", sizeof( Name))) == 0)
                        FReadDouble( Input, &AltBacklashArcmin);
                if( (strncmpi( Name, "AzBacklashArcmin", sizeof( Name))) == 0)
                        FReadDouble( Input, &AzBacklashArcmin);
                if( (strncmpi( Name, "ABacklashSignalPPortPin17", sizeof( Name))) == 0)
                        FReadFlag( Input, &ABacklashSignalPPortPin17);
                if( (strncmpi( Name, "AltLowLimitDeg", sizeof( Name))) == 0)
                        FReadDouble( Input, &AltLowLimitDeg);
                if( (strncmpi( Name, "AltHighLimitDeg", sizeof( Name))) == 0)
                        FReadDouble( Input, &AltHighLimitDeg);
                if( (strncmpi( Name, "AzLowLimitDeg", sizeof( Name))) == 0)
                        FReadDouble( Input, &AzLowLimitDeg);
                if( (strncmpi( Name, "AzHighLimitDeg", sizeof( Name))) == 0)
                        FReadDouble( Input, &AzHighLimitDeg);
                if( (strncmpi( Name, "GuideArcsecSec", sizeof( Name))) == 0)
                        FReadInt( Input, &GuideArcsecSec);
                if( (strncmpi( Name, "GuideDragAltArcsecPerMin", sizeof( Name))) == 0)
                        FReadDouble( Input, &GuideDragAltArcsecPerMin);
                if( (strncmpi( Name, "GuideDragAzArcsecPerMin", sizeof( Name))) == 0)
                        FReadDouble( Input, &GuideDragAzArcsecPerMin);
                if( (strncmpi( Name, "GuideDragRaArcsecPerMin", sizeof( Name))) == 0)
                        FReadDouble( Input, &GuideDragRaArcsecPerMin);
                if( (strncmpi( Name, "GuideDragDecArcsecPerMin", sizeof( Name))) == 0)
                        FReadDouble( Input, &GuideDragDecArcsecPerMin);
                if( (strncmpi( Name, "HPUpdateDriftFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &HPUpdateDriftFlag);
                if( (strncmpi( Name, "DriftAltArcsecPerMin", sizeof( Name))) == 0)
                        FReadDouble( Input, &DriftAltArcsecPerMin);
                if( (strncmpi( Name, "DriftAzArcsecPerMin", sizeof( Name))) == 0)
                        FReadDouble( Input, &DriftAzArcsecPerMin);
                if( (strncmpi( Name, "DriftRaDegPerHr", sizeof( Name))) == 0)
                        FReadDouble( Input, &DriftRaDegPerHr);
                if( (strncmpi( Name, "DriftDecDegPerHr", sizeof( Name))) == 0)
                        FReadDouble( Input, &DriftDecDegPerHr);
                if( (strncmpi( Name, "PECFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &PECFlag);
                if( (strncmpi( Name, "AutoAltPECPin", sizeof( Name))) == 0)
                        FReadLong( Input, &AutoAltPECPin);
                if( (strncmpi( Name, "AutoAltPECSyncOnFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &AutoAltPECSyncOnFlag);
                if( (strncmpi( Name, "AutoAltPECSyncLowHighFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &AutoAltPECSyncLowHighFlag);
                if( (strncmpi( Name, "AutoAltPECSyncDirFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &AutoAltPECSyncDirFlag);
                if( (strncmpi( Name, "AutoAltPECDeBounce", sizeof( Name))) == 0)
                        FReadFlag( Input, &AutoAltPECDeBounce);
                if( (strncmpi( Name, "AutoAzPECPin", sizeof( Name))) == 0)
                        FReadLong( Input, &AutoAzPECPin);
                if( (strncmpi( Name, "AutoAzPECSyncOnFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &AutoAzPECSyncOnFlag);
                if( (strncmpi( Name, "AutoAzPECSyncLowHighFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &AutoAzPECSyncLowHighFlag);
                if( (strncmpi( Name, "AutoAzPECSyncDirFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &AutoAzPECSyncDirFlag);
                if( (strncmpi( Name, "AutoAzPECDeBounce", sizeof( Name))) == 0)
                        FReadFlag( Input, &AutoAzPECDeBounce);
                if( (strncmpi( Name, "FullstepsPerPECArray", sizeof( Name))) == 0)
                        FReadLong( Input, &FullstepsPerPECArray);
                if( (strncmpi( Name, "PECIxOffset.A", sizeof( Name))) == 0)
                        FReadInt( Input, &PECIxOffset.A);
                if( (strncmpi( Name, "PECIxOffset.Z", sizeof( Name))) == 0)
                        FReadInt( Input, &PECIxOffset.Z);
                if( (strncmpi( Name, "FRStepSizeArcsec", sizeof( Name))) == 0)
                        FReadDouble( Input, &FRStepSizeArcsec);
                if( (strncmpi( Name, "SectoredFRDrive", sizeof( Name))) == 0)
                        FReadFlag( Input, &SectoredFRDrive);
                if( (strncmpi( Name, "FRStepSpeedMilliSec", sizeof( Name))) == 0)
                        FReadInt( Input, &FRStepSpeedMilliSec);
                if( (strncmpi( Name, "ReverseFRMotor", sizeof( Name))) == 0)
                        FReadFlag( Input, &ReverseFRMotor);
                /* FocusMethod and MotorControlMethods are defined as enum */
                if( (strncmpi( Name, "FocusMethod", sizeof( Name))) == 0)
                {
                        FReadInt( Input, &I);
                        FocusMethod = I;
                }
                if( (strncmpi( Name, "AltFullStepSizeArcsec", sizeof( Name))) == 0)
                        FReadDouble( Input, &AltFullStepSizeArcsec);
                if( (strncmpi( Name, "AzFullStepSizeArcsec", sizeof( Name))) == 0)
                        FReadDouble( Input, &AzFullStepSizeArcsec);
                if( (strncmpi( Name, "AzFullStepSizeArcsecCW", sizeof( Name))) == 0)
                        FReadDouble( Input, &AzFullStepSizeArcsecCW);
                if( (strncmpi( Name, "AzFullStepSizeArcsecCCW", sizeof( Name))) == 0)
                        FReadDouble( Input, &AzFullStepSizeArcsecCCW);
                if( (strncmpi( Name, "ReverseFocusMotor", sizeof( Name))) == 0)
                        FReadFlag( Input, &ReverseFocusMotor);
                if( (strncmpi( Name, "FocusFastStepsSec", sizeof( Name))) == 0)
                        FReadInt( Input, &FocusFastStepsSec);
                if( (strncmpi( Name, "FocusSlowStepsSec", sizeof( Name))) == 0)
                        FReadInt( Input, &FocusSlowStepsSec);
                if( (strncmpi( Name, "FocusPosition", sizeof( Name))) == 0)
                        FReadInt( Input, &FocusPosition);
                if( (strncmpi( Name, "MotorControlMethod", sizeof( Name))) == 0)
                {
                        FReadInt( Input, &I);
                        MotorControlMethod = I;
                }
                if( (strncmpi( Name, "MotorWindings", sizeof( Name))) == 0)
                        FReadInt( Input, &MotorWindings);
                if( (strncmpi( Name, "InvertOutput", sizeof( Name))) == 0)
                        FReadFlag( Input, &InvertOutput);
                if( (strncmpi( Name, "KeepAlivePPortPin", sizeof( Name))) == 0)
                        FReadInt( Input, &KeepAlivePPortPin);
                if( (strncmpi( Name, "ReverseAMotor", sizeof( Name))) == 0)
                        FReadFlag( Input, &ReverseAMotor);
                if( (strncmpi( Name, "ReverseZMotor", sizeof( Name))) == 0)
                        FReadFlag( Input, &ReverseZMotor);
                if( (strncmpi( Name, "HsRampStyle", sizeof( Name))) == 0)
                        FReadFlag( Input, &HsRampStyle);
                if( (strncmpi( Name, "HsTimerFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &HsTimerFlag);
                if( (strncmpi( Name, "MaxDelay", sizeof( Name))) == 0)
                        FReadInt( Input, &MaxDelay);
                if( (strncmpi( Name, "MinDelay", sizeof( Name))) == 0)
                        FReadInt( Input, &MinDelay);
                if( (strncmpi( Name, "HsDelayX", sizeof( Name))) == 0)
                        FReadInt( Input, &HsDelayX);
                if( (strncmpi( Name, "HsRampX", sizeof( Name))) == 0)
                        FReadInt( Input, &HsRampX);
                if( (strncmpi( Name, "InterruptHs", sizeof( Name))) == 0)
                        FReadInt( Input, &InterruptHs);
                if( (strncmpi( Name, "HoldReps", sizeof( Name))) == 0)
                        FReadInt( Input, &HoldReps);
                if( (strncmpi( Name, "HsOverVoltageControl", sizeof( Name))) == 0)
                        FReadInt( Input, &HsOverVoltageControl);
                if( (strncmpi( Name, "MaxConsecutiveSlews", sizeof( Name))) == 0)
                        FReadInt( Input, &MaxConsecutiveSlews);
                if( (strncmpi( Name, "MsPowerDownSec", sizeof( Name))) == 0)
                        FReadInt( Input, &MsPowerDownSec);
                if( (strncmpi( Name, "PWMRepsTick", sizeof( Name))) == 0)
                        FReadInt( Input, &PWMRepsTick);
                if( (strncmpi( Name, "AvgPWMRepsTickOnFlag", sizeof( Name))) == 0)
                        FReadFlag( Input, &AvgPWMRepsTickOnFlag);
                if( (strncmpi( Name, "MsDelayX", sizeof( Name))) == 0)
                        FReadInt( Input, &MsDelayX);
                if( (strncmpi( Name, "MsPause", sizeof( Name))) == 0)
                        FReadInt( Input, &MsPause);
                if( (strncmpi( Name, "Ms", sizeof( Name))) == 0)
                        FReadInt( Input, &Ms);
                if( (strncmpi( Name, "MaxIncrMsPerPWM", sizeof( Name))) == 0)
                {
                        FReadInt( Input, &MaxIncrMsPerPWM);
                        MaxIncrMsPerPWMWasRead = True;
                }
                if( (strncmpi( Name, "MsHsToggleIncrMsPerPWM", sizeof( Name))) == 0)
                {
                        FReadInt( Input, &MsHsToggleIncrMsPerPWM);
                        MsHsToggleIncrMsPerPWMWasRead = True;
                }
                if( (strncmpi( Name, "MaxPWM", sizeof( Name))) == 0)
                {
                        MaxPWMFoundFlag = Yes;
                        FReadInt( Input, &MaxPWM);
                }
                if( (strncmpi( Name, "PWM[", 4)) == 0)
                        ReadPWMValue();
                if( (strncmpi( Name, "PWMZ[", 5)) == 0)
                {
                        UsePWMZFlag = Yes;
                        ReadPWMValue();
                }
                if( (strncmpi( Name, "PWM_A", 5)) == 0)
                {
                        Ix = Name[6] - 'a';
                        if( Ix >= 0 && Ix < 4)
                        {
                                FReadDouble( Input, &PWM_A_Comp[Ix]);
                                SavePWMComp = Yes;
                        }
                        else
                                BadExit( strcat( "Bad PWM_A_? char in ", ConfigFile));
                }
                if( (strncmpi( Name, "PWM_Z", 5)) == 0)
                {
                        Ix = Name[6] - 'a';
                        if( Ix >= 0 && Ix < 4)
                        {
                                FReadDouble( Input, &PWM_Z_Comp[Ix]);
                                SavePWMComp = Yes;
                        }
                        else
                                BadExit( strcat( "Bad PWM_Z_? char in ", ConfigFile));
                }
                if( (strncmpi( Name, "QSC_", 4)) == 0)
                        if( Name[4] >= 'a' && Name[4] <= 'd')
                        {
                                UseQSC = True;
                                Ix = (Name[4] - 'a') * 4;
                                if( Name[5] >= '0' && Name[5] <= '3')
                                        Ix += Name[5] - '0';
                                FReadDouble( Input, &QSCvalues[Ix].A);
                                do
                                {
                                        C = Blank;
                                        FReadChar( Input, &C);
                                }
                                while( C != '\n' && C != ':');
                                if( C == ':')
                                        FReadDouble( Input, &QSCvalues[Ix].Z);
                        }
                if( (strncmpi( Name, "PPortAddr", sizeof( Name))) == 0)
                {
                        FReadUnsigned( Input, &PPortAddr);
                        StartPPortAddr = PPortAddr;
                }
                if( (strncmpi( Name, "Eyepieces", sizeof( Name))) == 0)
                        FReadInt( Input, &Eyepieces);
                if( Eyepieces > MAX_EYEPIECES)
                        Eyepieces = MAX_EYEPIECES;
                for (Ix=0; Ix < Eyepieces; Ix++)
                {
                        sprintf( StrCompare, "EPFocusPosition[%d].Position", Ix);
                        if( (strncmpi( Name, StrCompare, sizeof( Name))) == 0)
                                FReadInt( Input, &EPFocusPosition[Ix].Position);
                        sprintf( StrCompare, "EPFocusPosition[%d].Name", Ix);
                        if( (strncmpi( Name, StrCompare, sizeof( Name))) == 0)
                                FReadStringToCharCountOrNewLine( Input, EPFocusPosition[Ix].Name, sizeof( Name));
                };
                if( (strncmpi( Name, "COM3Base", sizeof( Name))) == 0)
                        FReadUnsigned( Input, &CommPort[Com3].Base);
                if( (strncmpi( Name, "COM3IRQ", sizeof( Name))) == 0)
                        FReadInt( Input, &CommPort[Com3].IRQ);
                if( (strncmpi( Name, "COM4Base", sizeof( Name))) == 0)
                        FReadUnsigned( Input, &CommPort[Com4].Base);
                if( (strncmpi( Name, "COM4IRQ", sizeof( Name))) == 0)
                        FReadInt( Input, &CommPort[Com4].IRQ);
                if( (strncmpi( Name, "EncoderString", sizeof( Name))) == 0)
                        FReadStringToCharCountOrNewLine( Input, EncoderString, sizeof( Name));
                if( (strncmpi( Name, "EncoderComPort", sizeof( Name))) == 0)
                        FReadInt( Input, &EncoderComPort);
                if( (strncmpi( Name, "EncoderBaudRate", sizeof( Name))) == 0)
                        FReadLong( Input, &EncoderBaudRate);
                if( (strncmpi( Name, "SerialWriteDelayMs", sizeof( Name))) == 0)
                        FReadInt( Input, &SerialWriteDelayMs);
                if( (strncmpi( Name, "AltEncoderCountsPerRev", sizeof( Name))) == 0)
                        FReadLong( Input, &AltEncoderCountsPerRev);
                if( (strncmpi( Name, "AzEncoderCountsPerRev", sizeof( Name))) == 0)
                        FReadLong( Input, &AzEncoderCountsPerRev);
                if( (strncmpi( Name, "AltEncoderDir", sizeof( Name))) == 0)
                        FReadFlag( Input, &AltEncoderDir);
                if( (strncmpi( Name, "AzEncoderDir", sizeof( Name))) == 0)
                        FReadFlag( Input, &AzEncoderDir);
                if( (strncmpi( Name, "EncoderErrorThresholdDeg", sizeof( Name))) == 0)
                        FReadDouble( Input, &EncoderErrorThresholdDeg);
                if( (strncmpi( Name, "TrackEncoderErrorThresholdDeg", sizeof( Name))) == 0)
                        FReadDouble( Input, &TrackEncoderErrorThresholdDeg);
                if( (strncmpi( Name, "MakeEncoderResetLogFile", sizeof( Name))) == 0)
                        FReadFlag( Input, &MakeEncoderResetLogFile);
                if( (strncmpi( Name, "EncoderOffset.A", sizeof( Name))) == 0)
                        FReadDouble( Input, &EncoderOffset.A);
                if( (strncmpi( Name, "EncoderOffset.Z", sizeof( Name))) == 0)
                        FReadDouble( Input, &EncoderOffset.Z);
                if( (strncmpi( Name, "LX200ComPort", sizeof( Name))) == 0)
                        FReadInt( Input, &LX200ComPort);
                if( (strncmpi( Name, "LX200BaudRate", sizeof( Name))) == 0)
                        FReadLong( Input, &LX200BaudRate);
                if( (strncmpi( Name, "LX200MotionTimeoutSec", sizeof( Name))) == 0)
                        FReadInt( Input, &LX200MotionTimeoutSec);
                if( (strncmpi( Name, "LX200SlewHs", sizeof( Name))) == 0)
                        FReadLong( Input, &LX200SlewHs);
                if( (strncmpi( Name, "LX200_LongFormat", sizeof( Name))) == 0)
                        FReadFlag( Input, &LX200_LongFormat);
                if( (strncmpi( Name, "Current.Alt", sizeof( Name))) == 0)
                {
                        FReadDouble( Input, &Current.Alt);
                        Current.Alt *= DegToRad;
                }
                if( (strncmpi( Name, "Current.Az", sizeof( Name))) == 0)
                {
                        FReadDouble( Input, &Current.Az);
                        Current.Az *= DegToRad;
                }
                if( (strncmpi( Name, "AccumMs.A", sizeof( Name))) == 0)
                        FReadLong( Input, &AccumMs.A);
                if( (strncmpi( Name, "AccumMs.Z", sizeof( Name))) == 0)
                        FReadLong( Input, &AccumMs.Z);
                if( (strncmpi( Name, "StartInitState", sizeof( Name))) == 0)
                        FReadInt( Input, &StartInitState);
                if( (strncmpi( Name, "InitOne", sizeof( Name))) == 0)
                        FReadPositionToNewLine( Input, &One);
                if( (strncmpi( Name, "InitTwo", sizeof( Name))) == 0)
                        FReadPositionToNewLine( Input, &Two);
                if( (strncmpi( Name, "InitThree", sizeof( Name))) == 0)
                        FReadPositionToNewLine( Input, &Three);
                if( (strncmpi( Name, "Z1Deg", sizeof( Name))) == 0)
                        FReadDouble( Input, &Z1Deg);
                if( (strncmpi( Name, "Z2Deg", sizeof( Name))) == 0)
                        FReadDouble( Input, &Z2Deg);
                if( (strncmpi( Name, "Z3Deg", sizeof( Name))) == 0)
                        FReadDouble( Input, &Z3Deg);
                if( (strncmpi( Name, "DataFileCoordYear", sizeof( Name))) == 0)
                        FReadDouble( Input, &DataFileCoordYear);
                if( (strncmpi( Name, "LatitudeDeg", sizeof( Name))) == 0)
                        FReadDouble( Input, &LatitudeDeg);
                if( (strncmpi( Name, "CMOS_RTC_Access", sizeof( Name))) == 0)
                        FReadFlag( Input, &CMOS_RTC_Access);
                if( (strncmpi( Name, "LongitudeDeg", sizeof( Name))) == 0)
                        FReadDouble( Input, &LongitudeDeg);
                if( (strncmpi( Name, "Height", sizeof( Name))) == 0)
                        FReadDouble( Input, &Height);
                if( (strncmpi( Name, "Tz", sizeof( Name))) == 0)
                        FReadDouble( Input, &Tz);
                if( (strncmpi( Name, "DST", sizeof( Name))) == 0)
                        FReadInt( Input, &DST);
                if( (strncmpi( Name, "TestString", sizeof( Name))) == 0)
                        FReadStringToCharCountOrNewLine( Input, TestString, sizeof( Name));
                fscanf( Input, "%s", Name);
        }
        fclose( Input);

        if( !MaxIncrMsPerPWMWasRead)
                MaxIncrMsPerPWM = Ms/2;

        if( !MsHsToggleIncrMsPerPWMWasRead)
                MsHsToggleIncrMsPerPWM = Ms/4;

        if( LongitudeDeg < 0)
                LongitudeDeg = 360. + LongitudeDeg;

        if( AutoGEMFlip)
                GEMFlipPossible = True;

        if( AutoAltPECDeBounce)
                AutoAltPECDeBounce = 1;
        if( AutoAzPECDeBounce)
                AutoAzPECDeBounce = 1;
}
Exemplo n.º 2
0
void DisplayInit( void)
{
	int StartX = InitFrame.Left + 5;
	int StartY = InitFrame.Top + 1;
	int AltX, AzX, RaX, DecX, SidTX;

	AltX = StartX + 3;
	AzX = AltX + SizeofDegX + 1;
	RaX = AzX + SizeofDegX + 1;
	DecX = RaX + SizeofHMSX + 1;
	SidTX = DecX + SizeofDMSX + 1;

	WriteWindow( InitFrame);

	TextAttr = DefaultText;
	VidMemXY.Y = StartY;
	VidMemXY.X = AltX;

	if( One.Init)
	{
		sprintf( StrBuf, "Alt");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = AzX;
		sprintf( StrBuf, "Az");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = RaX;
		sprintf( StrBuf, "Ra");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = DecX;
		sprintf( StrBuf, "Dec");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = SidTX;
		sprintf( StrBuf, "SidT");
		WriteStrBufToScreen_f_ptr();

		VidMemXY.Y++;
		VidMemXY.X = StartX;
		sprintf( StrBuf, "1:");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = AltX;
		VidMemDeg( One.Alt);
		VidMemXY.X = AzX;
		VidMemDeg( One.Az);
		VidMemXY.X = RaX;
		VidMemRaHMS( &One);
		VidMemXY.X = DecX;
		VidMemDecDMS( &One);
		VidMemXY.X = SidTX;
		VidMemSidT( &One);
	}
	else
	{
		sprintf( StrBuf, "no inits to display");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.Y++;
	}

	if( Two.Init)
	{
		VidMemXY.Y++;
		VidMemXY.X = StartX;
		sprintf( StrBuf, "2:");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = AltX;
		VidMemDeg( Two.Alt);
		VidMemXY.X = AzX;
		VidMemDeg( Two.Az);
		VidMemXY.X = RaX;
		VidMemRaHMS( &Two);
		VidMemXY.X = DecX;
		VidMemDecDMS( &Two);
		VidMemXY.X = SidTX;
		VidMemSidT( &Two);
	}
	if( Three.Init)
	{
		VidMemXY.Y++;
		VidMemXY.X = StartX;
		sprintf( StrBuf, "3:");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.X = AltX;
		VidMemDeg( Three.Alt);
		VidMemXY.X = AzX;
		VidMemDeg( Three.Az);
		VidMemXY.X = RaX;
		VidMemRaHMS( &Three);
		VidMemXY.X = DecX;
		VidMemDecDMS( &Three);
		VidMemXY.X = SidTX;
		VidMemSidT( &Three);                 
	}
	if( Two.Init)
	{
		VidMemXY.Y += 2;
		VidMemXY.X = StartX;
		sprintf( StrBuf, "Lat: ");
		WriteStrBufToScreen_f_ptr();
		VidMemDeg( Lat);
		sprintf( StrBuf, " (dif %3.3f)", Lat*RadToDeg - LatitudeDeg);
		WriteStrBufToScreen_f_ptr();

		sprintf( StrBuf, " Long: ");
		WriteStrBufToScreen_f_ptr();
		VidMemDeg( LongitudeRad);
		sprintf( StrBuf, " (dif %3.3f)", LongitudeRad*RadToDeg - LongitudeDeg);
		WriteStrBufToScreen_f_ptr();

		VidMemXY.Y++;
		VidMemXY.X = StartX;
		sprintf( StrBuf, "AzOff: ");
		WriteStrBufToScreen_f_ptr();
		VidMemDeg( AzOff);

		sprintf( StrBuf, " HAOff: ");
		WriteStrBufToScreen_f_ptr();
		GetHMSH( RadToHundSec*HAOff + 0.5, &HAOffHMSH);
		StrBufSHMS( HAOffHMSH);
		WriteStrBufToScreen_f_ptr();
		sprintf( StrBuf, " or %3.3f deg", HAOff*RadToDeg);
		WriteStrBufToScreen_f_ptr();

		VidMemXY.Y+=2;
		VidMemXY.X = StartX;
		sprintf( StrBuf, "To polar align, move %3.3f deg %s, %3.3f deg %s",
		fabs( PolarAlign.A*RadToDeg), PolarAlign.A<0.?"down":"up",
		fabs( PolarAlign.Z*RadToDeg), PolarAlign.Z<0.?"left":"right");
		WriteStrBufToScreen_f_ptr();
		VidMemXY.Y++;
	}
	VidMemXY.Y++;
	VidMemXY.X = StartX;
	sprintf( StrBuf, "Z1: %3.3f   Z2: %3.3f   Z3: %3.3f", Z1*RadToDeg,
	Z2*RadToDeg, Z3*RadToDeg);
	WriteStrBufToScreen_f_ptr();

	gotoxy( StartX + 6, VidMemXY.Y += 3);
	ContMsgRoutine();
	RemoveWindow( InitFrame);
}
Exemplo n.º 3
0
void TrackEncoder( void)
{
	const int MaxTries = 9;
	int count = 0;
	int step;
	double StepsPerSec;
	int rate;

	TE = (struct AZLong*) malloc( MsInWindings * sizeof( struct AZLong));
	if( TE == NULL)
		BadExit( "Problem with malloc of TE in TrackEncoder()");

	WriteWindow( MsgFrame);

	gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 1);
	printf( "moving motors to start position...");
	/* attempt to move both motors to microstep '0' on winding 'A' */
	do
	{
		Steps.A = (MsIx.A/MaxPWM) % MsInWindings;
		if( Steps.A && Dir.A == CW)
			Steps.A = MsInWindings - Steps.A;
		Steps.Z = (MsIx.Z/MaxPWM) % MsInWindings;
		if( Steps.Z && Dir.Z == CW)
			Steps.Z = MsInWindings - Steps.Z;
		MoveMs_f_ptr();
		count++;
	}while( count < MaxTries && (Steps.A || Steps.Z));

	/* get rate of motion */
	gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 2);
	printf( "Please enter speed in microsteps per second ");
	if( !GetDouble( &StepsPerSec))
		/* if user aborts, then set it up so that no more execution occurs */
		count = MaxTries;
	else
		/* split rate in half bec. encoders read halfway through */
		rate = (int) (.5 + ClockTicksSec / (2.*StepsPerSec));

	if( count < MaxTries)
	{
		/* move MsInWindings microsteps, taking encoder readings as we go */
		for( step = 0; step < MsInWindings; step++)
		{
			Steps.A = Steps.Z = 1;
			for( Ix = 0; Ix < rate; Ix++)
				MoveMs_f_ptr();
			QueryEncoders_f_ptr();
			for( Ix = 0; Ix < rate; Ix++)
				MoveMs_f_ptr();
			if( EncoderState == ReadReady)
				ReadEncoders_f_ptr();
			TE[step].A = EncoderCount.A;
			TE[step].Z = EncoderCount.Z;
			gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 3);
			printf( "microstep %d: encA %ld encZ %ld", step, TE[step].A, TE[step].Z);
		}
		gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 4);
		printf( "writing %s file", TrackEncodersFile);
		Output = fopen( TrackEncodersFile, "w");
		if( Input == NULL)
			BadExit( strcat( "Could not open ", TrackEncodersFile));
		for( step = 0; step < MsInWindings; step++)
			fprintf( Output, "%d %ld %ld\n", step, TE[step].A, TE[step].Z);
		fclose( Output);
		gotoxy( MsgFrame.Left + 2, MsgFrame.Top + 5);
		ContMsgRoutine();
		RemoveWindow( MsgFrame);
	}
	else
	{
		RemoveWindow( MsgFrame);
		PressKeyToContMsg( "could not move motors to start position");
	}
	free( TE);
	PauseUntilNewSidTime();
	HPEventGetEquat();
}
Exemplo n.º 4
0
void main( int argc, char** argv)
{
	//struct Position Pos;
	int Ix;

	strcpy( ConfigFile, "config.dat");

	Parity = NoneParity;
	DataBits = 8;
	StopBits = 1;

	CalledByGuideFlag = No;
	KeepGoingFlag = No;
	ReadSlewFlag = No;
	StartScrollFlag = No;

	/* if '-k' and '-s' (after full init): slew to Ra, Dec in slew.dat and keep going, exiting when
	desired, writing slew_out.dat file;
	if '-k' (before full init): (no slew.dat), keep going until centered on init position, write
	slew_out.dat file and exit;
	if '-s': slew to Ra, Dec in slew.dat and exit, writing slew_out.dat file;
	if no '-k' and no '-s': write slew_out.dat file and exit;

	if -c, then use following string as configuration file name, ie scope.exe -c config.dat will
	result in config.dat being used

	if -x, then use following string as scroll file name, and execute scroll file upon program
	startup, ie scope.exe -x nan.scr	will cause nan.scr to be loaded and started */

	/* argv[0] is name of executing program */
	for( Ix = 1; Ix < argc; Ix++)
		if( argv[Ix][0] == '-')
			if( strcmpi( &argv[Ix][1], "GUIDE") == 0)
				CalledByGuideFlag = Yes;
			else if( argv[Ix][1] == 'k')
				KeepGoingFlag = Yes;
			else if( argv[Ix][1] == 's')
				ReadSlewFlag = Yes;
			else if( (argv[Ix][1] == 'c' || argv[Ix][1] == 'C') && Ix < argc-1)
				strcpy( ConfigFile, argv[Ix+1]);
			else if( (argv[Ix][1] == 'x' || argv[Ix][1] == 'X') && Ix < argc-1)
			{
				strcpy( ScrollFilename, argv[Ix+1]);
				StartScrollFlag = Yes;
			}

	InitCommonVars();
	ReadConfig();

	/*
		Pos.Ra = Pos.Dec = 0;
		applyCorrectionsFromDataFileCoordYearToEpochNow(&Pos);
		printf("\n%f %f %f %f %f %f %f %f", Pos.Precession.A*RadToArcsec, Pos.Precession.Z*RadToArcsec,
		Pos.Nutation.A*RadToArcsec, Pos.Nutation.Z*RadToArcsec, Pos.AnnualAberration.A*RadToArcsec,
		Pos.AnnualAberration.Z*RadToArcsec, Pos.Ra*RadToArcsec, Pos.Dec*RadToArcsec);
		ContMsgRoutine();
	*/
	/*
		HsRecFile = fopen( HsRecFilename, "w");
		if( HsRecFile == NULL)
			BadExit( strcat( "Could not create ", HsRecFilename));
		HsRecIx = 0;
	*/

	/*
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		InitConvert();
		TestConvert();
		getch();
		TestAltAltAzTrack();
	*/


	if( DisplayOpeningMsgs)
	{
		printf( "\nCopyright BBAstroDesigns Inc. 2009\n");
		printf( "\nLIMITED WARRANTY This software is provided ``as is'' and any express or");
		printf( "\nimplied warranties, including, but not limited to, the implied warranties");
		printf( "\nof merchantability and fitness for a particular purpose are disclaimed.");
		printf( "\nIn no event shall BBAstroDesigns be liable for any direct, indirect,");
		printf( "\nincidental, special, exemplary, nor consequential damages (including, but");
		printf( "\nnot limited to, procurement of substitute goods or services, loss of use,");
		printf( "\ndate, or profits, or business interruption) however caused and on any");
		printf( "\ntheory of liability, whether in contract, strict liability, or tort");
		printf( "\n(including negligence or otherwise) arising in any way out of the use of");
		printf( "\nthis software, even if advised of the possibility of such damage.\n");
		printf( "\nThis software licensed under the GNU GENERAL PUBLIC LICENSE. You may");
		printf( "\ndistribute this software per the GNU GPL. See the enclosed gpl.txt.\n\n");
		ContMsgRoutine();
	}

	if( DisplayOpeningMsgs)
		printf( "\ncalled by guide: %d, keep_going: %d, read slew.dat file %d",
		CalledByGuideFlag, KeepGoingFlag, ReadSlewFlag);

	/* if( strcmpi( TestString, "TestSerial") == 0)
	{
		InitSerial( EncoderComPort, EncoderBaudRate, Parity, DataBits, StopBits);
		TestSerial( EncoderComPort);
		CloseSerial( EncoderComPort);
	} */
	/* else if( strcmpi( TestString, "TestVideo") == 0)
	{
		InitVideo( DisplayOpeningMsgs);
		TestVideo();
	} */
	/* else if( strcmpi( TestString, "TestATimes") == 0)
	{
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		TestTimes();
	} */
	/* else if( strcmpi( TestString, "TestParallelPort") == 0)
	{
		InitPPort();
		TestPPort();
		ClosePPort();
	} */
	/* else if( strcmpi( TestString, "TestRefract") == 0)
	{
		InitRefract();
		TestRefract();
	} */
	/* else if( strcmpi( TestString, "TestMouse") == 0)
	{
		TestMouse();
	} */
	/* else if( strcmpi( TestString, "TestEncoders") == 0)
	{
		InitSerial( EncoderComPort, EncoderBaudRate, Parity, DataBits, StopBits);
		InitEncoders();
		TestEncoders();
		CloseSerial( EncoderComPort);
	} */
	/* else if( strcmpi( TestString, "TestHandpad") == 0)
	{
		InitPPort();
		InitializeHandpad();
		TestHandpad();
		ClosePPort();
	} */
	/* else if( strcmpi( TestString, "TestConversion") == 0)
	{
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		InitConvert();
		TestConvert();
	} */
	/* else if( strcmpi( TestString, "TestAltOffset") == 0)
	{
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		InitConvert();
		TestAltOffset();
	} */
	/* else if( strcmpi( TestString, "TestIACA") == 0)
	{
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		TestIACA();
		InitIACA();
	} */
	/* else if( strcmpi( TestString, "WritePWMValues") == 0)
	{
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		InitVideo( DisplayOpeningMsgs);
		InitPPort();
		InitMotors();
		WritePWMValues();
		CloseSteppers();
		ClosePPort();
	}
	else */
	{
		if( strcmpi( TestString, "NoTest") != 0
		&& strcmpi( TestString, "PreloadGuidexx.dat") != 0
		&& strcmpi( TestString, "Track") != 0)
		{
			if( DisplayOpeningMsgs)
				printf( "\nsetting unrecognized TestString to 'NoTest'");
			strcpy( TestString, "NoTest");
		}
		InitSerial( EncoderComPort, EncoderBaudRate, Parity, DataBits, StopBits);
		InitEncoders();
		InitMouseControl();
		InitTimes( DisplayOpeningMsgs, Tz, DST, LongitudeDeg);
		InitVideo( DisplayOpeningMsgs);
		InitPPort();
		InitializeHandpad();
		InitMotors();
		InitConvert();
		InitRefract();
		InitPEC();
		InitGuide();
		if( strcmpi( TestString, "PreloadGuidexx.dat") == 0)
		{
			LoadGuideAlts();
			LoadGuideAzs();
		}
		InitIACA();
		InitLX200Input();
		InitHPEvent();
		if( !CalledByGuideFlag ||
		(CalledByGuideFlag && (KeepGoingFlag || ReadSlewFlag)))
		{
			InitKBEvent();
			if( ReadSlewFlag)
				InputEquatSlewDat();
			if( StartScrollFlag)
				LoadScrollFileFromFile();
			if( strcmpi( TestString, "Track") == 0)
				Start2MotorTrackWithDefaultValues();
			while( !QuitFlag)
			{
				SequentialTaskController();
				/* GrandTourFlag used to flag next object: set in ProcessHPEventsModeSwitch() */
				if( GrandTourLoaded && GrandTourFlag)
					ProcessGrandTour();
				else
					if( ScrollLoaded && ScrollFlag)
						ProcessScroll();
					else
						if( HPPolarAlignLoaded && HPPolarAlignFlag)
							ProcessHPPolarAlign();
						else
						{
							if( UseMouseFlag && ProcessMouseEvent())
								;
							else
								if( KeyStroke)
									ProcessKBEvents();
								else
									ProcessHPEvents();
						}
			}
			CloseKBEvent();
			if( DisplayOpeningMsgs)
			{
				AskAndWriteConfig();
				WriteLogFile();
			}
		}
		CloseSteppers();
		ClosePPort();
		CloseEncoderResetLogFile();
		CloseSerial( EncoderComPort);
		CloseSerial( LX200ComPort);
		if( CalledByGuideFlag)
			WriteAltazSlewOutFile();
		CloseMouseControl();
	}

	/*
		for( Ix = 0; Ix < HsRecSize; Ix++)
			fprintf( HsRecFile, "%8ld   %8ld\n", HsRec[Ix].A, HsRec[Ix].Z);
		// first position is index 0
		fprintf( HsRecFile, " last entry in circular queue at position %d", HsRecIx);
		fclose( HsRecFile);
	*/
}