Skip to content

Commit

Permalink
save changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BorysNykytiuk committed Sep 10, 2024
1 parent da7181d commit e3e8322
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 182 deletions.
4 changes: 2 additions & 2 deletions examples/lighting-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ target_sources(app PRIVATE
${TELINK_COMMON}/common/src/mainCommon.cpp
${TELINK_COMMON}/common/src/AppTaskCommon.cpp
${TELINK_COMMON}/util/src/LEDManager.cpp
${TELINK_COMMON}/util/src/PWMManager.cpp
${TELINK_COMMON}/util/src/ButtonManager.cpp
${TELINK_COMMON}/util/src/ThreadUtil.cpp
${TELINK_COMMON}/util/src/ColorFormat.cpp
Expand All @@ -56,8 +57,7 @@ chip_configure_data_model(app

if(CONFIG_PWM)
target_sources(app PRIVATE
${TELINK_COMMON}/util/src/PWMManager.cpp
${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c)
${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c)
endif()

if(CONFIG_BOOTLOADER_MCUBOOT)
Expand Down

This file was deleted.

41 changes: 9 additions & 32 deletions examples/lighting-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
#include <app/server/Server.h>

#include "ColorFormat.h"
#ifdef CONFIG_PWM
#include "PWMManager.h"
#elif CONFIG_GPIO
#include "LEDManager.h" // Include your LED management header
#endif
#include "LEDManager.h"

#include <app-common/zap-generated/attributes/Accessors.h>

Expand Down Expand Up @@ -138,11 +135,8 @@ void AppTask::SetInitiateAction(Fixture_Action aAction, int32_t aActor, uint8_t
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, (((uint32_t) sLedRgb.r * 1000) / UINT8_MAX));
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, (((uint32_t) sLedRgb.g * 1000) / UINT8_MAX));
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, (((uint32_t) sLedRgb.b * 1000) / UINT8_MAX));
#elif CONFIG_GPIO
// Set GPIOs to turn on the fixture
LedManager::getInstance().setLed(LedManager::EAppLed_App0, true);
LedManager::getInstance().setLed(LedManager::EAppLed_App1, true);
LedManager::getInstance().setLed(LedManager::EAppLed_App2, true);
#else
LedManager::getInstance().setLed(LedManager::EAppLed_App0, true);
#endif
}
else
Expand All @@ -152,11 +146,8 @@ void AppTask::SetInitiateAction(Fixture_Action aAction, int32_t aActor, uint8_t
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, false);
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, false);
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, false);
#elif CONFIG_GPIO
// Set GPIOs to turn off the fixture
LedManager::getInstance().setLed(LedManager::EAppLed_App0, false);
LedManager::getInstance().setLed(LedManager::EAppLed_App1, false);
LedManager::getInstance().setLed(LedManager::EAppLed_App2, false);
#else
LedManager::getInstance().setLed(LedManager::EAppLed_App0, false);
#endif
}
}
Expand Down Expand Up @@ -215,15 +206,10 @@ void AppTask::SetInitiateAction(Fixture_Action aAction, int32_t aActor, uint8_t

if (setRgbAction)
{
#ifdef CONFIG_PWM
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, (((uint32_t) sLedRgb.r * 1000) / UINT8_MAX));
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, (((uint32_t) sLedRgb.g * 1000) / UINT8_MAX));
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, (((uint32_t) sLedRgb.b * 1000) / UINT8_MAX));
#elif CONFIG_GPIO
// Set GPIOs to change the color of the fixture
// Doeas not support color change
#endif
}
}
}

