Skip to content

Commit

Permalink
#63 - Merge master into WB.
Browse files Browse the repository at this point in the history
  • Loading branch information
PerMalmberg committed Aug 31, 2019
2 parents fbf6ef9 + 3630a9c commit bad38d1
Show file tree
Hide file tree
Showing 296 changed files with 2,783 additions and 2,335 deletions.
8 changes: 5 additions & 3 deletions lib/smooth/application/hash/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ namespace smooth::application::hash::base64
std::string encode(const uint8_t* data, std::size_t len)
{
auto buff_size = len * 2;
std::size_t olen{0};
std::size_t olen{ 0 };
auto buff = std::make_unique<uint8_t[]>(buff_size);

auto res = mbedtls_base64_encode(buff.get(), buff_size, &olen, data, len);

while (res == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL)
{
buff = std::make_unique<uint8_t[]>(olen);
Expand All @@ -36,13 +37,14 @@ namespace smooth::application::hash::base64

std::string encoded{};

if(res == 0)
if (res == 0)
{
encoded.assign(buff.get(), buff.get() + olen);

// Ensure proper ending
encoded.append("");
}

return encoded;
}
}
}
8 changes: 5 additions & 3 deletions lib/smooth/application/hash/sha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ namespace smooth::application::hash
{
std::array<uint8_t, 20> sha1(const uint8_t* data, std::size_t len)
{
std::array<uint8_t,20> buff{};
std::array<uint8_t, 20> buff{};
mbedtls_sha1_ret(data, len, buff.data());

return buff;
}

std::array<uint8_t, 32> sha256(const uint8_t* data, std::size_t len)
{
std::array<uint8_t,32> buff{};
std::array<uint8_t, 32> buff{};
mbedtls_sha256_ret(data, len, buff.data(), 0);

return buff;
}
}
}
33 changes: 17 additions & 16 deletions lib/smooth/application/io/i2c/ADS1115.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


#include <bitset>
#include <thread>
#include <cmath>
Expand Down Expand Up @@ -47,7 +46,6 @@ namespace smooth
uint16_t low_thresh_hold,
uint16_t high_thresh_hold)
{

std::bitset<16> new_config;
new_config.set(0, assert_strategy & 1);
new_config.set(1, assert_strategy & 2);
Expand Down Expand Up @@ -79,7 +77,7 @@ namespace smooth
uint16_t low_thresh_hold,
uint16_t high_thresh_hold)
{
std::vector<uint8_t> data{Register::Config};
std::vector<uint8_t> data{ Register::Config };
data.push_back(static_cast<uint8_t>(config >> 8));
data.push_back(static_cast<uint8_t>(config & 0xFF));
bool res = write(address, data);
Expand Down Expand Up @@ -127,7 +125,8 @@ namespace smooth
{
// Ensure that the device has had enough time to perform a conversion.
auto delay = minimum_delay_after_reconfigure();
if(steady_clock::now() <= change_mark + delay)

if (steady_clock::now() <= change_mark + delay)
{
std::this_thread::sleep_until(change_mark + delay);
}
Expand All @@ -154,34 +153,36 @@ namespace smooth
std::chrono::milliseconds ADS1115::minimum_delay_after_reconfigure() const
{
constexpr std::array<std::pair<DataRate, milliseconds>, 8> delays = {
std::make_pair(DataRate::SPS_8, milliseconds{static_cast<int>(lround(1000.0 / 8))}),
std::make_pair(DataRate::SPS_16, milliseconds{static_cast<int>(lround(1000.0 / 16))}),
std::make_pair(DataRate::SPS_32, milliseconds{static_cast<int>(lround(1000.0 / 32))}),
std::make_pair(DataRate::SPS_64, milliseconds{static_cast<int>(lround(1000.0 / 64))}),
std::make_pair(DataRate::SPS_128, milliseconds{static_cast<int>(lround(1000.0 / 128))}),
std::make_pair(DataRate::SPS_250, milliseconds{static_cast<int>(lround(1000.0 / 250))}),
std::make_pair(DataRate::SPS_475, milliseconds{static_cast<int>(lround(1000.0 / 475))}),
std::make_pair(DataRate::SPS_860, milliseconds{static_cast<int>(lround(1000.0 / 860))}),
std::make_pair(DataRate::SPS_8, milliseconds{ static_cast<int>(lround(1000.0 / 8)) }),
std::make_pair(DataRate::SPS_16, milliseconds{ static_cast<int>(lround(1000.0 / 16)) }),
std::make_pair(DataRate::SPS_32, milliseconds{ static_cast<int>(lround(1000.0 / 32)) }),
std::make_pair(DataRate::SPS_64, milliseconds{ static_cast<int>(lround(1000.0 / 64)) }),
std::make_pair(DataRate::SPS_128, milliseconds{ static_cast<int>(lround(1000.0 / 128)) }),
std::make_pair(DataRate::SPS_250, milliseconds{ static_cast<int>(lround(1000.0 / 250)) }),
std::make_pair(DataRate::SPS_475, milliseconds{ static_cast<int>(lround(1000.0 / 475)) }),
std::make_pair(DataRate::SPS_860, milliseconds{ static_cast<int>(lround(1000.0 / 860)) }),
};

auto sps = static_cast<DataRate>((current_config & 0x0070) >> 4);

milliseconds delay{};

auto found = std::find_if(std::begin(delays), std::end(delays), [sps](auto& pair){ return pair.first == sps; });
auto found = std::find_if(std::begin(delays), std::end(delays), [sps](auto& pair)
{
return pair.first == sps;
});

if(found != std::end(delays))
if (found != std::end(delays))
{
delay = (*found).second;
}
else
{
delay = milliseconds{130};
delay = milliseconds{ 130 };
}

return delay;
}
}
}
}

Loading

0 comments on commit bad38d1

Please sign in to comment.