Giter Club home page Giter Club logo

Comments (5)

apmorton avatar apmorton commented on August 12, 2024

ino files are handled just like regular c files, except they include Arduino.h automatically.

$(BUILDDIR)/%.o: %.ino
    @echo "[CXX]\t$<"
    @mkdir -p "$(dir $@)"
    @$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(L_INC) -o "$@" -x c++ -include Arduino.h -c "$<"

Its hard to say exactly what issue you are having with your code without looking at it, but my guess would be something to do with forward declaration.

Can you post your code somewhere for me to look at?

from teensy-template.

mgcrea avatar mgcrea commented on August 12, 2024

Basically, I have two files, one firmata.ino that implements the firmata interface, and one file app.ino, I do have issues with the fact that app.ino gets compiled independantly. The second one seems indeed related to forward declaration. Any idea of which flag I should add?

My firmata.ino:

// Firmata
//


String sc_request, sc_response, sc_key, sc_value;
int sc_length, sc_equal;
void stringCallback(char *charBuffer) {

  sc_request = String(charBuffer);

  // Basic commands

  if(sc_request == "ping") {
    Firmata.sendString("pong");
  } else if(sc_request == "restart") {
    WRITE_RESTART(0x5FA0004);
  } else if(sc_request == "off") {
    for(int i = 0; i < chipsCount * 8; i++) {
      writeLedById(i, LOW);
    }
  } else if(sc_request == "on") {
    for(int i = 0; i < chipsCount * 8; i++) {
      writeLedById(i, HIGH);
    }
  } else if(sc_request == "play-finished") {
    resetScenario();
  } else {
    // Firmata.sendString(charBuffer);
  }

  // Assign commands

  sc_equal = sc_request.indexOf("=");

  if(sc_equal != -1) {
    sc_key = sc_request.substring(0, sc_equal);
    sc_value = sc_request.substring(sc_equal + 1);

    if(sc_key == "select") {
      selectButton(sc_value.toInt());
    }

  }

  // Force free memory
  free(charBuffer);
  charBuffer = 0;

}

void sysexCallback(byte command, byte argc, byte *argv) {
  Firmata.sendSysex(command, argc, argv);
}

Error output:

$ make 
[CXX] src/app.ino
In file included from libraries/Firmata/Firmata.h:16:0,
                 from src/app.ino:15:
libraries/Firmata/Boards.h:341:19: warning: extra tokens at end of #ifndef directive [enabled by default]
libraries/Firmata/Boards.h: In function 'unsigned char writePort(byte, byte, byte)':
libraries/Firmata/Boards.h:414:1: warning: no return statement in function returning non-void [-Wreturn-type]
src/app.ino: In function 'void setup()':
src/app.ino:49:31: error: 'stringCallback' was not declared in this scope
src/app.ino:50:31: error: 'sysexCallback' was not declared in this scope
src/app.ino:53:17: error: 'resetScenario' was not declared in this scope
src/app.ino: In function 'void setupPins(Adafruit_MCP23017)':
src/app.ino:68:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/app.ino:69:24: error: 'writeLedById' was not declared in this scope
src/app.ino: In function 'void loop()':
src/app.ino:91:15: error: 'loopDebug' was not declared in this scope
src/app.ino:93:17: error: 'runScenario' was not declared in this scope
src/app.ino: In function 'void resetScenario()':
src/app.ino:109:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/app.ino: In function 'void runScenario()':
src/app.ino:124:17: error: 'loopStandby' was not declared in this scope
src/app.ino:126:21: error: 'loopSelectChild' was not declared in this scope
src/app.ino:128:21: error: 'loopAllSelected' was not declared in this scope
src/app.ino: In function 'void loopStandby()':
src/app.ino:143:70: error: 'blinkLedByIds' was not declared in this scope
src/app.ino:146:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/app.ino:148:40: error: 'writeLedById' was not declared in this scope
src/app.ino:149:25: error: 'selectButton' was not declared in this scope
src/app.ino: In function 'void loopSelectChild()':
src/app.ino:163:81: error: 'sendJson' was not declared in this scope
src/app.ino:165:72: error: 'blinkLedByIds' was not declared in this scope
src/app.ino:170:67: error: 'writeLedById' was not declared in this scope
src/app.ino:171:41: error: 'writeLedById' was not declared in this scope
src/app.ino:172:25: error: 'selectButton' was not declared in this scope
src/app.ino: In function 'void selectButton(int)':
src/app.ino:202:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/app.ino:208:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/app.ino:222:82: error: 'implode' was not declared in this scope
src/app.ino: In function 'void sendJson(char*, int*, size_t)':
src/app.ino:231:37: error: 'implode' was not declared in this scope
src/app.ino: In function 'void implode(char*, int*, size_t)':
src/app.ino:239:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/app.ino: In function 'void blinkLedByIds(int*, size_t, int)':
src/app.ino:257:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/app.ino:261:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/app.ino:267:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/app.ino: In function 'void loopDebugLegacy()':
src/app.ino:280:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/app.ino:285:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/app.ino: In function 'void loopDebug()':
src/app.ino:296:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/app.ino: In function 'void debugValues()':
src/app.ino:312:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
make: *** [/Users/olivier/Dropbox/Projects/teensy-edf/app-i2c/build/src/app.o] Error 1

from teensy-template.

mgcrea avatar mgcrea commented on August 12, 2024

Looks like the arduino build step is indeed quite complex:

The Arduino environment performs a few transformations to your main sketch file (the concatenation of all the tabs in the sketch without extensions) before passing it to the avr-gcc compiler.
First, #include "Arduino.h", or for versions less than 1.0, #include "WProgram.h" is added to the top of your sketch. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the defintions needed for the standard Arduino core.
Next, the environment searches for function definitions within your main sketch file and creates declarations (prototypes) for them. These are inserted after any comments or pre-processor statements (#includes or #defines), but before any other statements (including type declarations). This means that if you want to use a custom type as a function argument, you should declare it within a separate header file. Also, this generation isn't perfect: it won't create prototypes for functions that have default argument values, or which are declared within a namespace or class.
Finally, the contents of the current target's main.cxx file are appended to the bottom of your sketch.

I guess I may switch to pure C++ builds! But I would lost the arduino support, wouldn't I?

from teensy-template.

apmorton avatar apmorton commented on August 12, 2024

indeed, this is due to forward declaration.

What you need to do is declare all your functions before you use them.

You can either do this at the top of app.ino or in a .h file which you include in app.ino

for example, you have a function called sendJson, which you use in loopSelectChild

currently your code looks something like this

void loopSelectChild() {
  sendJson(...);
}

void sendJson(char*, int*, size_t) {

}

Because loopSelectChild comes before sendJson is declared, it has no idea what to do.

If you declare the sendJson function first, it will work as expected.

// forward declarations
void loopSelectChild();
void sendJson(char*, int*, size_t);

// all function bodies after this point

void loopSelectChild() {
  sendJson(...);
}

void sendJson(char*, int*, size_t) {

}

from teensy-template.

mgcrea avatar mgcrea commented on August 12, 2024

@apmorton Thanks for the detailed explanation!

from teensy-template.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.