spigotx / Moodlite

Moodlite
GNU General Public License v3.0
109 stars 17 forks source link

invalid use of member function #17

Closed FlyingT closed 4 years ago

FlyingT commented 5 years ago

I followed the setup step-by-step and reinstalled everything freshly, but I'am stuck at this error:

Arduino: 1.8.9 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

In file included from E:\3D Drucker\moodlite v2\Moodlite Software_2019_04_28_V3.0\Arduino\Moodlite\Moodlite.ino:31:0:

C:\Users\Tim\Documents\Arduino\libraries\FastLED/FastLED.h:14:21: note: #pragma message: FastLED version 3.002.010

 #    pragma message "FastLED version 3.002.010"

                     ^

In file included from C:\Users\Tim\Documents\Arduino\libraries\FastLED/FastLED.h:65:0,

                 from E:\3D Drucker\moodlite v2\Moodlite Software_2019_04_28_V3.0\Arduino\Moodlite\Moodlite.ino:31:

C:\Users\Tim\Documents\Arduino\libraries\FastLED/fastspi.h:115:23: note: #pragma message: No hardware SPI pins defined.  All SPI access will default to bitbanged output

 #      pragma message "No hardware SPI pins defined.  All SPI access will default to bitbanged output"

                       ^

E:\3D Drucker\moodlite v2\Moodlite Software_2019_04_28_V3.0\Arduino\Moodlite\Moodlite.ino: In member function 'String& ByteString::copy(const void*, unsigned int)':

Moodlite:419:7: error: invalid use of member function (did you forget the '()' ?)

   len = length;

       ^

Moodlite:420:30: error: cannot convert 'String::buffer' from type 'const char* (String::)()const' to type 'void*'

   memcpy(buffer, data, length);

                              ^

Moodlite:421:16: error: invalid types '<unresolved overloaded function type>[unsigned int]' for array subscript

   buffer[length] = 0;

                ^

exit status 1
invalid use of member function (did you forget the '()' ?)
Deca commented 5 years ago

Same error for me, do you managed to solve it?

FlyingT commented 5 years ago

Same error for me, do you managed to solve it?

Nope, I think this project is dead I used an older version which compiled fine

matty337s commented 5 years ago

I also have this issue. Would love to know a fix, as this is an awesome project, but my coding is not quite up to this standard.

spigotx commented 5 years ago

Hi. Sorry for the late response, but I'm having difficulties to find spare time. The project is not dead. You can always ask in forum: I'm having difficulties to find spare time.

You can solve the problem by removing this part:

class ByteString : public String {
public:
    ByteString(void *data, size_t len) :
        String() {
        copy(data, len);
    }

    ByteString() :
        String() {
    }

    String& copy(const void *data, unsigned int length) {
        if (!reserve(length)) {
            invalidate();
            return (*this);
        }
        len = length;
        memcpy(buffer, data, length);
        buffer[length] = 0;
        return (*this);
    }
};

// Asynchronous TCP Client to retrieve data/time
struct AsyncHTTPClient {
    AsyncClient *aClient = NULL;

    bool         initialized = false;
    String       protocol;
    String       base64Authorization;
    String       host;
    int          port;
    String       uri;
    String       request;

    ByteString   response;
    int          statusCode;
    void(*onSuccess)();
    void(*onFail)(String);

    void initialize(String url) {
        // check for : (http: or https:
        int index = url.indexOf(':');

        if (index < 0) {
            initialized = false;                    // This is not a URLs
        }

        protocol = url.substring(0, index);
        DEBUGLN(protocol);
        url.remove(0, (index + 3));                 // remove http:// or https://

        index = url.indexOf('/');
        String hostPart = url.substring(0, index);
        DEBUGLN(hostPart);
        url.remove(0, index);                       // remove hostPart part

        // get Authorization
        index = hostPart.indexOf('@');

        if (index >= 0) {
            // auth info
            String auth = hostPart.substring(0, index);
            hostPart.remove(0, index + 1);                // remove auth part including @
            base64Authorization = base64::encode(auth);
        }

        // get port
        port = 80;                               //Default
        index = hostPart.indexOf(':');
        if (index >= 0) {
            host = hostPart.substring(0, index); // hostname
            host.remove(0, (index + 1));         // remove hostname + :
            DEBUGLN(host);
            port = host.toInt();                 // get port
            DEBUGLN(port);
        }
        else {
            host = hostPart;
            DEBUGLN(host);
        }
        uri = url;
        if (protocol != "http") {
            initialized = false;
        }

        DEBUGLN(initialized);
        request = "GET " + uri + " HTTP/1.1\r\nHost: " + host + "\r\n\r\n";

        DEBUGLN(request);
        initialized = true;
    }

    int getStatusCode() {
        return (statusCode);
    }

    String getBody() {
        if (statusCode == 200) {
            int bodyStart = response.indexOf("\r\n\r\n") + 4;
            return (response.substring(bodyStart));
        }
        else {
            return ("");
        }
    }

    static void clientError(void *arg, AsyncClient *client, int error) {
        DEBUGLN("Connect Error");
        AsyncHTTPClient *self = (AsyncHTTPClient *)arg;
        self->onFail("Connection error");
        self->aClient = NULL;
        delete client;
    }

    static void clientDisconnect(void *arg, AsyncClient *client) {
        DEBUGLN("Disconnected");
        AsyncHTTPClient *self = (AsyncHTTPClient *)arg;
        self->aClient = NULL;
        delete client;
    }

    static void clientData(void *arg, AsyncClient *client, void *data, size_t len) {
        DEBUGLN("Got response");

        AsyncHTTPClient *self = (AsyncHTTPClient *)arg;
        self->response = ByteString(data, len);
        String status = self->response.substring(9, 12);
        self->statusCode = atoi(status.c_str());
        DEBUGLN(status.c_str());

        if (self->statusCode == 200) {
            self->onSuccess();
        }
        else {
            self->onFail("Failed with code " + status);
        }
    }

    static void clientConnect(void *arg, AsyncClient *client) {
        DEBUGLN("Connected");

        AsyncHTTPClient *self = (AsyncHTTPClient *)arg;

        self->response.copy("", 0);
        self->statusCode = -1;

        // Clear oneError handler
        self->aClient->onError(NULL, NULL);

        // Set disconnect handler
        client->onDisconnect(clientDisconnect, self);

        client->onData(clientData, self);

        //send the request
        client->write(self->request.c_str());
    }

    void makeRequest(void(*success)(), void(*fail)(String msg)) {
        onFail = fail;

        if (!initialized) {
            fail("Not initialized");
            return;
        }

        if (aClient) {           //client already exists
            fail("Call taking forever");
            return;
        }

        aClient = new AsyncClient();

        if (!aClient) {           //could not allocate client
            fail("Out of memory");
            return;
        }

        onSuccess = success;

        aClient->onError(clientError, this);

        aClient->onConnect(clientConnect, this);

        if (!aClient->connect(host.c_str(), port)) {
            DEBUGLN("Connect Fail");
            fail("Connection failed");
            AsyncClient *client = aClient;
            aClient = NULL;
            delete client;
        }
    }
};

AsyncHTTPClient httpClient;

It's no longer needed.

spigotx commented 4 years ago

Removed obsolete code. It should compile fine now.