Need help w/ Library error messages

I wrote a modified version of the DS1307 library and I get error messages in my sketch if I include the library, but I don't understand what's causing them. BTW I used AVR project IDE to write the libray and it compiled without errors. I'd be grateful for any help on this ;). I'm using a Mega(1280) and the Arduino IDE(0022).

These are the error messages:

In file included from C:\Program Files\arduino-0022\hardware\arduino\cores\arduino/WProgram.h:6,
from MySketch.cpp:4:
c:/program files/arduino-0022/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected unqualified-id before 'double'
c:/program files/arduino-0022/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected )' before 'double' c:/program files/arduino-0022/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected )' before 'double'

This is my sketch that's giving the error messages:

#include <Wire.h>
#include <DS1307.h>

void setup() {
  Wire.begin();
}

void loop() {
}

Here is the library's .h file:

#ifndef DS1307_h
#define DS1307_h

#include <WProgram.h>
#include <Wire.h>

enum format {
  MILITARY = 0,
  STANDARD = 1
};

enum sqwout {
  OFF = 0,
  ON = 1
};

struct hms {
  uint8_t hh;
  uint8_t mm;
  uint8_t ss;
  char ap;
} Time;

struct ddmy {
  uint8_t day;
  uint8_t date;
  uint8_t month;
  uint8_t year;
} Date;

class DS1307 {
  public:
    DS1307();
    ~DS1307();
    void Start(void);
    void Stop(void);
    void SetFormat(format timeFormat);
    void SetSQW(sqwout squareWave);
    void SetTime(void);
    void GetTime(void);
    void SetDate(void);
    void GetDate(void);
    void SetRAM(uint8_t address, uint8_t data);
    uint8_t GetRAM(uint8_t address);
  private:
    uint8_t dec_bcd(uint8_t d);
    uint8_t bcd_dec(uint8_t b);
};

extern DS1307 RTC;
#endif

Here is the library's .cpp file:

#include <WProgram.h>
#include <Wire.h>
#include "DS1307.h"

#define DS1307_ID (0x68)

DS1307::DS1307(){
}

DS1307::~DS1307(){
}

void DS1307::Stop(void){
  Wire.beginTransmission(DS1307_ID);
  Wire.send(0x00);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ID, 1);
  Time.ss = (Wire.receive() | 0x80);
  Wire.beginTransmission(DS1307_ID);
  Wire.send(0x00);
  Wire.send(Time.ss);
  Wire.endTransmission();
}

void DS1307::Start(void){
  Wire.beginTransmission(DS1307_ID);
  Wire.send(0x00);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ID, 1);
  Time.ss = (Wire.receive() & 0x7F);
  Wire.beginTransmission(DS1307_ID);
  Wire.send(0x00);
  Wire.send(Time.ss);
  Wire.endTransmission();
}

void DS1307::SetFormat(format timeFormat){
  Stop();
  Wire.beginTransmission(DS1307_ID);
  Wire.send(0x02);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ID, 1);
  Time.hh = Wire.receive();
  if (timeFormat == MILITARY){
    Time.hh |= 0x40;
  }
  else {
    Time.hh &= 0xBF;
  }
  Wire.beginTransmission(DS1307_ID);
  Wire.send(0x02);
  Wire.send(Time.hh);
  Wire.endTransmission();
  Start();
}

void DS1307::SetSQW(sqwout squareWave){
  uint8_t sqw = 0x00;
  if (squareWave == ON){
    sqw = 0x10;
  }
  Stop();
  Wire.beginTransmission(DS1307_ID);
  Wire.send(0x07);
  Wire.send(sqw);
  Wire.endTransmission();
  Start();
}

void DS1307::SetTime(void){
  Stop();
  Wire.beginTransmission(DS1307_ID);
  Wire.send(0x02);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ID, 1);
  uint8_t timeFormat = (Wire.receive() & 0x40);
  if (timeFormat) {
    uint8_t ampm = 0x40;
    if ((Time.ap == 'p') || (Time.ap == 'P')) {
      ampm = 0x60;
    }
    Wire.beginTransmission(DS1307_ID);
    Wire.send(0x00);
    Wire.send(dec_bcd(Time.ss));
    Wire.send(dec_bcd(Time.mm));
    Wire.send((dec_bcd(Time.hh)) | ampm);
    Wire.endTransmission();
  }
  else {
    Wire.beginTransmission(DS1307_ID);
    Wire.send(0x00);
    Wire.send(dec_bcd(Time.ss));
    Wire.send(dec_bcd(Time.mm));
    Wire.send(dec_bcd(Time.hh));
    Wire.endTransmission();
  }
  Start();
}

