Giter Site home page Giter Site logo

flugkatze's People

Contributors

ch3nt3 avatar

Watchers

 avatar

flugkatze's Issues

No need to wait after Wire.requestFrom().

In the file "flugkatze/flightcontroller/v2_stm32/IMU.cpp", in the function "IMU::update()", there are two Wire.endTransmission() after each other. The second one is a Wire.endTransmission() on its own, and that is not allowed.

The function "IMU::getAddedRegisters()" is very complex, but all that timeout code is not needed. There is no such thing as a timeout after a Wire.requestFrom().
Explanation: Common-mistakes#1

When shifing 8 bits to the left, I prefer to do that with a 16 bits variable.
If the Wire.available() tells that there are enough data bytes available, they can be read and will be valid (they will be 0...255). Only in case there is no data, then the Wire.read() will return -1.

uint16_t IMU::getAddedRegisters() {
  uint16_t reg1, reg2;
  if (Wire.available() >= 2) {   // still enough data in the buffer ?
    reg1 = (uint16_t) Wire.read();
    reg2 = (uint16_t) Wire.read();
  } else {
    return 0;  // return zero in case of a I2C bus error
  }
  return (reg1 << 8 |reg2);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.