Skip to content

Wrong packet_duration calculation #27

Description

@Larsvn

Code
Consider this code fragment in your version v0.2.2:

uint8_t MSB = (Duration & 0xFF) >> 8;
uint8_t LSB = Duration & 0xFF;
// 1st bit, set 3D or Dual
if(mode == eRunMode::Mode3D) MSB |= (1 << 4);
// 2nd bit, set Auto or Fixed
if(setAutoDuration == false) MSB |= (1 << 3);

Problems

  • uint8_t MSB = (Duration & 0xFF) >> 8;
    Results in MSB = 0 at all times. So the higher part of the duration is lost.

  • bit adjustment for different modes is on wrong bits with wrong values

Suggested fixes

`
// Reset the highest two bits of Duration and mask out the lower byte,
// then shift right.
uint8_t MSB = (Duration & 0x3F00) >> 8;
uint8_t LSB = Duration & 0xFF;

// 1st bit, set 3D or Dual
if(mode == eRunMode::ModeDual) MSB |= (1 << 7);
// 2nd bit, set Auto or Fixed
if(setAutoDuration == false) MSB |= (1 << 6);
`

Referenced manual
Screenshot from this manual:
Set_3D_Pulse_Duration

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions