microsoft / microsoft/vscode-cpptools
Create Declaration / Definition in current file
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Discussed in https://github.com/microsoft/vscode-cpptools/discussions/10642
Originally posted by FernandoGarcia March 7, 2023
Hi!
I would to know how to create function prototype in an Arduino code while using Platformio.
I'm talking about this type of code:
main.cpp
#include <Arduino.h>
#include <Bounce2.h>
#define NUM_RELAYS 3
#define INITIAL_STATE LOW // Initial state = HIGH to active LOW relay model.
struct INFOS
{
const byte relayPin;
bool relayState;
const byte buttonPin;
};
INFOS info[NUM_RELAYS] =
{
{2, INITIAL_STATE, 18}, // Relay 0 pin, relay 0 state, button 0 pin
{4, INITIAL_STATE, 19},
{5, INITIAL_STATE, 21}
};
Bounce2::Button button[NUM_RELAYS] = {Bounce2::Button()};
void setup()
{
Serial.begin(9600);
for (byte i = 0; i < NUM_RELAYS; i++)
{
button[i].attach(info[i].buttonPin, INPUT_PULLUP);
button[i].setPressedState(LOW);
button[i].interval(5);
pinMode(info[i].relayPin, OUTPUT);
digitalWrite(info[i].relayPin, info[i].relayState);
}
}
void loop()
{
for (byte i = 0; i < NUM_RELAYS; i++)
{
button[i].update();
if (button[i].pressed())
{
info[i].relayState = !info[i].relayState;
digitalWrite(info[i].relayPin, info[i].relayState);
printDebug(i);
break;
}
}
}
void printDebug(byte i)
{
Serial.print("Button ");
Serial.print(i);
Serial.print(" pressed, relayState ");
Serial.print(i);
Serial.print(": ");
Serial.println(info[i].relayState);
}
The compiling error for this code is:
src/main.cpp: In function 'void loop()':
src/main.cpp:47:7: error: 'printDebug' was not declared in this scope
printDebug(i);
^~~~~~~~~~
src/main.cpp:47:7: note: suggested alternative: 'Printable'
printDebug(i);
^~~~~~~~~~
Printable
*** [.pio/build/uno/src/main.cpp.o] Error 1
So I have always to create manually all functions prototypes on top of my code in this way:
void printDebug(byte i);
I have tried the new feature of C++ extension but it doesn't works well for this type of code.
The declaration is being placed in Arduino.h header file what is not correct for this case.
Thanks in advance.
Best regards.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue using the provided main.cpp example in a PlatformIO Arduino project, focusing on the Create Definitions and Declarations feature. Compare the generated declaration placement with Arduino.h and the current file context. Done means the function prototype is placed in the current source file rather than Arduino.h.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, cpp
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100