Multi devices driver [solved]

Hello,

I'm working on a menu brower with several embedded devices. It works with Serial, encoder, keyboard 4x4 and joystick as selectable inputs and Serial or I2C LCD 4x20.

The problem is that at the moment I select them from a #define in my library... I don't see how to select then directly from a sketch, which seems to be the best solution... An idea?

This is the continuation of this topic

Do you envisage prompting the user to select the devices ?

No, it's just at compilation time that devices have to be selected.

Could the #defines go in the actual sketch ?

At the moment they are in the library, I would like to make them working in the sketch but it doesn’t work… Because when you include a library with <something.h>, something.cpp has no connection to the sketch… Am i wrong?

it doesn't work

What does that mean ?

For that I would just make a parent class which has all the shared functionality and make child classes (which inherit from the parent) to add the device specific details. Now you can select the device by creating an object of the correct child in your sketch.

septillion:
For that I would just make a parent class which has all the shared functionality and make child classes (which inherit from the parent) to add the device specific details. Now you can select the device by creating an object of the correct child in your sketch.

That was my first suggestion 8 days ago.

Ahh, wasn't aware it was sort of a cross post!

UKHeliBob:
What does that mean ?

With the attached exmaple I get this error, I think it’s logic.

Compiling library "dummy"
"C:\\PROGS\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10809 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\PROGS\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\PROGS\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "-IC:\\PROGS\\Arduino\\libraries\\dummy" "C:\\PROGS\\Arduino\\libraries\\dummy\\dummy.cpp" -o "C:\\Users\\pfeuh\\AppData\\Local\\Temp\\arduino_build_472975\\libraries\\dummy\\dummy.cpp.o"
C:\PROGS\Arduino\libraries\dummy\dummy.cpp: In function 'byte getDefine()':

C:\PROGS\Arduino\libraries\dummy\dummy.cpp:6:12: error: 'VALUE_FROM_SKETCH' was not declared in this scope

    return VALUE_FROM_SKETCH;

           ^

dummy.zip (1.27 KB)

gfvalvo:
That was my first suggestion 8 days ago.

Now I understand what you mean. It was not the case 8 days before. Thanks a lot everybody.