microsoft / microsoft/vscode-cpptools
Create Declaration / Definition in current file
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 6.2k
- Forks
- 1.7k
- Ø Merge
- 14 Std. 46 Min.
- Gemergte PRs (30 T.)
- 61
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Problem anhand des bereitgestellten main.cpp-Beispiels in einem PlatformIO-Arduino-Projekt und konzentriere dich dabei auf das Feature Create Definitions and Declarations. Vergleiche die Platzierung der generierten Deklaration mit Arduino.h und dem aktuellen Dateikontext. Als erledigt gilt die Aufgabe, wenn der Funktionsprototyp in der aktuellen Quelldatei statt in Arduino.h platziert wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- arduino, cpp
- Bereich
- developer-experience, tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100