Skip to content. | Skip to navigation

Personal tools

subsys.cpp

subsys.cpp

subsys.cpp

// SUBSYS.CPP
//
void CMirror::Init()
{
        Motion = MMStop;
        Limit = MLNone;
}

void CMirror::Update()
{
        int OldMotion = Motion,OldLimit = Limit;
#ifdef ENABLEIO
        Motion = 2 * read_bit(48) + read_bit(46);
        Limit = 2 * !read_bit(47) + !read_bit(45);
#endif


// Halt motions if a limit is reached
        if ((Motion & MMUp) && (Limit & MLUp))
                Stop();
        if ((Motion & MMDown) && (Limit & MLDown))
                Stop();
// Halt motion if the mirror times out
        if (Motion && (Timer - MotionTimer > MotionTimeout))
        {
                Stop();
                Log.AddX("Mirror motion timeout",500,LIGHTRED,0);
        }

        if (OldMotion != Motion)
                DisplayMotion();
        if (OldLimit != Limit)
                DisplayLimit();
}

void CMirror::DisplayAll()
{
        DisplayMotion();
        DisplayLimit();
}

void CMirror::DisplayMotion()
{
        switch (Motion)
        {
                case MMStop:
                        PutULED(148,208,BLACK);
                        PutDLED(148,216,BLACK);
                break;
                case MMUp:
                        PutULED(148,208,LIGHTGREEN);
                        PutDLED(148,216,BLACK);
                break;
                case MMDown:
                        PutULED(148,208,BLACK);
                        PutDLED(148,216,LIGHTGREEN);
                break;
                case MMBoth:
                        PutULED(148,208,LIGHTRED);
                        PutDLED(148,216,LIGHTRED);
                break;
        }
}

void CMirror::DisplayLimit()
{
        switch (Limit)
        {
                case MLNone:
                        PutULED(188,208,BLACK);
                        PutDLED(188,216,BLACK);
                        PutString16("Midway",260,340,208,BLACK,LIGHTGRAY);
                break;
                case MLUp:
                        PutULED(188,208,LIGHTGREEN);
                        PutDLED(188,216,BLACK);
                        PutString16("Up",260,340,208,BLACK,LIGHTGRAY);
                break;
                case MLDown:
                        PutULED(188,208,BLACK);
                        PutDLED(188,216,LIGHTGREEN);
                        PutString16("Down",260,340,208,BLACK,LIGHTGRAY);
                break;
                case MLBoth:
                        PutULED(188,208,LIGHTRED);
                        PutDLED(188,216,LIGHTRED);
                        PutString16("Error",260,340,208,BLACK,LIGHTGRAY);
                break;
        }
}

void CMirror::Up()
{
        if (!(Limit & MLUp))
        {
#ifdef ENABLEIO
                write_bit(48,1);
                write_bit(46,0);
#endif

                MotionTimer = Timer;
        }
}

void CMirror::Down()
{
        if (!(Limit & MLDown))
        {
#ifdef ENABLEIO
                write_bit(48,0);
                write_bit(46,1);
#endif

                MotionTimer = Timer;
        }
}

void CMirror::Stop()
{
#ifdef ENABLEIO
                write_bit(48,0);
                write_bit(46,0);
#endif

}

//----------------------------

void CM3TurretPin::Init()
{
        Motion = MTPMStop;
        Limit = MTPLNone;
}

void CM3TurretPin::Update()
{
        int OldMotion = Motion,OldLimit = Limit;
#ifdef ENABLEIO
        Limit = 2 * !read_bit(41) + !read_bit(43);
        Motion = 2 * read_bit(42) + read_bit(44);
#endif


// Halt motions if a limit is reached
        if ((Motion & MTPMLock) && (Limit & MTPLLock))
                Stop();
        if ((Motion & MTPMUnlock) && (Limit & MTPLUnlock))
                Stop();
// Halt motion if the lock pin times out
        if (Motion && (Timer - MotionTimer > MotionTimeout))
        {
                Stop();
                Log.AddX("M3 Turret Pin timeout",500,LIGHTRED,0);
        }

        if (OldMotion != Motion)
                DisplayMotion();
        if (OldLimit != Limit)
                DisplayLimit();
}

void CM3TurretPin::DisplayAll()
{
        DisplayMotion();
        DisplayLimit();
}

void CM3TurretPin::DisplayMotion()
{
        switch (Motion)
        {
                case MTPMStop:
                        PutULED(148,240,BLACK);
                        PutDLED(148,248,BLACK);
                break;
                case MTPMLock:
                        PutULED(148,240,BLACK);
                        PutDLED(148,248,LIGHTGREEN);
                break;
                case MTPMUnlock:
                        PutULED(148,240,LIGHTGREEN);
                        PutDLED(148,248,BLACK);
                break;
                case MTPMBoth:
                        PutULED(148,240,LIGHTRED);
                        PutDLED(148,248,LIGHTRED);
                break;
        }
}

void CM3TurretPin::DisplayLimit()
{
        switch (Limit)
        {
                case MTPLNone:
                        PutULED(188,240,BLACK);
                        PutDLED(188,248,BLACK);
                        PutString16("Midway",260,340,240,BLACK,LIGHTGRAY);
                break;
                case MTPLLock:
                        PutULED(188,240,BLACK);
                        PutDLED(188,248,LIGHTGREEN);
                        PutString16("Locked",260,340,240,BLACK,LIGHTGRAY);
                break;
                case MTPLUnlock:
                        PutULED(188,240,LIGHTGREEN);
                        PutDLED(188,248,BLACK);
                        PutString16("Unlocked",260,340,240,BLACK,LIGHTGRAY);
                break;
                case MTPLBoth:
                        PutULED(188,240,LIGHTRED);
                        PutDLED(188,248,LIGHTRED);
                        PutString16("Error",260,340,240,BLACK,LIGHTGRAY);
                break;
        }
}

void CM3TurretPin::Lock()
{
        if ((M3Turret->Position >= MTPForward) && (M3Turret->Position <= MTPReverse)
                        && (M3Turret->Motion == MTMStop) && !(Limit & MTPLLock))
        {
#ifdef ENABLEIO
                write_bit(44,1);
                write_bit(42,0);
#endif

                MotionTimer = Timer;
        }
}

void CM3TurretPin::Unlock()
{
        if (!(Limit & MTPLUnlock))
        {
#ifdef ENABLEIO
                write_bit(42,1);
                write_bit(44,0);
#endif

                MotionTimer = Timer;
        }
}

void CM3TurretPin::Stop()
{
#ifdef ENABLEIO
        write_bit(44,0);
        write_bit(42,0);
#endif

}

Generated by GNU Enscript 1.6.5.2.
Document Actions