diff options
author | Lisin Dmitriy <d.lisin@thirdpin.io> | 2020-09-25 15:15:11 +0300 |
---|---|---|
committer | Lisin Dmitriy <d.lisin@thirdpin.io> | 2020-09-25 15:15:11 +0300 |
commit | 58d12fc371c84ab45c8e05a147896e1d3d54a557 (patch) | |
tree | 741866b79ec1b2aeeb8545059fb188177002c399 | |
parent | e4b8dfd437d4d2d2f60bfcd9776589065dd72d24 (diff) |
Suppress all implicit conversion warnings [2]
-rw-r--r-- | cm3cpp/extra/one_wire.cpp | 18 | ||||
-rw-r--r-- | cm3cpp/utils/round_buffer.hpp | 10 |
2 files changed, 16 insertions, 12 deletions
diff --git a/cm3cpp/extra/one_wire.cpp b/cm3cpp/extra/one_wire.cpp index 8489955..20eda3d 100644 --- a/cm3cpp/extra/one_wire.cpp +++ b/cm3cpp/extra/one_wire.cpp @@ -38,7 +38,7 @@ uint8_t OneWire::read_byte(void) _wait(_READ_SAMPLE_WAIT_US); /*sample bus and shift into msb*/ - data = data >> 1; + data = static_cast<uint8_t>(data >> 1); if (_pinout.get() != 0) data |= 0x80; @@ -61,7 +61,7 @@ void OneWire::write_byte(uint8_t data) /*write next bit*/ ((bool)(data & 0x01)) ? _pinout.set() : _pinout.clear(); - data = data >> 1; + data = static_cast<uint8_t>(data >> 1); /*wait until end of slot*/ _wait(_WRITE_SLOT_WAIT_US); @@ -192,7 +192,8 @@ bool OneWire::search_next(bool do_reset, bool alarm_only) do { // read a bit and its compliment bit_test = static_cast<uint8_t>(uint8_t(read_bit()) << 1); - bit_test |= ((uint8_t)read_bit()); + bit_test = + static_cast<uint8_t>(bit_test | static_cast<uint8_t>(read_bit())); // check for no devices on 1-wire if (bit_test == 3) @@ -227,7 +228,8 @@ bool OneWire::search_next(bool do_reset, bool alarm_only) if (search_direction == 1) _serial[serial_byte_number] |= serial_byte_mask; else - _serial[serial_byte_number] &= ~serial_byte_mask; + _serial[serial_byte_number] = static_cast<uint8_t>( + _serial[serial_byte_number] & ~serial_byte_mask); // serial number search direction write bit write_bit((bool)search_direction); @@ -235,7 +237,7 @@ bool OneWire::search_next(bool do_reset, bool alarm_only) // increment the byte counter bit_number // and shift the mask serial_byte_mask bit_number++; - serial_byte_mask <<= 1; + serial_byte_mask = static_cast<uint8_t>(serial_byte_mask << 1); // if the mask is 0 then go to new SerialNum[portnum] byte // serial_byte_number and reset mask @@ -304,14 +306,14 @@ void OneWire::_crc_check(uint8_t data, uint8_t* crc_byte) for (uint8_t bit_count = 0; bit_count < 8; bit_count++) { if ((data & 0x01) ^ (tmp & 0x01)) { - tmp = tmp >> 1; + tmp = static_cast<uint8_t>(tmp >> 1); tmp = tmp ^ 0x8c; // 0b10001100; } else { - tmp = tmp >> 1; + tmp = static_cast<uint8_t>(tmp >> 1); } - data = data >> 1; + data = static_cast<uint8_t>(data >> 1); } *crc_byte = tmp; diff --git a/cm3cpp/utils/round_buffer.hpp b/cm3cpp/utils/round_buffer.hpp index e9fe371..296efb6 100644 --- a/cm3cpp/utils/round_buffer.hpp +++ b/cm3cpp/utils/round_buffer.hpp @@ -132,7 +132,7 @@ class RoundBuffer { uint32_t pos = _head; - assert(index <= std::numeric_limits<int32_t>::max()); + assert(index <= std::size_t(std::numeric_limits<int32_t>::max())); mrb_plus(&pos, static_cast<int32_t>(index)); @@ -225,7 +225,7 @@ class RoundBuffer return (false); } - assert(count <= std::numeric_limits<int32_t>::max()); + assert(count <= std::size_t(std::numeric_limits<int32_t>::max())); mrb_plus(&_head, static_cast<int32_t>(count)); return (true); @@ -244,8 +244,10 @@ class RoundBuffer return 0; } - return ((*this)[index] + - static_cast<uint16_t>((*this)[index + 1] << 8)); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + return (*this)[index] + ((*this)[index + 1] << 8); +#pragma GCC diagnostic pop } bool push(uint8_t byte) |