anyKode Marilou
ContentsIndexHome
PreviousUpNext
DevicesGroupTouchArea

Le groupe de devices 'TouchArea' permet de parallÚliser la commande de plusieurs DeviceTouchArea.

C++
class DevicesGroupTouchArea : public DevicesGroup;

ModaCpp.h

//Code from Samples/Devices/TouchArea sample
#include "Modacpp.h"
#include "World.h"
#include "conio.h"

using namespace Moda;

#define MODASERVER "localhost"

//////////////////////////////////////////////////////////////////////////////////////
//This sample is using the generated World.cpp class (made by Class Creator)
//You can connect directly to touch area devices without using this generated class:
//RobotPHX *pWorld=pConnection->QueryRobotPHX("/");
//DeviceTouchArea *pButton1=pWorld->QueryDeviceTouchArea("sphere0/touchopen");
//DeviceTouchArea *pButton2=pWorld->QueryDeviceTouchArea("sphere0/touchclose");
// ...
//Using groups:
//
//DevicesGroupTouchArea group;
group.AddDevice(pButton1);
group.AddDevice(pButton2);
//////////////////////////////////////////////////////////////////////////////////////


/////////////// USING TOUCH AREA WITH GROUP /////////////////////////////////
int main(int argc, char* argv[])
{
ModaCPP::Connection *pConnection=new ModaCPP::Connection(true);
//Try connect to MODA server
if(pConnection->Connect(MODASERVER))
    {
    _cprintf("Connection ok to moda server\r\n");
    //Find the robot
    World *pWorld=pConnection->QueryRobotPHX2<World>("/");
    if(pWorld && pWorld->IsValid())
        {
        _cprintf("World found\r\n");

        //get devices from cache
        DeviceServoMotor *pServo=pWorld->GetServoMotorByIndex(0);

        DevicesGroupTouchArea *pGroup=pWorld->GetTouchAreasGroup();
        Moda::Commons::TouchAreaState States[2];

        while(!_kbhit())
            {
            if(pGroup->GetAreasState(States,2)==MODA_EOK)
                {
                //is the button 1 pressed (green button) ?
                if(States[0].bPressed)
                    {
                    //move to 90░ (open)
                    pServo->GoPositionDeg(90,15);
                    }
                else
                    {
                    //is the button 2 pressed (red button) ?
                    if(States[1].bPressed)
                        {
                        //move to 0░ (close)
                        pServo->GoPositionDeg(0,15);
                        }
                    }
                }
            else
                {
                _cprintf("an error occured: %d\r\n",pGroup->GetLastSystemError());
                }
            //next iteration
            pConnection->Sleep(20);
            }
        delete pWorld;
        }
    else
        {
        _cprintf("World not found or was invalid\r\n");
        }
    }
else
    {
    _cprintf("Unable to connect to moda server\r\n");
    }
//Disconnect & delete
pConnection->Disconnect();
delete pConnection;
_getch();
return 0;
}
Documentation v4.7 (18/01/2015), Copyright (c) 2015 anyKode. All rights reserved.
What do you think about this topic? Send feedback!