void DS1307::GetTime(void){
  Wire.beginTransmission(DS1307_ID);
  Wire.send(0x02);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ID, 1);
  uint8_t registerByte = Wire.receive();
  if (registerByte & 0x40) {
    if (registerByte & 0x20) {
      Time.ap = 'P';
    }
    else {
      Time.ap = 'A';
    }
    Wire.beginTransmission(DS1307_ID);
    Wire.send(0x00);
    Wire.endTransmission();
    Wire.requestFrom(DS1307_ID, 3);
    Time.ss = bcd_dec(Wire.receive() & 0x7F);
    Time.mm = bcd_dec(Wire.receive());
    Time.hh = bcd_dec(Wire.receive() & 0x1F);
  }
  else {
    Time.ap = '\0';
    Wire.beginTransmission(DS1307_ID);
    Wire.send(0x00);
    Wire.endTransmission();
    Wire.requestFrom(DS1307_ID, 3);
    Time.ss = bcd_dec(Wire.receive() & 0x7F);
    Time.mm = bcd_dec(Wire.receive());
    Time.hh = bcd_dec(Wire.receive());
  }
}

void DS1307::SetDate(void){
  Stop();
  Wire.beginTransmission(DS1307_ID);
  Wire.send(0x03);
  Wire.send(dec_bcd(Date.day));
  Wire.send(dec_bcd(Date.date));
  Wire.send(dec_bcd(Date.month));
  Wire.send(dec_bcd(Date.year));
  Wire.endTransmission();
  Start();
}

void DS1307::GetDate(void){
  Wire.beginTransmission(DS1307_ID);
  Wire.send(0x03);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ID, 4);
  Date.day = bcd_dec(Wire.receive());
  Date.date = bcd_dec(Wire.receive());
  Date.month = bcd_dec(Wire.receive());
  Date.year = bcd_dec(Wire.receive());
}

void DS1307::SetRAM(uint8_t address, uint8_t data){
  Wire.beginTransmission(DS1307_ID);
  Wire.send(address);
  Wire.send(data);
  Wire.endTransmission();
}

uint8_t DS1307::GetRAM(uint8_t address){
  Wire.beginTransmission(DS1307_ID);
  Wire.send(address);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ID, 1);
  uint8_t data = Wire.receive();
  return data;
}

uint8_t DS1307::dec_bcd(uint8_t d){
  return (((d / 10) * 16) + (d % 10));
}

uint8_t DS1307::bcd_dec(uint8_t b){
  return (((b / 16) * 10) + (b % 16));
}

DS1307 RTC = DS1307();

Thanks for any help,
DigitalJohnson

(part of the ) solution is in this thread - http://arduino.cc/forum/index.php/topic,71405.0.html - read carefully.

@robtillaart

Thanks for being the only person to reply to my post.8) I've read the thread you posted and the related threads in that post. I have to admit it's all a bit over my head as I am more novice than expert when it comes c/c++. :~ If I understand it right (and probably not) something in my library is conflicting with the math.h library at line 439, which is the round function. I commented out that function in the math library and tried compiling again. This time I got errors on my enumeration sqwout referencing a boolean datatype. I think my use of OFF and ON are another conflict somewhere. I think I'll go back to the drawing board and try other ways of getting what I want. When I get better at this(c/c++) I'll get back to this issue to see if I can understand whats going on.
Thanks again for your help,
DigitalJohnson

I saw a similar question today and as I recalled an earlier thread I searched and found an answer and your thread unanswered. So I posted similar answers on both threads - "Two birds with one stone" - :slight_smile:

i had the same problem with my program, it generated exactly the same error at the same line.. if i understood correctly it's some kind of error related to the microcontroller and the libraries and i didn't manage to solve the errors. :frowning: