2016-09-11 26 views
0

私はC++の初心者ですが、私のarduinoではこのコードが必要です。 arduinoの下位バージョン用にコンパイルと作業をしています。 arduino-1.6.5.r5。 1.6.9以降、arduino(1.6.11)の最新版でさえ、この宣言はもはやコンパイルされていません。 私はこのエラーを完全に理解していません。別の方法で書き直すことはできますか? CallBack.hライブラリを使用しています。宣言関数ポインタC++ arduino 1.6.11

ライブラリのソース: https://bitbucket.org/ehsmaes/cmdcallback/wiki/Home

例ライブラリ `

#include <CallBack.h> 
// Compile and upload to arduino. Run the serial monitor and type command 
// :help; 
// Values for initiation of cmd/response interface. 
// After initial boot, id, gid and del are stored in eeprom. 
// Change values by command. Make sure each device has a unique id. 
String descr="Command/response test program v0.1"; 
String id="a1"; 
String gid="a"; 
int del=0; //delayed response 

// List of commands defined by keyword, funtion pointer, number of arguments 
// and description used in "help" command. 
CallBackDef f[] = { 
    {(String)"add", (FunctionPointer)&add, (int)2, (String)":num1:num2"} 
}; 

// initiate command handler: function array, number of functions and intial values 
CallBack cmd(f, sizeof(f)/sizeof(*f), id, gid, descr, del); 

void setup() { 
    Serial.begin(9600); 
    cmd.ok(); // say hello 
} 

void loop() { 
    // Put code here. Use timers instead of delay if possible as not to disrupt 
    // command/response interaction with host 
} 

void serialEvent() { 
    // Don't forget this line. Parse command if serial data is available. 
    cmd.cmdCheck(); 
} 

// --------- command initiated callback functions below --------- 
// callback functions all need to be defined void and with String argv 
// argument list. The command parser will validate the number of input 
// parameters but any additional validation has to be perfomed by each 
// callback function. As the argument list is passed as strings, type 
// casting to other types is the responsibility of the function. 


void add(String argv[]) { 
    int a = cmd.stoi(argv[0]); 
    int b = cmd.stoi(argv[1]); 
    cmd.respond(String(a + b)); 
} 

`

CmdCallBack_example_minimum:17: error: 'add' was not declared in this scope 
    {(String)"add", (FunctionPointer)&add, (int)2, (String)":num1:num2"} 
            ^
Using library CmdCallBack in folder: /Users/adrian/ownCloud/Arduino/libraries/CmdCallBack (legacy) 
exit status 1 
'add' was not declared in this scope 
+0

(...コールバックCMDの一部の不正なパラメータの型)にもその修正後に壊れている(basevent、baseheat、XDVを、PIDなどをVVV) –

+0

より具体的な回答を得るには、[MCVE](http://stackoverflow.com/help/mcve) –

+0

を投稿してください。私はこのライブラリをそのまま使用するので、私はコードを完全に理解していません。私は今、私の目的を果たしています。 Pid、vvvなどは、コンピュータからarduinoへシリアル経由で送られるコマンドです。私はCallBackdef [] – busymind

答えて

0

からこのエラーは、機能baseeventCallBackDef f[] = ...前に宣言されなかったことを意味します。関数プロトタイプが使用される前に、関数定義(=使用前に完全な関数)が必要です。

Arduinoには別のプリプロセッサもあります。これはこれらの定義を扱い、スケッチの開始点のどこかに置きます。しかし、より複雑なものは通常は破壊されます(生成されたプロトタイプは完全に間違っています)。したがって、法的なC++コードでさえもコンパイルできません。 Arduinoのバージョン間で動作が変更されることもあります。

例CmdCallBack_example_minimumあなたは関数のプロトタイプを追加した場合、1.6.9ではデフォルトで作業していないが、明示的な関数プロトタイプArduinoのプリプロセッサなし

#include <CallBack.h> 

// Compile and upload to arduino. Run the serial monitor and type command 
// :help; 

// Values for initiation of cmd/response interface. 
// After initial boot, id, gid and del are stored in eeprom. 
// Change values by command. Make sure each device has a unique id. 
String descr="Command/response test program v0.1"; 
String id="a1"; 
String gid="a"; 
int del=0; //delayed response 
byte echo=1; // command back to host 

// ------------------------------------------------ 
// Function Prototype for add: 
void add(String argv[]); 

// List of commands defined by keyword, funtion pointer, number of arguments 
// and description used in "help" command. 
CallBackDef f[] = { 
    {(String)"add", (FunctionPointer)&add, (int)2, (String)":num1:num2"} 
}; 

// initiate command handler: function array, number of functions and intial values 
CallBack cmd(f, sizeof(f)/sizeof(*f), id, gid, descr, del, echo); 

void setup() { 
    Serial.begin(9600); 
    cmd.ok(); // say hello 
} 

void loop() { 
    // Don't forget this line. Parse command if serial data is available. 
    cmd.cmdCheck(); 

    // Put code here. Use timers instead of delay if possible as not to disrupt 
    // command/response interaction with host 


} 

// --------- command initiated callback functions below --------- 
// callback functions all need to be defined void and with String argv 
// argument list. The command parser will validate the number of input 
// parameters but any additional validation has to be perfomed by each 
// callback function. As the argument list is passed as strings, type 
// casting to other types is the responsibility of the function. 

void add(String argv[]) { 
    int a = cmd.stoi(argv[0]); 
    int b = cmd.stoi(argv[1]); 
    cmd.respond(String(a + b)); 
} 

はそれの世話をするが、それはそれの行の後に挿入されます使用されている。だからまだエラーがあります。

あなたのバージョンはしかし、あなたはそれらのもののための宣言を提供する必要が

+0

関数プロトタイプはどのようなものですか?この場合、関数は参照引数をとります(先行する&) – busymind

+0

いいえ、それは関数プロトタイプではありません。見て[ここをクリック](http://www.cplusplus.com/forum/beginner/22038/) – KIIV

+0

Tank you KIIV。ヘルプと情報を感謝します。 – busymind