diff --git a/src/debugging/can_listener.cpp b/src/debugging/can_listener.cpp index 68db67b7..6b5c3076 100644 --- a/src/debugging/can_listener.cpp +++ b/src/debugging/can_listener.cpp @@ -21,7 +21,6 @@ bool CanListener::hasId(uint32_t id, bool extended) log_.debug("received extended CAN message; skipping"); return false; } - return ids_.find(id) != ids_.end(); } diff --git a/src/sensors/imu.cpp b/src/sensors/imu.cpp index 568d0b71..8590a278 100644 --- a/src/sensors/imu.cpp +++ b/src/sensors/imu.cpp @@ -29,7 +29,7 @@ static constexpr uint8_t kPwrMgmt1 = 0x06; // userbank 0 static constexpr uint8_t kPwrMgmt2 = 0x07; // userbank 0 // Configuration -static constexpr uint8_t kReadFlag = 0x80; // unable to find in datasheet +static constexpr uint8_t kReadFlag = 0x80; // msb is 1 which signifies a read operation for SPI // Configuration bits Imu // constexpr uint8_t kBitsFs250Dps = 0x00; @@ -286,12 +286,13 @@ data::ImuData Imu::getData() } } else { log_.debug("Getting Imu data"); - uint8_t response[8]; + uint8_t response[6]; int16_t bit_data; float value; std::array acceleration_data; - readBytes(kAccelXoutH, response, 8); + // Reading six bytes - first two give x-acceleration, next two give y-acceleration, last two give z-acceleration (high and low byte pairs) + readBytes(kAccelXoutH, response, 6); for (size_t i = 0; i < 3; ++i) { bit_data = ((int16_t)response[i * 2] << 8) | response[i * 2 + 1]; value = static_cast(bit_data); diff --git a/src/sensors/main.cpp b/src/sensors/main.cpp index 99b94692..6e52e5ad 100644 --- a/src/sensors/main.cpp +++ b/src/sensors/main.cpp @@ -387,7 +387,7 @@ std::optional> Main::brakePressurePinsFromFile(utils::Logge } const auto brake_pressure_pin_array = config_object["brake_pressure_pins"].GetArray(); if (brake_pressure_pin_array.Size() != data::Sensors::kNumBrakePressure) { - log.error("Found %d brake sensor pins but %d were expected in configuration file at %s", + log.error("Found %d brake pressure pins but %d were expected in configuration file at %s", brake_pressure_pin_array.Size(), data::Sensors::kNumBrakePressure, path.c_str()); } std::vector brake_pressure_pins; diff --git a/src/utils/io/gpio.cpp b/src/utils/io/gpio.cpp index 93775753..e451ff9c 100644 --- a/src/utils/io/gpio.cpp +++ b/src/utils/io/gpio.cpp @@ -133,7 +133,7 @@ void Gpio::exportGPIO() // let the kernel know we are using this pin int fd; uint32_t len; - fd = open("/sys/class/gpio/export", O_WRONLY); + fd = open("/sys/class/gpio/export", O_RDWR); if (fd < 0) { log_.error("could not open export file"); return; diff --git a/src/utils/io/spi.cpp b/src/utils/io/spi.cpp index 5f721d6b..89c5d772 100644 --- a/src/utils/io/spi.cpp +++ b/src/utils/io/spi.cpp @@ -96,7 +96,7 @@ Spi &Spi::getInstance() Spi::Spi(Logger &log) : spi_fd_(-1), hw_(0), ch_(0), log_(log) { - const char device[] = "/dev/spidev1.0"; // spidev1.0 for SPI0 + const char device[] = "/dev/spidev0.0"; // spidev0.0 for SPI0 spi_fd_ = open(device, O_RDWR, 0); if (spi_fd_ < 0) { @@ -105,7 +105,7 @@ Spi::Spi(Logger &log) : spi_fd_(-1), hw_(0), ch_(0), log_(log) } // set clock frequency - setClock(Clock::k1MHz); + setClock(Clock::k500KHz); uint8_t bits = SPI_BITS; // need to change this value if (ioctl(spi_fd_, SPI_IOC_WR_BITS_PER_WORD, &bits) < 0) { @@ -149,7 +149,6 @@ bool Spi::initialise() ch_ = &hw_->ch0; log_.info("Mapping successfully created %d", sizeof(SPI_HW)); - log_.info("revision 0x%x", hw_->revision); return true; } @@ -157,6 +156,9 @@ void Spi::setClock(Clock clk) { uint32_t data; switch (clk) { + case Clock::k500KHz: + data = 500000; + break; case Clock::k1MHz: data = 1000000; break; diff --git a/src/utils/io/spi.hpp b/src/utils/io/spi.hpp index c22d03e9..07188752 100644 --- a/src/utils/io/spi.hpp +++ b/src/utils/io/spi.hpp @@ -15,7 +15,7 @@ class Spi { public: static Spi &getInstance(); - enum class Clock { k1MHz, k4MHz, k16MHz, k20MHz }; + enum class Clock { k500KHz, k1MHz, k4MHz, k16MHz, k20MHz }; void setClock(Clock clk);