#ifndef _MODE_CTRL
#define _MODE_CTRL

#include "mag_types.h"

enum MagMode { m_randnom=0, m_stop_or_manual, m_pot_field, m_path, m_bug2, m_mapping, m_save=98, m_quit=99 };

class MagJoystickClass {
public:
    void            setState(double nx, double ny, double nz, double nr, unsigned nb, unsigned nh, long int t)
                                            { x=nx; y=ny; z=nz; r=nr; b=nb; h=nh; ts=t; }
    double          getX    () const        { return(x); }
    double          getY    () const        { return(y); }
    double          getZ    () const        { return(z); }
    double          getR    () const        { return(r); }
    unsigned        getButtons() const      { return(b); }
    bool            getBut1() const         { return((b&0x0001)!=0); }
    bool            getBut2() const         { return((b&0x0002)!=0); }
    bool            getBut3() const         { return((b&0x0004)!=0); }
    bool            getBut4() const         { return((b&0x0008)!=0); }
    bool            getBut5() const         { return((b&0x0010)!=0); }
    bool            getBut6() const         { return((b&0x0020)!=0); }
    bool            getBut7() const         { return((b&0x0040)!=0); }
    bool            getBut8() const         { return((b&0x0080)!=0); }
    bool            getBut9() const         { return((b&0x0100)!=0); }
    bool            getButA() const         { return((b&0x0200)!=0); }
    bool            getButB() const         { return((b&0x0400)!=0); }
    bool            getButC() const         { return((b&0x0800)!=0); }
    unsigned        getHat() const          { return(h); }
    bool            getTS()  const          { return(ts); }

protected:
    double          x, y, z, r;
    unsigned short  b;  // buttons - pressed has a corresponding bit set to 1
    unsigned short  h;  // hat (if available)
    unsigned long   ts; // timestamp
};

// lock/unlock applied automatically
extern AutoSynchronized<MagMode>          robotMode;
extern AutoSynchronized<ArPose>           robotGoal;
extern AutoSynchronized<ArPose>           robotWayPoint;

// lock/unlock must be used by the programmer
extern LockSynchronized<MagJoystickClass> robotJoystick;

#endif