Loading...
Pages: [1]   Go Down
Author Topic: {Need help} Error Compiling  (Read 278 times)
0 Members and 1 Guest are viewing this topic.
surabaya
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried to upload code to the Arduino Mega ADK but always come out a warning "error compiling". Is there something wrong with the code? How do I fix this?

the code :
Code:

#include <inttypes.h>
#include <avr/pgmspace.h>

//#include <Spi.h>
#include <Max3421e.h>
#include <Max3421e_constants.h>
#include <Max_LCD.h>
#include <Usb.h>

#include <ptp.h>
#include <canoneos.h>


#define DEV_ADDR        1

// Canon EOS 400D
#define DATA_IN_EP      1
#define DATA_OUT_EP     2
#define INTERRUPT_EP    3
#define CONFIG_NUM      1


#define SerPri  Serial.print
#define SerPriln Serial.println
#define SerAva  Serial.available
#define SerRea  Serial.read

uint16_t x;

class CamStateHandlers : public PTPStateHandlers
{
      bool stateConnected;
   
public:
      CamStateHandlers() : stateConnected(false) {};
     
      virtual void OnDeviceDisconnectedState(PTP *ptp);
      virtual void OnDeviceInitializedState(PTP *ptp);
} CamStates;

CanonEOS  Eos(DEV_ADDR, DATA_IN_EP, DATA_OUT_EP, INTERRUPT_EP, CONFIG_NUM, &CamStates);

void CamStateHandlers::OnDeviceDisconnectedState(PTP *ptp)
{
    if (stateConnected)
    {
        stateConnected = false;
        Notify(PSTR("Camera disconnected\r\n"));
    }
}

void CamStateHandlers::OnDeviceInitializedState(PTP *ptp)
{
    if (!stateConnected)
        stateConnected = true;

    while(stateConnected){
      //Serial.println("Reading");
      //delay(1000);
      readSerialCommand();
     
    }

   
   // if (rc != PTP_RC_OK)
     //   Message(PSTR("Error: "), rc);
   
    delay(5000);
}

void setup()
{
  Serial.begin( 115200 );
  Serial.println("Start");
  Eos.Setup();
  delay( 200 );
}

void loop()
{
    Eos.Task();
   
}

void readSerialCommand() {
  char queryType;
  if (SerAva()) {
    queryType = SerRea();
    switch (queryType) {
   
    case 'C': //Capture!!!
      Serial.println("Capture!");
      Eos.Capture();
      delay(500);
      break;
     
   
    case 'O': //ViewFinder Output. 1 = LCD. 2 = AV.
      //Eos.SetDevicePropValue(EOS_DPC_CameraOutput, (uint16_t)readFloatSerial());
      delay(1000);
      break;
   
    case 'V': //Liveview ON/OFF
      if((uint16_t)readFloatSerial() == 0){
        Eos.SwitchLiveView(false);
        Serial.println("Live View OFF!");
      }
      else {
        Eos.SwitchLiveView(true);
        Serial.println("Live View ON!");
      }
      delay(1000);
      break;
    case 'I': //Set Iso
      Eos.SetProperty(EOS_DPC_Iso, (uint16_t)readFloatSerial());
      delay(1000);
       Serial.println("ISO Changed!");
      break;
    case 'S': //Set ShutterSpeed
      Eos.SetProperty(EOS_DPC_ShutterSpeed, (uint16_t)readFloatSerial());
      delay(1000);
       Serial.println("Shutter Speed Changed!");
      break;
    case 'W': //Set Whitebalance
      Eos.SetProperty(EOS_DPC_WhiteBalance, (uint16_t)readFloatSerial());
      delay(1000);
      Serial.println("White Balance Changed!");
      break;
    case 'A': //Set Aperture
      Eos.SetProperty(EOS_DPC_Aperture, (uint16_t)readFloatSerial());
      delay(1000);
       Serial.println("Aperture value Changed!");
      break;
     
     
     
      case 'F': //MoveFocus
       
      Eos.MoveFocus(3);
     
      break;
     
      case 'B': //MoveFocus
     
       
      Eos.MoveFocus(0x8003);
     
      break;
     
    }
  }
}


float readFloatSerial() {
  byte index = 0;
  byte timeout = 0;
  char data[128] = "";

  do {
    if (SerAva() == 0) {
      delay(10);
      timeout++;
    }
    else {
      data[index] = SerRea();
      timeout = 0;
      index++;
    }
  } 
  while ((data[constrain(index-1, 0, 128)] != ';') && (timeout < 5) && (index < 128));
  return atof(data);
}
 

error message :
Code:
core.a(main.cpp.o): In function `main':
D:\arduino-1.0.1\hardware\arduino\cores\arduino/main.cpp:5: undefined reference to `setup'
D:\arduino-1.0.1\hardware\arduino\cores\arduino/main.cpp:15: undefined reference to `loop'

Thanks any help would be great
Logged

North Queensland, Australia
Online Online
Edison Member
*
Karma: 31
Posts: 1188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not to sure yet. Add the function prototypes ( for loop and setup ) your self above all the classes.

Even try placing them above all includes and defines.
Logged


Offline Offline
Edison Member
*
Karma: 9
Posts: 1000
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you use the newest Arduino 1.0.3 ?
The example is old.

For a sketch the "#include <inttypes.h>" and "#include <avr/pgmspace.h>" are not needed I think. I'm not sure about a library.

This line causes an error :
Code:
class CamStateHandlers : PTPStateHandlers
Can you try to remove the ": PTPStateHandlers" and see what error you get ?
Logged

UK
Offline Offline
Edison Member
*
Karma: 44
Posts: 2233
What a host of balls she had seen: gaity, the brass buttons...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try turning on verbose output on compilation - it may give you more errors, like missing header files
Logged


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 315
Posts: 35519
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have setup() and loop() as functions in the class body.

You REALLY need to learn how to do classes properly. You should have at least three files -  a header file that defines the class, a source file that implements the class, and a sketch that uses the class.
Logged

Pages: [1]   Go Up
Print
 
Jump to: