anyKode Marilou
ContentsIndexHome
PreviousUpNext
DeviceLCD

Gestion du LCD.

C++
class DeviceLCD : public Device;

ModaCpp.h

La classe DeviceLCD ne dois pas être instanciée par le programme lui même: elle doit être obtenue par QueryDeviceLCD de la classe RobotPHX

 

Comment créer cet équipement ? 

//Sample from Samples/Devices/LCD
#include "Modacpp.h"
#include "conio.h"

#define DEFAULT_MODASERVER    "localhost"
#define DEFAULT_PHXNAME    "/"

using namespace ModaCPP;

//************************************************************************
//Creates a ModaCPP::Image from your desktop
void CreateDesktopImage(ModaCPP::Image &image,int lcdwidth,int lcdheight)
    {
    int dx=GetSystemMetrics(SM_CXSCREEN);
    int dy=GetSystemMetrics(SM_CYSCREEN);
    HDC hdcecr=GetDC(NULL);
    HDC hdctemp=CreateCompatibleDC(hdcecr);

    HBITMAP hb=CreateCompatibleBitmap(hdcecr,lcdwidth,lcdheight);
    SelectObject(hdctemp,hb);

    SetStretchBltMode(hdctemp,COLORONCOLOR);

    StretchBlt(hdctemp,0,0,lcdwidth,lcdheight,hdcecr,0,0,dx,dy,SRCCOPY);

    BITMAPINFO b;
    image.FillImageBitmapInfo(&b);
    GetDIBits(hdctemp,hb,0,lcdheight,image.GetImageBits(),&b,DIB_RGB_COLORS);

    DeleteObject(hb);
    DeleteDC(hdctemp);
    ReleaseDC(NULL,hdcecr);
    }

int x=0;
int y=0;
int sensx=1;
int sensy=1;

//************************************************************************
void DoLCD(DeviceLCD *pLCD0,DeviceLCD *pLCD1,DeviceCamera *pCamera)
{
SurfaceInformation information0;
SurfaceInformation information1;

//retrieve surfaces information
if( (pLCD0->GetSurfaceFormat(&information0)==MODA_EOK) && (pLCD1->GetSurfaceFormat(&information1)==MODA_EOK))
    {
    _cprintf("LCD0 format: width:%d height%d format:%d\r\n",information0.Width,information0.Height,information0.Format);
    _cprintf("LCD1 format: width:%d height%d format:%d\r\n",information0.Width,information0.Height,information0.Format);
    pLCD0->Clear();
    pLCD1->Clear();

    ModaCPP::Image image0;
    ModaCPP::Image imagecamera;
    image0.Construct(information0.Width,information0.Height,Marilou::Commons::X8R8G8B8,false);

    //display images on LDCs
    while(!_kbhit())
        {
        //display desktop image
        CreateDesktopImage(image0,information0.Width,information0.Height);
        pLCD0->DrawImageBits(0,0,&image0);

        //get image from camera then write it on LCD
        if(pCamera->GetNextImage(&imagecamera) && imagecamera.IsValid())
            {
            imagecamera.DoHorizontalFlip();
            pLCD1->DrawImageBits(x,y,&imagecamera);

            if( (x>=(int)information1.Width) || (x<0)) sensx=-sensx;
            if( (y>=(int)information1.Height) || (y<0)) sensy=-sensy;

            x+=2*sensx;
            y+=4*sensy;
            }
        pLCD0->GetRobot()->GetConnection()->Sleep(10);
        }
    }
else
    {
    _cprintf("unable to get surface information\r\n");
    }

}

//************************************************************************
int main(int argc, char* argv[])
{
//take a look at commandline aruments:
// /server:[my server ip]
// /robot:/myrobot
CommandLine::ProcessCommandLine(argc,argv);

xkode::lib::String Server;
xkode::lib::String Phx;

if(CommandLine::ExistsValue("/server"))    Server=CommandLine::GetArgumentValue("/server");
else                                    Server=DEFAULT_MODASERVER;

if(CommandLine::ExistsValue("/robot"))    Phx=CommandLine::GetArgumentValue("/robot");
else                                    Phx=DEFAULT_PHXNAME;

//Try connect to MODA server
ModaCPP::Connection *connection=new ModaCPP::Connection(true);
if(connection->Connect(Server))
    {
    _cprintf("Connection ok to moda server\r\n");
    //Find the robot/world
    ModaCPP::RobotPHX *phx=connection->QueryRobotPHX(Phx);
    if(phx)
        {
        //query devices
        DeviceLCD *pLCD0=phx->QueryDeviceLCD("plane/lcd");
        DeviceLCD *pLCD1=phx->QueryDeviceLCD("plane2/lcd");
        DeviceCamera *pCamera=phx->QueryDeviceCamera("viewpoint0/cam");

        if(pCamera && pLCD0 && pLCD1)
            {
            //all devices found !
            DoLCD(pLCD0,pLCD1,pCamera);
            delete pLCD0;
            delete pLCD1;
            delete pCamera;
            }
        else
            {
            _cprintf("lcd 'plane/lcd' and/or 'plane2/lcd' and/or 'viewpoint0/cam' not found\r\n");
            }
        delete phx;
        }
    else
        {
        _cprintf("phx %s not found\r\n",Phx.GetData());
        }
    }
else
    {
    _cprintf("Unable to connect to moda server\r\n");
    }
//Disconnect & delete
connection->Disconnect();
delete connection;
_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!