Pages: [1]   Go Down
Author Topic: undefined reference to function from my library  (Read 1358 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I'm trying to write my own MIDI library for the Arduino.
Now I seem to have com across a strange problem. Apparently I'm able to call the begin() method of my object, but when I try to call read() I get an error telling me there is no reference to that method...

o: In function `loop':
E:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build52696.tmp/Temporary_8968_8700.cpp:17: undefined reference to `MIDI::read()'


Basically I can call methods that don't return anything, but I can't call methods with a return value.

code:
MIDI.h:
Code:
#ifndef MIDI_h
#define MIDI_h

#include "WConstants.h"

struct Midimsg {
      byte status;
      byte data1;
      byte data2;
};

class MIDI {
      public:
            MIDI();
            void begin();
            bool read();
            void send(byte status, byte data1, byte data2);
            void send(byte status, byte data1);
            void send(byte status);
            byte getStatus();
            byte getData1();
            byte getData2();
            byte getChannelFromStatus(byte status);
            int getMessageSize(byte status);
      private:
            Midimsg msg;
            byte getNextByte();
            void clearMessage();
};

#endif

MIDI.cpp:
Code:
#include "WProgram.h"

#include "MIDI.h"
#include "HardwareSerial.h"

MIDI::MIDI() { }

void MIDI::begin() {
      Serial.begin(31250);
}

bool MIDI::read() {
      clearMessage();
      if (Serial.available() > 0) {
            byte sts = Serial.read();
            int size = getMessageSize(sts);
            switch (format) {
                  case 1: {
                        msg.status = sts;
                        msg.data1 = 0;
                        msg.data2 = 0;
                  }
                  return true;
                  
                  case 2: {
                        byte dat1 = getNextByte();
                        if (dat1 != -1) {
                              msg.status = sts;
                              msg.data1 = dat1;
                              msg.data2 = 0;
                        }
                  }
                  return true;
                  
                  case 3: {
                        byte dat1 = getNextByte();
                        if (dat1 != -1) {
                              byte dat2 = getNextByte();
                              if (dat2 != -1) {
                                    msg.status = sts;
                                    msg.data1 = dat1;
                                    msg.data2 = dat2;
                              }
                        }
                  }
                  return true;
                  
                  case -1:
                  return false; // invalid status byte
            }
      }
      else {
            return false;
      }
      return false;
}

void MIDI::send(byte status, byte data1, byte data2) {
      Serial.print(status, BYTE);
      Serial.print(data1, BYTE);
      Serial.print(data2, BYTE);
}

void MIDI::send(byte status, byte data1) {
      Serial.print(status, BYTE);
      Serial.print(data1, BYTE);
}

void MIDI::send(byte status) {
      Serial.print(status, BYTE);
}

byte MIDI::getStatus() {
      return msg.status;
}

byte MIDI::getData1() {
      return msg.data1;
}

byte MIDI::getData2() {
      return msg.data2;
}

byte MIDI::getChannelFromStatus(byte status) {
      return (status & 0x0F);
}

int MIDI::getMessageSize(byte status) {
      if (status > 0xF5) { // 1 byte msg
            return 1;
      }
      else if ((status > 0xC0 && status < 0xE0) || (status == 0xF3)) { // 2 byte msg
            return 2;
      }
      else if ((status > 0x7F && status < 0xC0) || (status > 0xDF && status < 0xF0)) { // 3 byte msg
            return 3;
      }
      else {
            return -1; // invalid/unsupported message
      }
}

byte MIDI::getNextByte() {
      int i = 3;
      while ((Serial.available() < 1) && (i > 0)) { // wait for the 2nd byte if it isn't already available
            delayMicroseconds(10);
            i--;
      }
      return Serial.read();
}

void MIDI::clearMessage() {
      msg.status = 0;
      msg.data1 = 0;
      msg.data2 = 0;
}

I'm using version 0015 and experienced the same problem with v0013.

Great thanks in advance.
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 13
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I suspect that deleting MIDI.o and then recompile will solve your problem?
Logged

Connecticut, US
Offline Offline
Edison Member
*
Karma: 2
Posts: 1036
Whatduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Since the error's in your loop(), let's see your loop().
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I suspect that deleting MIDI.o and then recompile will solve your problem?

Thank you very much!!!
Copied the directory around one to many incorrect times  smiley-grin
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 13
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Thank you very much!!!
Copied the directory around one to many incorrect times  smiley-grin

I've spent too much time banging my head because of the exact same thing. smiley-sad

Glad it solved your problem smiley
Logged

Pages: [1]   Go Up
Jump to: