0

this is my MotorEncoder.h

#include <Encoder.h>

class MotorEncoder {
public:
    MotorEncoder(int pin1, int pin2);
    void init();
    int read();

private:
    int pin1;
    int pin2;
    Encoder encoder;
};

And this is MotorEncoder.cpp

#include "MotorEncoder.h"

MotorEncoder::MotorEncoder(int pin1, int pin2) {
    this->pin1 = pin1;
    this->pin2 = pin2;
    this->encoder = Encoder(pin1, pin2);
}

void MotorEncoder::init() {
}

int MotorEncoder::read() {
}

I get always an error stated that I call Encoder with 0 parameters.

In file included from src/encoder/MotorEncoder.h:5:0,
                 from src/encoder/MotorEncoder.cpp:1:
/Users/slawalata/.platformio/lib/Encoder_ID129/Encoder.h:72:2: note: candidate: Encoder::Encoder(uint8_t, uint8_t)
  Encoder(uint8_t pin1, uint8_t pin2) {
  ^
/Users/slawalata/.platformio/lib/Encoder_ID129/Encoder.h:72:2: note:   candidate expects 2 arguments, 0 provided

It breaks in compilation time. I haven't called this constructor at all.

Many thanks in advance.

slawalata
  • 389
  • 1
  • 2
  • 14

1 Answers1

0

Based on this link, i change my code to :

MotorEncoder.h

class MotorEncoder {

    public:
    MotorEncoder(int pin1, int pin2);

    void init();

    int read();

    private:
        int pin1;
        int pin2;
        Encoder* encoder;
};

MotorEncoder.cpp

MotorEncoder::MotorEncoder(int pin1, int pin2) {
    this->pin1 = pin1;
    this->pin2 = pin2;
    this->encoder = new ::Encoder(pin1, pin2);
}

void MotorEncoder::init() {
}

int MotorEncoder::read() {
    return encoder->read();
}

Many thanks,

slawalata
  • 389
  • 1
  • 2
  • 14