Including .H & .CPP in the sketch folder

Hello,

I'm developping my first library and I'm experiencing a trouble when compiling if my librairie files (.h & .cpp) are in the same folder as the sketch (.ino).

Here is the error message :

Same files (.h & .cpp) in the "arduino-1.0.3/libraries/PPMread/" compile fine.

Is there a solution to have in the same IDE instance : the librarie (h & cpp) and the sketch (ino), in order to debug, compile & test it fast ?

PPMRead.zip (2.01 KB)

Sadly, the tabs don't change when I click on then, nor does the scrollbar move. The copy and paste functions don't work worth a damn, either.

Sorry, I can't reproduce your problem.

How about posting your code, and not just a screenshot of it?

How to use this forum

I've added a ZIP file containing every files in the initial post.

But...
Here is the .H content :

/*
  PPMread.h - Library for reading PPM 6ch (negative modulated).
  V001
 */

#ifndef PPMread_H
#define PPMread_H

class PPMread
{
public:
  PPMread(unsigned int* rxPoint);
  void begin();
  int read();
private:
  unsigned int* _rxPoint;
};

#endif

And the CPP :

/*
  PPMread.cpp - Library for reading PPM 6ch (negative modulated).
 V001
 */

#include "PPMread.h"
#include <Arduino.h>

// #define LEDPPM 1   // Uncomment to flash Arduino LED 
                      // Quickly when Ok, slowly on failsafe

PPMread::PPMread(unsigned int* rxPoint)
{
  _rxPoint=rxPoint;
}

// Données de capture du Rx
boolean endTrame=0,failsafe=0;
volatile unsigned int vchUp[8];
volatile unsigned int vchPos[6];
byte curEdge;
#ifdef LEDPPM
unsigned int failflash;
#endif


ISR(TIMER1_CAPT_vect)
{
  vchUp[curEdge]=ICR1; // Capture des timestamp 1 à 6
  curEdge++;
  if (curEdge>7) {     // A partie du 7ème...   
    TCNT1=0;           // RESET du counter pour éviter le FailSafe
    if ((vchUp[7]-vchUp[1]) > 30000) {  //Si la trame totale dépasse 15ms - Trame KO ou mauvaise synchro
      curEdge=0;            //Remise à 0 du compteur de fronts                      
    }
    else {                  //Sinon, une bonne trame est capturée, on calcule donc la valeur des canaux
      curEdge=1;
      for (int i=0;i<6;i++) {
        vchPos[i]=(vchUp[i+2]-vchUp[i+1]); //Mesure des canaux (diviser par 2 pour obtenir des µs)
      }
      endTrame=1;           // Pour dire à la fonction read que de nouvelles valeurs sont disponibles
      if (failsafe==1) failsafe=0;
#ifdef LEDPPM
      if (digitalRead(13)==LOW) digitalWrite(13,HIGH);
      else digitalWrite(13,LOW);
#endif
    }
  }
}

ISR(TIMER1_OVF_vect)
{
  failsafe=1;  // Le compteur a attends sa limite (32ms), on déclenche donc le FailSafe
#ifdef LEDPPM
  if (failflash==10) {
  failflash=0;
    if (digitalRead(13)==LOW) digitalWrite(13,HIGH);
  else digitalWrite(13,LOW);
  }
  else failflash++;
#endif
}


void PPMread::begin()
{
  // Timer1 setup
  TCCR1A=B00000000; // OCR2A/OCR2B : disconnected, Timer: normal mode
  TCCR1B=B00000010; // Falling edge CAPTUREPIN detection, Timer:normal mode, Prescaler=clk/8 
  TIMSK1=B00100001; // Activate CAPTUREPIN interrupt & OVF interrupt
#ifdef LEDPPM
  pinMode(13,OUTPUT);
#endif
}

int PPMread::read()
{
  if (endTrame==1) {
    endTrame=0;
    unsigned int* movingPoint=_rxPoint;
    for (int i=0;i<6;i++) { 
      *movingPoint=vchPos[i];
      movingPoint++;
    }
    return 1;
  }
  if (failsafe==1) {
    return 2;
  }
  else {
    return 0;
  }
}

And finaly the sketch :

#include "PPMread.h"          // On inclue la librairie

// Données du Rx
unsigned int cha[6];           // Les valeurs des canaux

ppmread ppm(&cha[0]);          // On lance l'instance, en fournissant le pointeur

void setup()
{
  Serial.begin(115200);        // On prepare la sortie série
  Serial.println("");
  Serial.println("PPM read, librarie test");

  ppm.begin();                // On démarre la lecture PPM en arrière-plan
}

void loop()
{
  if (0 < ppm.read()){   // Si des nouvelles valeurs ou FAILSAFE
    if (1 < ppm.read()){   // Si FAILSAFE
      Serial.println("FAILSAFE");

    }
    else {               // Si des nouvelles valeurs, la variable est DEJA A JOUR
    for (int i=0; i < 6; i++){ // Imprimer les valeurs des canaux sur le port série
        Serial.print(cha[i]);
        Serial.print(";");
      }
      Serial.println(";");

    } 
  }
}

The sketch needs to have a different name from the class. That is, the sketch can NOT be called PPMread.ino.

ppmread ppm(&cha[0]);          // On lance l'instance, en fournissant le pointeur

What is this? The class is called PPMread.

Binary sketch size: 2,782 bytes (of a 30,720 byte maximum)

After renaming the sketch...

Thank you very much PaulS, since I was testing everything, I was breaking my code trying to find the trick !!

I'll code more serene now.