arduino / arduino/ArduinoCore-mbed

Unable to compile libraries when passing chrono duration instead of integer millisecond count

Open
#557 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
411
Forks
225
PR merge metrics
No merged PRs in 30d

Description

When compiling any of the examples for USBHID the following warning appears

```
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouseKeyboard.cpp: In member function 'bool arduino::USBMouseKeyboard::doubleClick()':
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouseKeyboard.cpp:706:36: warning: 'void rtos::ThisThread::sleep_for(uint32_t)' is deprecated: Pass a chrono duration, not an integer millisecond count. For example use `5s` rather than `5000`. [since mbed-os-6.0.0] [-Wdeprecated-declarations]
rtos::ThisThread::sleep_for(100);
^
In file included from C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouseKeyboard.cpp:21:0:
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\cores\arduino/mbed/rtos/include/rtos/ThisThread.h:216:6: note: declared here
void sleep_for(uint32_t millisec);
^~~~~~~~~
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouseKeyboard.cpp: In member function 'bool arduino::USBMouseKeyboard::click(uint8_t)':
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouseKeyboard.cpp:721:35: warning: 'void rtos::ThisThread::sleep_for(uint32_t)' is deprecated: Pass a chrono duration, not an integer millisecond count. For example use `5s` rather than `5000`. [since mbed-os-6.0.0] [-Wdeprecated-declarations]
rtos::ThisThread::sleep_for(10);
^
In file included from C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouseKeyboard.cpp:21:0:
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\cores\arduino/mbed/rtos/include/rtos/ThisThread.h:216:6: note: declared here
void sleep_for(uint32_t millisec);
^~~~~~~~~
```

Was planning on fixing it on a pull request as the warning message seemed quite self explanatory, but when I tried to fix it by changing it from `rtos::ThisThread::sleep_for(10)` to `rtos::ThisThread::sleep_for(10ms)` it wouldn't compile throwing the following error.

```
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouse.cpp: In member function 'bool arduino::USBMouse::double_click()':
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouse.cpp:152:33: error: unable to find numeric literal operator 'operator""ms'
rtos::ThisThread::sleep_for(100ms);
^~~~~
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouse.cpp: In member function 'bool arduino::USBMouse::click(uint8_t)':
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouse.cpp:167:33: error: unable to find numeric literal operator 'operator""ms'
rtos::ThisThread::sleep_for(10ms);
^~~~
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouseKeyboard.cpp: In member function 'bool arduino::USBMouseKeyboard::doubleClick()':
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouseKeyboard.cpp:706:33: error: unable to find numeric literal operator 'operator""ms'
rtos::ThisThread::sleep_for(100ms);
^~~~~
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouseKeyboard.cpp: In member function 'bool arduino::USBMouseKeyboard::click(uint8_t)':
C:\Users\jvaqu\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.3.0\libraries\USBHID\src\USBMouseKeyboard.cpp:721:33: error: unable to find numeric literal operator 'operator""ms'
rtos::ThisThread::sleep_for(10ms);
^~~~
```

I thought that the type of `10ms` would just match to `void sleep_for(Kernel::Clock::duration_u32 rel_time);` it could be that I'm missing some imports but I don't really know which ones.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by inspecting USBMouse.cpp and USBMouseKeyboard.cpp at the reported sleep_for calls, then check the included mbed ThisThread and chrono declarations. Verify the required duration syntax and imports by compiling the USBHID examples. Done means the examples compile without the deprecated integer-duration warnings or chrono literal errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.