arduino-libraries / ArduinoBLE

ArduinoBLE library for Arduino
GNU Lesser General Public License v2.1
291 stars 198 forks source link

HCI.cpp:991:7: error: case value '10' not in enumerated type 'LE_META_EVENT' #346

Closed franciozzy closed 5 months ago

franciozzy commented 5 months ago

I'm trying to compile the "scan" example from 1.3.6 on Arduino IDE 2.2.1 and running into a few errors including the following:

~/Documents/Arduino/libraries/ArduinoBLE/src/utility/HCI.cpp:1272:30: warning: missing initializer for member 'HCIClass::handleEventPkt(uint8_t, uint8_t*)::F4Params::Z' [-Wmissing-field-initializers]
~/Documents/Arduino/libraries/ArduinoBLE/src/utility/HCI.cpp:991:7: error: case value '10' not in enumerated type 'LE_META_EVENT' [-Werror=switch]
       case 0x0A:{

Looks like a legit error as the enum LE_META_EVENT (see HCI.h) only has values from 1 to 9 and the switch statement checks for 10.

per1234 commented 5 months ago

Thanks for your report @franciozzy. I see we already have an issue tracking this problem: https://github.com/arduino-libraries/ArduinoBLE/issues/310. So I'll close this as a duplicate.

From the fact that this problem is causing a compilation error instead of only a warning, I will assume you are compiling for an ESP32 board.

The "esp32" boards platform (as well as the "Arduino ESP32 Boards" platform which is a fork of "esp32") is unique in that the compilation result is affected by the setting of Arduino IDE's "Compiler warnings" preference.

Traditionally this preference has only influenced how many warnings we see in the compilation output, but the Arduino boards platform framework allows each platform developer to decide exactly what effect they want each of the levels of this preference to have. The ESP32 developers decided to add the -Werror=all flag to the compilation command when you set the "Compiler warnings" preference to the "More" or "All" levels. This flag causes compilation to fail when the sketch code produces a compilation warning.

This means that the workaround for this error is to reduce the level of the "Compiler warnings" preference to avoid the warnings causing a compilation error:

  1. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus. The "Preferences" dialog will open.
  2. Select "Default" from the "Compiler warnings" menu in the "Preferences" dialog.
  3. Click the "OK" button.

After doing that, you should be able to compile the ArduinoBLE library for ESP32 boards.