Integrate Qt in Application for Debug/Simulation (without qmake?)
-
wrote on 13 Aug 2018, 19:36 last edited by
Hello,
I already have some pieces of code for an arduino. I would like to visualize some of the calculated things as kind of a debug modus. So qt should not run beside the arduino!
The user have the choice to compile it for arduino or for Computer with qt.At the moment, I just have some terminal output as the debug modus. So I wrote a makefile, which supports make and make upload for arduino and make debug for Terminal output. How could I integrate Qt? Normally, we have a .pro file generating a new makefile ... is it possible to write my own makefile for qt? Or can I call the generated makefile from my other makefile?
Thanks!
-
Hi,
Do you mean you want to:
- Build and upload your code to the arduino
- Build the exact same code as a Qt application to do some stuff but not use the arduino at all
Is that correct ?
-
wrote on 17 Aug 2018, 14:46 last edited by
I think so.
Of course my code uses macros to comment out arduino specific things, which could not run under x86_64 .
A simple example
#ifndef DEBUG #include <avr/io.h> #else #include <iostream> #endif int main (void) { //some calculations (which leds should be on) int leds = 5 * 10; #ifndef DEBUG DDRB = 0xFF; PORTB = leds; #else std::cout << "These leds are high: " << leds << '\n'; #endif while(1) ; return 0; }
This is just a small useless example for illustration. In my real code I want the debug information (std::cout) to be visualized with qt and the qt code will only use the data from the arduino code and will be more seperated (adaptern pattern).
Folder Structure
- MyProject
- bin
- obj
- src
- debug
- SomeQtCode.h
- SomeArduinoCode.h
- debug
- Makefile
In my Makefile there should be two options
make -> compiles everything for arduino (without qt classes of course) ... obj files in obj folder, bin files in bin folder (works perfect)
make debug -> compiles everything for x86_64 (with qt files) ... obj files in obj folder, bin files in bin folder. Additionally it sets the DEBUG macro.But as we compile qt with qmake (which creates a makefile), my makefile should probably include the created makefile from qt? And it would also be great if I could specify that object/moc files come into the obj folder ....
My Makefile currently
TARGET := Hexapod #avr MCU := atmega328p PROGRAMMER := arduino PORT := -P /dev/ttyUSB0 BAUD := -b 57600 F_CPU := 16000000 #Compiler CXX := avr-g++ LDFLAGS := CXXFLAGS := -Wall -std=c++11 -c # Commands REMOVE := rm -r -f #Directories SRCDIR := src OBJDIR := obj BINDIR := bin # Files cppfiles := $(wildcard $(SRCDIR)/*.cpp) objects := $(subst $(SRCDIR)/, $(OBJDIR)/, $(cppfiles:.cpp=.o)) .Phony: all debug arduino install size clean default all: arduino debug: CXXFLAGS += -D DEBUG=1 debug: CXX = g++ debug: $(BINDIR)/$(TARGET) arduino: LDFLAGS += -Os -mmcu=$(MCU) -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums arduino: CXXFLAGS += -Os -mmcu=$(MCU) -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -D F_CPU=$(F_CPU) arduino: $(BINDIR)/$(TARGET).hex # Debug $(BINDIR)/$(TARGET): $(objects) mkdir -p $(@D) $(CXX) $(LDFLAGS) -o $@ $^ $(OBJDIR)/%.o: $(SRCDIR)/%.cpp mkdir -p $(@D) $(CXX) $(CXXFLAGS) -o $@ $< # Arduino $(BINDIR)/$(TARGET).elf: $(objects) mkdir -p $(@D) $(CXX) $(LDFLAGS) -o $@ $^ $(BINDIR)/$(TARGET).hex: $(BINDIR)/$(TARGET).elf avr-objcopy -O ihex -j .data -j .text $(BINDIR)/$(TARGET).elf $(BINDIR)/$(TARGET).hex upload: avrdude -p $(MCU) $(PORT) $(BAUD) -c $(PROGRAMMER) -U flash:w:$(BINDIR)/$(TARGET).hex:i size: avr-size --mcu=$(MCU) -C --format=avr $(BINDIR)/$(TARGET).elf clean: $(REMOVE) $(OBJDIR) $(REMOVE) $(BINDIR)
- MyProject
-
Just to sum up and be sure we are talking about the same thing. You would like to run and debug your arduino code on your desktop as if it was running on the target and be able to build the same code and run in on the target. Correct ?
1/4