ESP8266WebServer::on(const char [6], <unresolved overloaded function type>)' 的问题

Problem with, ESP8266WebServer::on(const char [6], <unresolved overloaded function type>)'

我正在学习如何在 C++ 中使用 'class',当我试图从我的 class 调用一个函数时,我收到了这个错误:

错误 C:\Users\Mateus\Documents\ArduinoData\packages\esp8266\hardware\esp8266.5.0\libraries\ESP8266WebServer\src/ESP8266WebServer.h:90:8: 注意:void ESP8266WebServer::on(const String&, HTTPMethod, ESP8266WebServer::THandlerFunction, ESP8266WebServer::THandlerFunction)

void on(const String &uri, HTTPMethod 方法, THandlerFunction fn, THandlerFunction ufn);

    ^

C:\Users\Mateus\Documents\ArduinoData\packages\esp8266\hardware\esp8266.5.0\libraries\ESP8266WebServer\src/ESP8266WebServer.h:90:8:注意:候选人需要 4 个参数,提供 2 个

退出状态 1 没有匹配函数调用 'ESP8266WebServer::on(const char [6], )'

我的代码:

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

ESP8266WebServer server;
class Light {
  public:
      int InPin;
      int OutPin;
      Light(int aInPin, int aOutPin){
          InPin = aInPin;
          OutPin = aOutPin;
      }
      void setPin() {
          pinMode(InPin, INPUT_PULLUP);
          pinMode(OutPin, OUTPUT);
      }
      void toggleLight()
      {
        digitalWrite(InPin,!digitalRead(InPin));
        String lstate = digitalRead(InPin) ? "Status: ON" : "Status: OFF";
        server.send(200,"text/html", lstate);
      }
};


char* ssid = "MaIs2";
char* password = "3134767570";

const char index_html[] PROGMEM ={"HUGE html string"};

const char style_css[] PROGMEM = {"HUGE css string"};

int Door = 4;
int BDoor = 14;
Light l1(0, 16);
Light l2(2, 5);

void setup()
{
    WiFi.begin(ssid,password);
    Serial.begin(9600);
    while(WiFi.status()!=WL_CONNECTED)
    {
      Serial.print(".");
      delay(500);
    }
    Serial.println("");
    Serial.print("IP Address: ");
    Serial.println(WiFi.localIP());
    l1.setPin();
    l2.setPin();
    server.on("/",[](){server.send_P(200,"text/html",index_html);});
    server.on("/style.css", handleCss);
    server.on("/Lg1", l1.toggleLight); //ERROR HERE
    server.on("/Lg2", l2.toggleLight); //ERROR HERE
    server.on("/Door",TDoor);
    server.on("/Doorpulse", PDoor);
    server.begin();


}

void handleCss(){
  server.send_P(200, "text/css", style_css);
}

void loop()
{
  server.handleClient();
  if(digitalRead(l1.InPin) == LOW){
    l1.toggleLight();
    delay(1000);
  }
  if(digitalRead(l2.InPin) == LOW){
    l2.toggleLight();
    delay(1000);
  }
    if(digitalRead(Bdoor) == LOW){
    Tdoor();
    delay(1000);
  }
}

void PDoor()
{
  digitalWrite(Door, HIGH);
  delay(5000);
  digitalWrite(Door, LOW);
}
void TDoor(){
  digitalWrite(Door,!digitalRead(Door));
  String doorstate = digitalRead(Door) ? "Status: Unlocked" : "Status: Locked";
  server.send(200,"text/html", doorstate);
}

看起来您需要一个 lambda 函数,类似于您之前的示例

server.on("/Lg1", [](){ l1.toggleLight(); });