Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add window-app for the nrfconnect platform #17678

Merged
merged 9 commits into from
May 5, 2022
19 changes: 3 additions & 16 deletions examples/window-app/nrfconnect/main/WindowCovering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ static k_timer sLiftTimer;
static k_timer sTiltTimer;
static constexpr uint32_t sMoveTimeoutMs{ 200 };

static constexpr uint32_t FromOneRangeToAnother(uint32_t aInMin, uint32_t aInMax, uint32_t aOutMin, uint32_t aOutMax,
uint32_t aInput)
{
const auto diffInput = aInMax - aInMin;
const auto diffOutput = aOutMax - aOutMin;
if (diffInput > 0)
{
return static_cast<uint32_t>(aOutMin + static_cast<uint64_t>(aInput - aInMin) * diffOutput / diffInput);
}
return 0;
}

WindowCovering::WindowCovering()
{
mLiftLED.Init(LIFT_STATE_LED);
Expand Down Expand Up @@ -319,9 +307,6 @@ void WindowCovering::SetBrightness(MoveType aMoveType, uint16_t aPosition)

uint8_t WindowCovering::PositionToBrightness(uint16_t aPosition, MoveType aMoveType)
{
static constexpr uint32_t sPercent100thsMin{ 0 };
static constexpr uint32_t sPercent100thsMax{ 10000 };

uint8_t pwmMin{};
markaj-nordic marked this conversation as resolved.
Show resolved Hide resolved
uint8_t pwmMax{};

Expand All @@ -336,5 +321,7 @@ uint8_t WindowCovering::PositionToBrightness(uint16_t aPosition, MoveType aMoveT
pwmMax = mTiltIndicator.GetMaxLevel();
markaj-nordic marked this conversation as resolved.
Show resolved Hide resolved
}

return FromOneRangeToAnother(sPercent100thsMin, sPercent100thsMax, pwmMin, pwmMax, aPosition);
AbsoluteLimits pwmLimits{ pwmMin, pwmMax };

return Percent100thsToValue(pwmLimits, aPosition);
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ static Percent100ths ValueToPercent100ths(AbsoluteLimits limits, uint16_t absolu
return ConvertValue(limits.open, limits.closed, WC_PERCENT100THS_MIN_OPEN, WC_PERCENT100THS_MAX_CLOSED, absolute);
}

static uint16_t Percent100thsToValue(AbsoluteLimits limits, Percent100ths relative)
{
return ConvertValue(WC_PERCENT100THS_MIN_OPEN, WC_PERCENT100THS_MAX_CLOSED, limits.open, limits.closed, relative);
}

static OperationalState ValueToOperationalState(uint8_t value)
{
switch (value)
Expand Down Expand Up @@ -378,6 +373,11 @@ bool IsPercent100thsValid(NPercent100ths percent100ths)
return true;
}

uint16_t Percent100thsToValue(AbsoluteLimits limits, Percent100ths relative)
{
return ConvertValue(WC_PERCENT100THS_MIN_OPEN, WC_PERCENT100THS_MAX_CLOSED, limits.open, limits.closed, relative);
}

uint16_t LiftToPercent100ths(chip::EndpointId endpoint, uint16_t lift)
{
uint16_t openLimit = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ LimitStatus CheckLimitState(uint16_t position, AbsoluteLimits limits);
bool IsPercent100thsValid(Percent100ths percent100ths);
bool IsPercent100thsValid(NPercent100ths npercent100ths);

uint16_t Percent100thsToValue(AbsoluteLimits limits, Percent100ths relative);

uint16_t LiftToPercent100ths(chip::EndpointId endpoint, uint16_t lift);
uint16_t Percent100thsToLift(chip::EndpointId endpoint, uint16_t percent100ths);
void LiftPositionSet(chip::EndpointId endpoint, NPercent100ths position);
Expand Down