#ifdef CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET
Expand All @@ -237,15 +223,11 @@ void AppTask::PowerOnFactoryResetEventHandler(AppEvent * aEvent)
{
LOG_INF("Lighting App Power On Factory Reset Handler");
sPowerOnFactoryResetTimerCnt = 1;
#ifdef CONFIG_PWM
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, (bool) (sPowerOnFactoryResetTimerCnt % 2));
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, (bool) (sPowerOnFactoryResetTimerCnt % 2));
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, (bool) (sPowerOnFactoryResetTimerCnt % 2));
#elif CONFIG_GPIO
// Set GPIOs to indicate factory reset
LedManager::getInstance().setLed(LedManager::EAppLed_App0, false);
LedManager::getInstance().setLed(LedManager::EAppLed_App1, false);
LedManager::getInstance().setLed(LedManager::EAppLed_App2, false);
#if !CONFIG_PWM
LedManager::getInstance().setLed(LedManager::EAppLed_App0, false);
#endif
k_timer_init(&sPowerOnFactoryResetTimer, PowerOnFactoryResetTimerEvent, nullptr);
k_timer_start(&sPowerOnFactoryResetTimer, K_MSEC(kPowerOnFactoryResetIndicationTimeMs),
Expand All @@ -256,15 +238,10 @@ void AppTask::PowerOnFactoryResetTimerEvent(struct k_timer * timer)
{
sPowerOnFactoryResetTimerCnt++;
LOG_INF("Lighting App Power On Factory Reset Handler %u", sPowerOnFactoryResetTimerCnt);
#ifdef CONFIG_PWM
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, (bool) (sPowerOnFactoryResetTimerCnt % 2));
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, (bool) (sPowerOnFactoryResetTimerCnt % 2));
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, (bool) (sPowerOnFactoryResetTimerCnt % 2));
#elif CONFIG_GPIO
// Set GPIOs to indicate factory reset
// Doeas not support color change
#endif
if (sPowerOnFactoryResetTimerCnt > kPowerOnFactoryResetIndicationMax)
if (sPowerOnFactoryResetTimerCnt > kPowerOnFactoryResetIndicationMax)
{
k_timer_stop(timer);
LOG_INF("schedule factory reset");
Expand Down
43 changes: 4 additions & 39 deletions examples/platform/telink/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,41 +78,6 @@ endif()

set(GLOBAL_BOOT_CONF_OVERLAY_FILE "${BOOT_CONF_OVERLAY_FILE} ${BOOT_USB_CONF_OVERLAY_FILE}")

# Check if the current source directory is the lighting-app example
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CHIP_ROOT}/examples/lighting-app/telink)
set(PROJECT_CONFIG_FILE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/prj.conf")
set(LED_POOL_DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/boards/${BASE_BOARD}_led_pool.overlay")
# Initialize a flag
set(CONFIG_PWM_SET_TO_N OFF)
if(EXISTS "${PROJECT_CONFIG_FILE_PATH}")
# Read the configuration file content
file(READ "${PROJECT_CONFIG_FILE_PATH}" CONFIG_CONTENTS)
# Split the content into lines
string(REPLACE "\n" ";" CONFIG_LINES "${CONFIG_CONTENTS}")
# Iterate over each line and check
foreach(line IN LISTS CONFIG_LINES)
# Trim whitespace from the beginning and end of the line
string(STRIP "${line}" stripped_line)
# Check if the line contains the exact string without a leading comment
if(stripped_line MATCHES "^CONFIG_PWM=n")
set(CONFIG_PWM_SET_TO_N ON)
break() # Exit the loop early, since we found what we're looking for
endif()
endforeach()
# Output the result
if(CONFIG_PWM_SET_TO_N)
# Left it as is
set(LED_POOL_DTC_OVERLAY_FILE "${LED_POOL_DTC_OVERLAY_FILE}")
message(STATUS "${LED_POOL_DTC_OVERLAY_FILE} will be appended to DTC_OVERLAY_FILE")
else()
# Do not use the LED_POOL_DTC_OVERLAY_FILE
unset(LED_POOL_DTC_OVERLAY_FILE)
endif()
else()
message(STATUS "Project config file: ${PROJECT_CONFIG_FILE_PATH} doesn't exist")
endif()
endif()

set(LOCAL_DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/boards/${BASE_BOARD}.overlay")
if(NOT EXISTS "${LOCAL_DTC_OVERLAY_FILE}")
message(STATUS "${LOCAL_DTC_OVERLAY_FILE} doesn't exist")
Expand All @@ -136,11 +101,11 @@ endif()

if(DTC_OVERLAY_FILE)
set(DTC_OVERLAY_FILE
"${DTC_OVERLAY_FILE} ${GLOBAL_DTC_OVERLAY_FILE} ${USB_DTC_OVERLAY_FILE} ${MARS_DTC_OVERLAY_FILE} ${FLASH_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE} ${LED_POOL_DTC_OVERLAY_FILE}"
CACHE STRING "" FORCE)
"${DTC_OVERLAY_FILE} ${GLOBAL_DTC_OVERLAY_FILE} ${USB_DTC_OVERLAY_FILE} ${MARS_DTC_OVERLAY_FILE} ${FLASH_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE}"
CACHE STRING "" FORCE
)
else()
set(DTC_OVERLAY_FILE
${GLOBAL_DTC_OVERLAY_FILE} ${USB_DTC_OVERLAY_FILE} ${MARS_DTC_OVERLAY_FILE} ${FLASH_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE} ${LED_POOL_DTC_OVERLAY_FILE})
set(DTC_OVERLAY_FILE ${GLOBAL_DTC_OVERLAY_FILE} ${USB_DTC_OVERLAY_FILE} ${MARS_DTC_OVERLAY_FILE} ${FLASH_DTC_OVERLAY_FILE} ${LOCAL_DTC_OVERLAY_FILE})
endif()

if(NOT CONF_FILE)
Expand Down
2 changes: 0 additions & 2 deletions examples/platform/telink/common/include/AppTaskCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ class AppTaskCommon

void InitLeds();
virtual void LinkLeds(LedManager & ledManager);
#ifdef CONFIG_PWM
void InitPwms();
virtual void LinkPwms(PwmManager & pwmManager);
#endif
void InitButtons(void);
virtual void LinkButtons(ButtonManager & buttonManager);

Expand Down
Loading

0 comments on commit e3e8322

Please sign in to comment.