I happened to come across a macro definition as shown below in a c++ code(https://github.com/LairdCP/UwTerminalX).
#define SpeedModeInactive 0b00
#define SpeedModeRecv 0b01
#define SpeedModeSend 0b10
#define SpeedModeSendRecv 0b11
When I tried to compile it using visual studio 2010, it giving me the following error.
Error 14 error C2059: syntax error : ')'
What is the meaning of this macro?
The usage of macro is shown below.
if ((gchSpeedTestMode == SpeedModeSendRecv || gchSpeedTestMode == SpeedModeRecv) && (gintSpeedBytesReceived10s > 0 || ui->edit_SpeedBytesRec10s->text().toInt() > 0))
{
//Data has been received in the past 10 seconds: start a timer before stopping to catch the extra data packets
gchSpeedTestMode = SpeedModeRecv;
gtmrSpeedTestDelayTimer = new QTimer();
gtmrSpeedTestDelayTimer->setSingleShot(true);
connect(gtmrSpeedTestDelayTimer, SIGNAL(timeout()), this, SLOT(SpeedTestStopTimer()));
gtmrSpeedTestDelayTimer->start(5000);
//Show message that test will end soon
ui->statusBar->showMessage("Waiting 5 seconds for packets to be received... Click cancel again to stop instantly.");
}
It is because visual studio doesn't recognize binary values (starting with 0bXXX) but, you can simply define as a hex values just like that:
#define SpeedModeInactive 0x0
#define SpeedModeRecv 0x1
#define SpeedModeSend 0x2
#define SpeedModeSendRecv 0x3
The use of binary literals was first introduced in C++14 which is not supported by VS2010, https://en.wikipedia.org/wiki/C%2B%2B14#Binary_literals
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
Dear Stackoverflowers,
I am trying to add support for the esp32 to the HX8357D 3.5" TFT display from Adafruit (link). I made a fork of the library from Adafruit (link) that handles the 8-bit parallel interface and added an esp32 branch. I figured out most of the components needed, but I'm having trouble to get the code to compile. Could someone help me with getting it to work?
I made an Arduino sketch with the code that has to be implemented into the library:
//Not used in this sketch, but these are the 5 control pins for the TFT display
#define LCD_CS 27
#define LCD_CD 26
#define LCD_WR 25
#define LCD_RD 14
#define LCD_RESET 13
//8 data pins (random, but made sure they are all ardressable with one register)
#define DATA_PIN0 3
#define DATA_PIN1 18
#define DATA_PIN2 5
#define DATA_PIN3 17
#define DATA_PIN4 16
#define DATA_PIN5 4
#define DATA_PIN6 2
#define DATA_PIN7 15
#define DELAY 200
gpio_config_t io_conf;
//Some random data to write to the gpio pins, creates a pattern to the LED's that I connected
uint32_t data[] {
0b00000000000000001000000000001000,
0b00000000000001000000000000000100,
0b00000000000000000000000000110000,
0b00000000000000110000000000000000,
0b00000000000000000000000000000000,
0b00000000000000110000000000000000,
0b00000000000000000000000000110000,
0b00000000000001000000000000000100,
0b00000000000000001000000000001000
};
void setup() {
Serial.begin(115200);
setReadDir();
print32Bits(GPIO.in);
setWriteDir();
}
void loop() {
for (int i = 0; i < 9; i++) {
GPIO.out_w1tc = 0xFFFFFFFF;
GPIO.out_w1ts = data[i];
delay(DELAY);
}
}
//Set 8 data pins to OUTPUT
void setWriteDir() {
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
io_conf.pin_bit_mask = ((1ULL << DATA_PIN0 ) | (1ULL << DATA_PIN1) | (1ULL << DATA_PIN2) | (1ULL << DATA_PIN3) | (1ULL << DATA_PIN4) | (1ULL << DATA_PIN5) | (1ULL << DATA_PIN6) | (1ULL << DATA_PIN7)); // of course, do like this all the pins
gpio_config(&io_conf);
}
//Set 8 data pins to INPUT
void setReadDir() {
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
io_conf.pin_bit_mask = ((1ULL << LCD_CS ) | (1ULL << LCD_CD) | (1ULL << LCD_WR) | (1ULL << LCD_RD) | (1ULL << LCD_RESET)); // of course, do like this all the pins
gpio_config(&io_conf);
}
//Function to print 32 bit interger to Serial, just for convenience
void print32Bits(uint32_t myByte) {
for (uint32_t mask = 0x80000000; mask; mask >>= 1) {
if (mask & myByte) {
Serial.print('1');
} else {
Serial.print('0');
}
}
Serial.println();
}
I added the necessary code to ADAFRUIT_TFTLCD.h, ADAFRUIT_TFTLCD.cpp and pin_magic.h
The functions in pin_magic.h (write8inlin and read8inlin) are not completely done yet. I tried to compile the code to test whether the stuff I had done so far would compile correctly, but I am getting a lot of ....was not declared in this scope errors.
In pin_magic.h I have:
#define RD_ACTIVE GPIO.out_w1tc |= rdPinset
#define RD_IDLE GPIO.out_w1ts |= rdPinSet
#define WR_ACTIVE GPIO.out_w1tc |= wrPinset
#define WR_IDLE GPIO.out_w1ts |= wrPinSet
#define CD_COMMAND GPIO.out_w1tc |= cdPinset
#define CD_DATA GPIO.out_w1ts |= cdPinSet
#define CS_ACTIVE GPIO.out_w1tc |= csPinset
#define CS_IDLE GPIO.out_w1ts |= csPinSet
The first part of the error that I get:
D:\ProgramData\Arduino\libraries\TFTLCD-Library\pin_magic.h:389:42: error: 'csPinset' was not declared in this scope
#define CS_ACTIVE GPIO.out_w1tc |= csPinset
^
D:\ProgramData\Arduino\libraries\TFTLCD-Library\Adafruit_TFTLCD.cpp:268:5: note: in expansion of macro 'CS_ACTIVE'
CS_ACTIVE;
^
If someone with more experience in C/C++ could have a look at it I would be super grateful.
I took a look at your code, are you compiling it in your PC? Looks like the compiler is ignoring the declaration of the csPinset etc due to you #ifdef block -
I'm not familiar with AVR environment, but I recommend compiling your code with the correct compiler(eg AVR compliant) in the intended environment. Alternatively, you can also define __ AVR __ at compile time using the -D option:
g++ < file_name.cpp > -D__AVR__
EDIT
To make sure the variables you need are declared for all environment, you can change the header file to something like this-
#ifndef USE_ADAFRUIT_SHIELD_PINOUT
#ifdef AVR
// "Variable declaration for AVR goes here"
#elif defined SAM
//"Variable declaration for SAM goes here"
/*else block, in case ESP32 is not the correct macro name*/
#else
//"General Variables for everything else other than SAM or AVR."
#endif
//in case the ADA SHIELD PINOUT is defined
#else
//"General Variables for when USE_ADAFRUIT_SHIELD_PINOUT is defined."
#endif
This should fix the "variable not declared" error. You can explore or ask in https://arduino.stackexchange.com the right way to customise this header for the ESP32 env.
I'm new in Embedded systems I am using "atmel Studio7" so I opened ASF wizard T_C driver for xmega128a1 and modified it to set just the timer TCC0 to count 50 ms and throw an overflow flag every 50 ms beside I commented other timers,
I tried to compile but I have one error and I can't correct it the error is: "expected declaration or statement at end of input".
which located in this segment of the code:
void tc_set_ccd_interrupt_callback(volatile void *tc, tc_callback_t callback)
{
#ifdef TCC0
if ((uintptr_t) tc == (uintptr_t) & TCC0)
{
tc_tcc0_ccd_callback = callback;
}
else
#endif
}
anyone have an idea or advise.
Remove the else word. It expects a new statement after it, which you do not have
i have a problem with resources in my audio plugin
here is my resource file
// Unique IDs for each image resource.
#define BCKG_ID 101
#define CANT_ID 102
#define COM10_ID 103
#define COM20_ID 104
#define COM40_ID 105
#define COM80_ID 106
#define SAVE_ID 107
#define WAIT_ID 108
#define ONOFFBYPASS_ID 109
#define ONOFFPRESSED_ID 110
// Image resource locations for this plug.
#define BCKG_FN "resources/img/background.png"
#define CANT_FN "resources/img/cant.png"
#define COM10_FN "resources/img/combo10.png"
#define COM20_FN "resources/img/combo20.png"
#define COM40_FN "resources/img/combo40.png"
#define COM80_FN "resources/img/combo80.png"
#define SAVE_FN "resources/img/savwav.png"
#define WAIT_FN "resources/img/waiting.png"
#define ONOFFBYPASS_FN "resources/img/onoff-bypass.png"
#define ONOFFPRESSED_FN "resources/img/onoff-pressed.png"
i have an assert issue : "file not found" when using this code :
IBitmap onoff1 = pGraphics->LoadIBitmap(ONOFFBYPASS_ID, ONOFFBYPASS_FN, 1);
if i use WAIT_ID instead of ONOFFBYPASS_ID, everything works
in debug assert this code raises a flag:
IBitmap IGraphics::LoadIBitmap(int ID, const char* name, int nStates, bool framesAreHoriztonal)
{
LICE_IBitmap* lb = s_bitmapCache.Find(ID);
if (!lb)
{
lb = OSLoadBitmap(ID, name);
#ifndef NDEBUG
bool imgResourceFound = lb;
#endif
assert(imgResourceFound); **//imgResourceFound = false**
s_bitmapCache.Add(lb, ID);
}
return IBitmap(lb, lb->getWidth(), lb->getHeight(), nStates, framesAreHoriztonal);
}
i tried to :
switch ID values (109 <-> 108)
change the names
check 10 times the paths
but nothing works
it doesn't makes sense, especially because i have 2 other audio plugins with the same part of code that are working ok...
sorry can't provide sample code as it would mean installing VST SDK, WDL-OK...so a bit too much i guess.
please help anyway
Jeff
oh i made a noob error: i forget to add
ONOFFBYPASS_ID PNG ONOFFBYPASS_FN
ONOFFPRESSED_ID PNG ONOFFPRESSED_FN
to MyProg.rc
now everything works
Jeff
I would like to be able to switch my feed between an image, a video and a webcam.
Atm i try this:
#define F_WEBCAM
#define F_VIDEO
#define F_IMAGE
#define FEED(F_WEBCAM)
Somewhere else:
#if defined(FEED) && FEED == F_WEBCAM
ofVideoGrabber vidGrabber;
#elif defined(FEED) && FEED == F_VIDEO
ofVideoPlayer vidPlayer;
#elif defined(FEED) && FEED == F_IMAGE
// code for image
#endif
But i get the following error:
Expected value in expression
Is this possible the way i want?
To compare, you need to define your macro constants with values. This will solve your issue:
#define F_WEBCAM 1
#define F_VIDEO 2
#define F_IMAGE 3
#define FEED F_WEBCAM
(Environment: gcc/g++ 4.6.1 in -std=gnu++0x mode on Linux 3.0 / x86_64...)
#include <stdlib.h>
#include <signal.h>
#include <iostream>
using namespace std;
class SegmentationFault {};
void ThrowSegmentationFault(int)
{
throw SegmentationFault();
}
void ohno(char* x)
{
*x = 42;
}
int main()
{
signal(SIGSEGV, ThrowSegmentationFault);
try
{
ohno(0);
}
catch (const SegmentationFault&)
{
cout << "success" << endl;
}
}
By compiling the above with the -fnon-call-exceptions flag, it allows the SIGSEGV signal handler to throw an exception, and when run it will print "success". The documentation of the -fnon-call-exceptions gcc flag reads as follows:
Generate code that allows trapping instructions to throw
exceptions. Note that this requires platform-specific runtime support
that does not exist everywhere. Moreover, it only allows trapping
instructions to throw exceptions, i.e. memory references or floating
point instructions. It does not allow exceptions to be thrown from
arbitrary signal handlers such as SIGALRM.
My question is which of the signals are trapping instructions and which are not?
#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SIGTRAP 5
#define SIGABRT 6
#define SIGIOT 6
#define SIGBUS 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGUSR1 10
#define SIGSEGV 11
#define SIGUSR2 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGSTKFLT 16
#define SIGCHLD 17
#define SIGCONT 18
#define SIGSTOP 19
#define SIGTSTP 20
#define SIGTTIN 21
#define SIGTTOU 22
#define SIGURG 23
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define SIGWINCH 28
#define SIGIO 29
#define SIGPOLL SIGIO
/*
#define SIGLOST 29
*/
#define SIGPWR 30
#define SIGSYS 31
#define SIGUNUSED 31
SIGILL, SIGTRAP, SIGBUS, SIGFPE, SIGSEGV, SIGSTKFLT are the most probable synchronous signals (i.e., generated by hardware as consequence of an instruction trying to do something invalid).