Yoctopuce Yocto-Color Mode D'emploi page 59

Table des Matières

Publicité

Un exemple réel
Lancez votre environnement C++ et ouvrez le projet exemple correspondant, fourni dans le
répertoire Examples/Doc-GettingStarted-Yocto-Color de la librairie Yoctopuce. Si vous préférez
travailler avec votre éditeur de texte préféré, ouvrez le fichier
dans le répertoire de l'exemple pour le compiler.
make
Vous reconnaîtrez dans cet exemple l'utilisation des fonctions expliquées ci-dessus, cette fois
utilisées avec le décorum nécessaire à en faire un petit programme d'exemple concret.
#include "yocto_api.h"
#include "yocto_colorled.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace
std;
static void usage(void)
{
cout
<<
"usage: demo <serial_number>
cout
<<
"
cout
<<
"
endl;
cout
<<
"Eg."
<< endl;
cout
<<
"
demo any FF1493 "
cout
<<
"
demo YRGBLED1-123456 red"
u64
now = yGetTickCount();
while (yGetTickCount()
// wait 3 sec to show the message
}
exit(1);
}
int main(int
argc,
{
string
errmsg;
string
target;
YColorLed
*led1;
YColorLed
*led2;
string
color_str;
unsigned int
color;
if(argc <
3) {
usage();
}
target
=
(string)
color_str
=
(string)
if
(color_str ==
color = 0xFF0000;
else if (
color_str ==
color = 0x00FF00;
else if
(color_str ==
color = 0x0000FF;
else
color =
(unsigned
// Setup the API to use local USB devices
if
(yRegisterHub("usb",
cerr
<<
"RegisterHub error: "
return
1;
}
if
(target ==
"any") {
led1 =
yFirstColorLed();
if
(led1 ==
NULL) {
cout
<<
"No module connected (check USB cable)"
return
1;
}
led2 =
led1->nextColorLed();
} else {
led1 =
yFindColorLed(target + ".colorLed1");
led2 =
yFindColorLed(target + ".colorLed2");
}
if (led1->isOnline()) {
www.yoctopuce.com
demo <logical_name> [ color | rgb ]"
demo any
[ color | rgb ]
<< endl;
- now <
3000) {
const
char
*
argv[])
argv[1];
argv[2];
"red")
"green")
"blue")
int)strtoul(color_str.c_str(), NULL, 16);
errmsg)
!=
YAPI_SUCCESS) {
<< errmsg << endl;
main.cpp
[ color | rgb ]"
<< endl;
<< endl;
(use any discovered device)"
<< endl;
<< endl;
9. Utilisation du Yocto-Color en C++
, vous taperez simplement
<<
53

Publicité

Table des Matières
loading

Table des Matières