Merge pull request #647 from adafruit/fix-warning

Fix warning
This commit is contained in:
Ha Thach authored and GitHub committed 2021-05-26 11:04:04 +07:00
commit 04a80873cd
13 files changed
+73 -68

No files matched your search

+18 -6
View File
@@ -266,12 +266,16 @@ bool HardwarePWM::takeOwnership(uint32_t token)
bool const thread_mode = !isInISR();
if (token == 0) {
if (thread_mode) LOG_LV1("HwPWM", "zero is not a valid ownership token (attempted use in takeOwnership)");
if (thread_mode) {
LOG_LV1("HwPWM", "zero is not a valid ownership token (attempted use in takeOwnership)");
}
return false;
}
if (token == this->_owner_token) {
if (thread_mode) LOG_LV1("HwPWM", "failing to acquire ownership because already owned by requesting token (cannot take ownership twice)");
if (thread_mode) {
LOG_LV1("HwPWM", "failing to acquire ownership because already owned by requesting token (cannot take ownership twice)");
}
return false;
}
@@ -290,22 +294,30 @@ bool HardwarePWM::releaseOwnership(uint32_t token)
bool const thread_mode = !isInISR();
if (token == 0) {
if (thread_mode) LOG_LV1("HwPWM", "zero is not a valid ownership token (attempted use in releaseOwnership)");
if (thread_mode) {
LOG_LV1("HwPWM", "zero is not a valid ownership token (attempted use in releaseOwnership)");
}
return false;
}
if (!this->isOwner(token)) {
if (thread_mode) LOG_LV1("HwPWM", "attempt to release ownership when not the current owner");
if (thread_mode) {
LOG_LV1("HwPWM", "attempt to release ownership when not the current owner");
}
return false;
}
if (this->usedChannelCount() != 0) {
if (thread_mode) LOG_LV1("HwPWM", "attempt to release ownership when at least on channel is still connected");
if (thread_mode) {
LOG_LV1("HwPWM", "attempt to release ownership when at least on channel is still connected");
}
return false;
}
if (this->enabled()) {
if (thread_mode) LOG_LV1("HwPWM", "attempt to release ownership when PWM peripheral is still enabled");
if (thread_mode) {
LOG_LV1("HwPWM", "attempt to release ownership when PWM peripheral is still enabled");
}
return false; // if it's enabled, do not allow ownership to be released, even with no pins in use
}
+8 -8
View File
@@ -109,14 +109,14 @@ constexpr static uint64_t _calculate_pulse_count(uint32_t frequency, uint32_t du
(((uint64_t)duration) * frequency / 1000ULL);
};
static int _bits_used(unsigned long x) {
if (0 == x) return 0;
unsigned int result = 0;
do {
result++;
} while (x >>= 1);
return result;
}
//static int _bits_used(unsigned long x) {
// if (0 == x) return 0;
// unsigned int result = 0;
// do {
// result++;
// } while (x >>= 1);
// return result;
//}
static int _bits_used(unsigned long long x) {
if (0 == x) return 0;
+16 -7
View File
@@ -693,13 +693,22 @@ void String::remove(unsigned int index){
}
void String::remove(unsigned int index, unsigned int count){
if (index >= len) { return; }
if (count <= 0) { return; }
if (count > len - index) { count = len - index; }
char *writeTo = buffer + index;
len = len - count;
strncpy(writeTo, buffer + index + count,len - index);
buffer[len] = 0;
// removes characters from the middle of a string.
if (count <= 0) { return; } // exit if nothing to remove
if (index >= len) { return; } // ensure start is within string length; thus, ensures (len-index >= 1)
if (count > len - index) { // ensure characters to remove is no larger than total length remaining
count = len - index;
}
char *writeTo = buffer + index;
char *copyFrom = buffer + index + count;
len = len - count;
// strncpy() cannot be used with overlapping buffers, so copy one char at a time
unsigned int charactersToMove = len - index; // yes, uses post-adjusted length
for (unsigned int i = 0; i < charactersToMove; i++, writeTo++, copyFrom++) {
*writeTo = *copyFrom;
}
buffer[len] = 0;
}
void String::toLowerCase(void)
@@ -44,8 +44,8 @@ class BLEAdafruitSensor : public BLEService
void setNotifyCallback(notify_callback_t fp);
protected:
BLECharacteristic _period;
BLECharacteristic _measurement;
BLECharacteristic _period;
Adafruit_Sensor* _sensor;
@@ -310,6 +310,9 @@ void pairing_complete_callback(uint16_t conn_handle, uint8_t auth_status)
}else
{
Serial.println("Failed");
// disconnect
conn->disconnect();
}
#ifdef USE_ARCADA
@@ -321,9 +324,6 @@ void pairing_complete_callback(uint16_t conn_handle, uint8_t auth_status)
{
tft->setTextColor(ARCADA_RED);
tft->print("Failed ");
// disconnect
conn->disconnect();
}
tft->setTextColor(ARCADA_WHITE);
@@ -241,7 +241,7 @@ void displayNotification(int index)
}else
{
// Text size = 1, max char is 21. Text size = 2, max char is 10
char tempbuf[22];
char tempbuf[30];
sprintf(tempbuf, "%-15s %02d/%02d", myNtf->app_name, index+1, notifCount);
oled.println(tempbuf);
@@ -84,7 +84,7 @@ void onPDMdata() {
uint16_t getSoundAverage() {
uint32_t avg = 0;
for (int i = 0; i < sizeof(soundSampleBuffer)/sizeof(soundSampleBuffer[0]); i++) {
for (uint32_t i = 0; i < sizeof(soundSampleBuffer)/sizeof(soundSampleBuffer[0]); i++) {
avg += soundSampleBuffer[i]*soundSampleBuffer[i];
}
return sqrt(avg);
@@ -207,6 +207,10 @@ void bleuart_rx_callback(uint16_t conn_hdl)
red = (c565 & 0xf800) >> 8;
green = (c565 & 0x07e0) >> 3;
blue = (c565 & 0x001f) << 3;
}else
{
Serial.println("Error: incorrect color bits ");
while(1) yield();
}
// Convert RGB into Eink Color
@@ -288,7 +288,9 @@ bool bond_load_cccd(uint8_t role, uint16_t conn_hdl, ble_gap_addr_t const* id_ad
file.close();
if ( !loaded ) LOG_LV1("BOND", "CCCD setting not found");
if ( !loaded ) {
LOG_LV1("BOND", "CCCD setting not found");
}
return loaded;
}
+1 -1
View File
@@ -206,7 +206,7 @@ void SPIClass::transfer(const void *tx_buf, void *rx_buf, size_t count)
while (count)
{
// each transfer can only up to 64KB (16-bit) bytes
const size_t xfer_len = min(count, UINT16_MAX);
const size_t xfer_len = min((uint16_t) count, UINT16_MAX);
nrfx_spim_xfer_desc_t xfer_desc =
{
+1 -1
View File
@@ -59,7 +59,7 @@ private:
static SoftwareSerial *active_object;
// private methods
void recv() __attribute__((__always_inline__));
void recv();
uint32_t rx_pin_read();
void tx_pin_write(uint8_t pin_state) __attribute__((__always_inline__));
void setTX(uint8_t transmitPin);
+15 -37
View File
@@ -7,10 +7,9 @@ import time
SUCCEEDED = "\033[32msucceeded\033[0m"
FAILED = "\033[31mfailed\033[0m"
SKIPPED = "\033[33mskipped\033[0m"
WARNING = "\033[31mwarnings\033[0m"
SKIPPED = "\033[35mskipped\033[0m"
WARNING = "\033[33mwarnings\033[0m "
all_warnings = False
exit_status = 0
success_count = 0
fail_count = 0
@@ -31,15 +30,6 @@ else:
all_examples = list(glob.iglob('libraries/**/*.ino', recursive=True))
all_examples.sort()
def errorOutputFilter(line):
if len(line) == 0:
return False
if line.isspace(): # Note: empty string does not match here!
return False
# TODO: additional items to remove?
return True
def build_examples(variant):
global exit_status, success_count, fail_count, skip_count, build_format, build_separator
@@ -64,49 +54,37 @@ def build_examples(variant):
sketchdir = os.path.dirname(sketch)
if os.path.exists(sketchdir + '/.all.test.skip') or os.path.exists(sketchdir + '/.' + variant + '.test.skip'):
success = SKIPPED
skip_count += 1
elif glob.glob(sketchdir+"/.*.test.only") and not os.path.exists(sketchdir + '/.' + variant + '.test.only'):
success = SKIPPED
skip_count += 1
else:
# TODO - preferably, would have STDERR show up in **both** STDOUT and STDERR.
# preferably, would use Python logging handler to get both distinct outputs and one merged output
# for now, split STDERR when building with all warnings enabled, so can detect warning/error output.
if all_warnings:
build_result = subprocess.run("arduino-cli compile --warnings all --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=PIPE, stderr=PIPE)
else:
build_result = subprocess.run("arduino-cli compile --warnings default --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=PIPE, stderr=PIPE)
# get stderr into a form where len(warningLines) indicates a true warning was output to stderr
warningLines = [];
if all_warnings and build_result.stderr:
tmpWarningLines = build_result.stderr.decode("utf-8").splitlines()
warningLines = list(filter(errorOutputFilter, (tmpWarningLines)))
build_result = subprocess.run("arduino-cli compile --warnings all --fqbn {} {}".format(fqbn, sketch), shell=True, stdout=PIPE, stderr=PIPE)
# get stderr into a form where warning/error was output to stderr
if build_result.returncode != 0:
exit_status = build_result.returncode
success = FAILED
fail_count += 1
elif len(warningLines) != 0:
exit_status = -1
success = WARNING
fail_count += 1
else:
success = SUCCEEDED
success_count += 1
if build_result.stderr:
success = WARNING
else:
success = SUCCEEDED
build_duration = time.monotonic() - start_time
print(build_format.format(sketch.split(os.path.sep)[1], os.path.basename(sketch), success, '{:5.2f}s'.format(build_duration)))
if success != SKIPPED:
# Build failed
if build_result.returncode != 0:
print(build_result.stdout.decode("utf-8"))
if (build_result.stderr):
print(build_result.stderr.decode("utf-8"))
if len(warningLines) != 0:
for line in warningLines:
print(line)
else:
skip_count += 1
# Build with warnings
if build_result.stderr:
print(build_result.stderr.decode("utf-8"))
build_time = time.monotonic()