静的に定義しない限り、関数を期待する関数にメソッドを渡すことはできません。
静的に書きます:
static void velocity::functionISR_name()
と
attachInterrupt(&velocity::functionISR_name);
残念ながら、静的メソッドは特定のインスタンスにバインドされなくなりました。シングルトンと一緒にのみ使用してください。Arduino では、抜粋したコードで以下に示すようなクラスを作成する必要があります。
class velocity
{
static velocity *pThisSingelton;
public:
velocity()
{
pThisSingelton=this;
}
static void functionISR_name()
{
pThisSingelton->CallWhatEverMethodYouNeeded();
// Do whatever needed.
}
// … Your methods
};
velocity *velocity::pThisSingelton;
velocity YourOneAndOnlyInstanceOfThisClass;
void setup()
{
attachInterrupt(&velocity::functionISR_name);
// …other stuff…
}
これは見栄えが悪いですが、私の意見では、このようなシステムでは機会が非常に限られているため、Arduino ではまったく問題ありません。
もう一度考えてみると、私は個人的に、ソリンが上記の回答で言及したアプローチを採用します。それはもっと似ているでしょう:
class velocity
{
public:
velocity()
{
}
static void functionISR_name()
{
// Do whatever needed.
}
// … Your methods
};
velocity YourOneAndOnlyInstanceOfThisClass;
void functionISR_name_delegation()
{
YourOneAndOnlyInstanceOfThisClass.functionISR_name();
}
void setup()
{
attachInterrupt(functionISR_name_delegation);
// …other stuff…
}
また、最初の例で必要なポインター用に数バイト節約できます。
サイト ノートとして: 将来のために、正確なコードを投稿し (たとえば、attachInterrupt にはより多くのパラメーターが必要)、エラー メッセージをコピーして貼り付けてください。通常、エラーはあなたが疑わない場所で正確です。この質問は例外でした。通常、私と他の人はより良い仕様を求めます。