Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Compile Error with enum variable (Read 1206 times)
Fer
Newbies
*
Offline


Posts: 5
Location: Buenos Aires
Joined: Aug 27th, 2018
Compile Error with enum variable
Jul 1st, 2019 at 5:03pm
Print Post  
Hi. I am migrating from the Arduino IDE to Visual Micro and encountered the following problem. The following sketch compiles OK in the Arduino IDE: 

enum umMode { normal, awaken, lowPower, settings };
const byte SET_A_PIN = 6;
const byte SET_B_PIN = 7;
void setup() {
       SetUmMode(settings);
       ConfigUm();
       
}

void loop() {
}

void ConfigUm() {
}

void SetUmMode(umMode _umMode) {
       Serial.print("_umMode = "); Serial.println(_umMode);             // DEBUG
       byte setAState;
       byte setBState;
       switch (_umMode)
       {
       case normal:                                                       
              setAState = 0;
              setBState = 0;
              break;
       case awaken:
              setAState = 0;
              setBState = 1;
              break;
       case lowPower:
              setAState = 1;
              setBState = 0;
              break;
       case settings:
              setAState = 1;
              setBState = 1;
              break;
       }
       digitalWrite(SET_A_PIN, setAState);
       digitalWrite(SET_B_PIN, setBState);
}

In Visual Micro I get the green check mark saying No issues found, but when I try to build it, I get the following error: 

Building variant ...
 
Using previously compiled variant
 
Building core ...
 
Building project code ...
 
UM_Config_F.ino: 12:16: error: variable or field 'SetUmMode' declared void
 
UM_Config_F.ino: 12:16: error: 'umMode' was not declared in this scope
Error compiling project sources
Build failed for project 'UM_Config_F'
 
UM_Config_F.ino: In function void setup()


Please, could you help me find the problem? Thanks a lot for your help. 

Kind regards,

Fernando.
  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Compile Error with enum variable
Reply #1 - Jul 1st, 2019 at 6:30pm
Print Post  
Hi,

One of the only differences is that we have not yet implemented the ctags system to determine the correct location for prototypes of functions that use types created in the .ino files.

In short this means you need to do what you would do in a c++ file and add the prototype at the location that makes sense. Like this. Notice the "void SetUmMode(umMode _umMode);" prototype with exact same signature as the method is located between the creation of the type and first use.

Code (C++)
Select All
enum umMode { normal, awaken, lowPower, settings };
const byte SET_A_PIN = 6;
const byte SET_B_PIN = 7;
void setup() {
       SetUmMode(settings);
       ConfigUm();

}

void loop() {
}

void ConfigUm() {
}


void SetUmMode(umMode _umMode);

void SetUmMode(umMode _umMode) {
       Serial.print("_umMode = "); Serial.println(_umMode);             // DEBUG
       byte setAState;
       byte setBState;
       switch (_umMode)
       {
       case normal:
              setAState = 0;
              setBState = 0;
              break;
       case awaken:
              setAState = 0;
              setBState = 1;
              break;
       case lowPower:
              setAState = 1;
              setBState = 0;
              break;
       case settings:
              setAState = 1;
              setBState = 1;
              break;
       }
       digitalWrite(SET_A_PIN, setAState);
       digitalWrite(SET_B_PIN, setBState);
}
 

  
Back to top
WWW  
IP Logged
 
Fer
Newbies
*
Offline


Posts: 5
Location: Buenos Aires
Joined: Aug 27th, 2018
Re: Compile Error with enum variable
Reply #2 - Jul 2nd, 2019 at 1:56pm
Print Post  
Thank you very much, Tim. I added the function prototype and now it works perfectly.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint