//
//  Copyright © 2003, RESON Inc. All Rights Reserved.
//
//  No part of this file may be reproduced or transmitted in any form or by
//  any means, electronic or mechanical, including photocopy, recording, or
//  information storage or retrieval system, without permission in writing
//  from RESON Inc.
//
//  Filename:   7kTriggerSequence.cpp
//
//  Project:    6046
//
//  Author(s):  W. Arcus
//
//  Purpose:    Defines the class C7kTriggerSequence and its helper class C7kSequenceStep.
//
//  Notes:      
//

#if !defined(AFX_7KTRIGGERSEQUENCE_H__3E745E94_902D_4760_B05B_724067E58191__INCLUDED_)
#define AFX_7KTRIGGERSEQUENCE_H__3E745E94_902D_4760_B05B_724067E58191__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#pragma warning( push, 3 )                                                                          // Microsoft's STL is dirty so suppress necessary warnings.
#pragma warning( disable : 4018 )
#include <vector>
#pragma warning( default : 4018 )
#pragma warning( pop )

class EXPORT_DLL C7kSequenceStep
{
public:

    ///////////////
    // Definitions.

    enum ETRIGGEREDGE
    {
        triggerEdgeRising       = 0,
        triggerEdgeFalling
    };

    ///////////////
    // Services.
                                        C7kSequenceStep                     (   void );
                                        C7kSequenceStep                     (   const C7kSequenceStep  &rRhs );

    virtual                            ~C7kSequenceStep                     (   void );

    C7kSequenceStep &                   operator =                          (   const C7kSequenceStep  &rRhs );

    bool                                operator ==                         (   const unsigned long    &rulTriggerId )  const;
    bool                                operator <                          (   const unsigned long    &rulTriggerId )  const;

    void                                Configure                           (   const unsigned long     &rulTriggerId,
                                                                                const unsigned long     &rulDelay,
                                                                                const ETRIGGEREDGE      &reTriggerEdge = triggerEdgeRising );

    unsigned long                       TriggerId                           (   void )  const;
    unsigned long                       TriggerEdge                         (   void )  const;
    unsigned long                       Delay                               (   void )  const;

private:

    ///////////////
    // Attributes.

    unsigned long                       m_ulTriggerId;                                                              // Trigger Id.
    unsigned long                       m_ulEdgeTrigger;                                                            // 0 – Raising edge on previous pulse 1 – Falling edge on previous pulse.
    unsigned long                       m_ulDelay;                                                                  // Delay pulse in microseconds since trigger edge of previous pulse (only valid for OUT triggers).

};

class EXPORT_DLL C7kTriggerSequence
{
public:

    ///////////////
    // Definitions.

    enum EMODE
    {
        modeSingleTrigger,
        modeRepeatTrigger
    };

    ///////////////
    // Services.

    // Construction and destruction.

                                        C7kTriggerSequence                  (   void );
                                        C7kTriggerSequence                  (   const C7kTriggerSequence       &rRhs );

    virtual                            ~C7kTriggerSequence                  (   void );

    // Operators.

    C7kTriggerSequence &                operator =                          (   const C7kTriggerSequence   &rRhs );
    bool                                operator <                          (   const C7kTriggerSequence   &rRhs )          const;
    bool                                operator ==                         (   const unsigned long        &rulSequenceId ) const;

    const C7kSequenceStep *             SequenceSteps                       (   void )  const;

    void                                Mode                                (   const EMODE                &reMode );
    void                                SequenceId                          (   const unsigned long        &rulSequenceId );

    void                                Enable                              (   void );
    void                                Disable                             (   void );

    bool                                DeleteSteps                         (   void );
    bool                                AddStep                             (   const C7kSequenceStep      &rsSequenceStep );

    // Read-only methods.

    bool                                IsEnabled                           (   void )  const;
    unsigned long                       SequenceId                          (   void )  const;
    unsigned long                       Steps                               (   void )  const;

private:

    ///////////////
    // Definitions.

    typedef std::vector<C7kSequenceStep> SequenceList_t;
    typedef SequenceList_t::iterator     SequenceListIterator_t;

    ///////////////
    // Attributes.

    bool                                m_bEnabled;
    unsigned long                       m_ulSequenceId;

    EMODE                               m_eMode;
    SequenceList_t                      m_SequenceList;

    ///////////////
    // Services.

    bool                                IsNew                               (   const unsigned long        &rulTriggerId ) const;

};

#endif // !defined(AFX_7KTRIGGERSEQUENCE_H__3E745E94_902D_4760_B05B_724067E58191__INCLUDED_)
