无法转换' MyClass :: capDischarged'来自类型' void(MyClass ::)()'输入' void(*)()'

时间:2017-05-06 16:12:59

标签: c++ arduino type-conversion interrupt esp8266

我看到非常类似的问题得到了很多回答,但没有一点符合我的具体情况。当我尝试编程微处理器(ESP8266 - 使用Arduino IDE)时,我不会处理线程。我的软件工作得很好,直到我试图将代码块转换成库,因此我可以更容易地重用它。现在它不会编译。

代码的相关部分:

float HydroMonitorECSensor::getEC(float temp) {

    // Lots of code removed.

    attachInterrupt(digitalPinToInterrupt(capPos), HydroMonitorECSensor::capDischarged, FALLING);
    WRITE_PERI_REG (GPIO_SET_OUTPUT_LOW, (1<<ECpin));
    pinMode (ECpin, OUTPUT); 

    // Use cycle counts and an interrupt to get a much more precise time measurement, especially for high-EC situations.
    startCycle = ESP.getCycleCount();
    while (endCycle == 0) {
      if (millis() > (startTime + timeout)) break;
      yield();
    }
    detachInterrupt(digitalPinToInterrupt(capPos));

    // Lots more code removed.
}

// Upon interrupt: register the cycle count of when the cap has discharged.
void ICACHE_RAM_ATTR HydroMonitorECSensor::capDischarged() {
  endCycle = ESP.getCycleCount();
}

随附的.h文件中的相关声明(删除了许多其他声明):

class HydroMonitorECSensor
{
  // user-accessible "public" interface
  public:
    HydroMonitorECSensor(); // The constructor.
    float getEC(float); // Measures the EC value, takes the water temperature as input, returns the result.


  // library-accessible "private" interface
  private:
    void capDischarged(void);
};

我见过的大部分答案都与pthreads有关,这与微处理器无关 - 它是单线程的,仅限于非常基本的协作式多任务处理。

一个非常重要的部分是ICACHE_RAM_ATTR语句,因为这可以确保中断处理程序始终保存在RAM中。如果不是,就会发生崩溃。

0 个答案:

没有答案