Skip to content

Commit

Permalink
add cluster to switch temperature units C/F
Browse files Browse the repository at this point in the history
  • Loading branch information
devbis committed Nov 2, 2023
1 parent 8307a9b commit f142a34
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/app_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ extern "C" {
//#define ZCL_IAS_ZONE_SUPPORT 1
#define ZCL_TEMPERATURE_MEASUREMENT_SUPPORT 1
#define ZCL_RELATIVE_HUMIDITY_SUPPORT 1
#define ZCL_ZCL_THERMOSTAT_UI_CFG_SUPPORT 1
//#define ZCL_POLL_CTRL_SUPPORT 1
#define ZCL_OTA_SUPPORT 1

Expand All @@ -163,6 +164,10 @@ extern "C" {
#define ZCL_RELATIVE_HUMIDITY
#define ZCL_RELATIVE_HUMIDITY_MEASUREMENT
#endif
#if ZCL_THERMOSTAT_UI_CFG_SUPPORT
#define ZCL_THERMOSTAT_UI_CFG
#endif


#define DEFAULT_POLL_RATE (10 * (4 * POLL_RATE_QUARTERSECONDS))

Expand Down
34 changes: 34 additions & 0 deletions src/custom_zcl/zcl_thermostat_ui_cfg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

/**********************************************************************
* INCLUDES
*/
#include "zcl_include.h"


#ifdef ZCL_THERMOSTAT_UI
/**********************************************************************
* LOCAL CONSTANTS
*/


/**********************************************************************
* LOCAL TYPES
*/


/**********************************************************************
* LOCAL VARIABLES
*/


/**********************************************************************
* LOCAL FUNCTIONS
*/

_CODE_ZCL_ status_t zcl_thermostat_ui_cfg_register(u8 endpoint, u16 manuCode, u8 attrNum, const zclAttrInfo_t attrTbl[], cluster_forAppCb_t cb)
{
return zcl_registerCluster(endpoint, ZCL_CLUSTER_HAVC_USER_INTERFACE_CONFIG, manuCode, attrNum, attrTbl, NULL, cb);
}

#endif /* ZCL_THERMOSTAT_UI */

18 changes: 18 additions & 0 deletions src/custom_zcl/zcl_thermostat_ui_cfg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#ifndef ZCL_THERMOSTAT_UI_CFG_H
#define ZCL_THERMOSTAT_UI_CFG_H

/*********************************************************************
* CONSTANTS
*/

/**
* @brief thermostatu UI configuration cluster Attribute IDs
*/
#define ZCL_THERMOSTAT_UI_CFG_ATTRID_TEMPERATUREDISPLAYMODE 0x0000
#define ZCL_THERMOSTAT_UI_CFG_ATTRID_KEYPADLOCKOUT 0x0001
#define ZCL_THERMOSTAT_UI_CFG_ATTRID_SCHEDULEPROGRAMMINGVISIBILITY 0x0002

// status_t zcl_relative_humidity_register(u8 endpoint, u16 manuCode, u8 attrNum, const zclAttrInfo_t attrTbl[], cluster_forAppCb_t cb);

#endif /* ZCL_THERMOSTAT_UI_CFG_H */
13 changes: 11 additions & 2 deletions src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,18 @@ void read_sensor_and_save() {
g_zcl_powerAttrs.batteryVoltage = converted_voltage;
g_zcl_powerAttrs.batteryPercentage = percentage2;

s16 displayTemperature = g_zcl_temperatureAttrs.measuredValue / 10;
u8 tempSymbol = 1;

if (g_zcl_thermostatUICfgAttrs.displayMode == 1) {
// TODO: convert to fahrenheits
s16 displayTemperature = (s16)(((s32)g_zcl_temperatureAttrs.measuredValue * 9) / (5*10) + 320);
u8 tempSymbol = 2;
}

// update lcd
show_temp_symbol(1);
show_big_number(g_zcl_temperatureAttrs.measuredValue / 10, 1);
show_temp_symbol(tempSymbol);
show_big_number(displayTemperature, 1);
show_small_number(g_zcl_relHumidityAttrs.measuredValue / 100, 1);
#if defined(SHOW_SMILEY)
show_smiley(
Expand Down
8 changes: 8 additions & 0 deletions src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ typedef struct {
u16 tolerance;
}zcl_relHumidityAttr_t;

/**
* @brief Defined for thermostat UI config cluster attributes
*/
typedef struct {
u8 displayMode;
}zcl_thermostatUICfgAttr_t;


/**
* @brief Defined for poll control cluster attributes
Expand Down Expand Up @@ -126,6 +133,7 @@ extern const af_simple_descriptor_t sensorDevice_simpleDesc;
extern zcl_basicAttr_t g_zcl_basicAttrs;
extern zcl_identifyAttr_t g_zcl_identifyAttrs;
extern zcl_powerAttr_t g_zcl_powerAttrs;
extern zcl_thermostatUICfgAttr_t g_zcl_thermostatUICfgAttrs;
extern zcl_temperatureAttr_t g_zcl_temperatureAttrs;
extern zcl_relHumidityAttr_t g_zcl_relHumidityAttrs;
// extern zcl_iasZoneAttr_t g_zcl_iasZoneAttrs;
Expand Down
22 changes: 21 additions & 1 deletion src/sensorEpCfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,22 @@ const zclAttrInfo_t relative_humdity_attrTbl[] =
#define ZCL_RELATIVE_HUMIDITY_ATTR_NUM sizeof(relative_humdity_attrTbl) / sizeof(zclAttrInfo_t)
#endif

#ifdef ZCL_THERMOSTAT_UI_CFG
zcl_thermostatUICfgAttr_t g_zcl_thermostatUICfgAttrs =
{
.displayMode = 0x0000,
};

const zclAttrInfo_t thermostat_ui_cfg_attrTbl[] =
{
{ ZCL_THERMOSTAT_UI_CFG_ATTRID_TEMPERATUREDISPLAYMODE, ZCL_DATA_TYPE_ENUM8, ACCESS_CONTROL_READ | ACCESS_CONTROL_WRITE, (u8*)&g_zcl_thermostatUICfgAttrs.displayMode },

{ ZCL_ATTRID_GLOBAL_CLUSTER_REVISION, ZCL_DATA_TYPE_UINT16, ACCESS_CONTROL_READ, (u8*)&zcl_attr_global_clusterRevision},
};

#define ZCL_THERMOSTAT_UI_CFG_ATTR_NUM sizeof(thermostat_ui_cfg_attrTbl) / sizeof(zclAttrInfo_t)
#endif


#ifdef ZCL_POLL_CTRL
/* Poll Control */
Expand Down Expand Up @@ -288,7 +304,11 @@ const zcl_specClusterInfo_t g_sensorDeviceClusterList[] =
{ZCL_CLUSTER_MS_TEMPERATURE_MEASUREMENT, MANUFACTURER_CODE_NONE, ZCL_TEMPERATURE_MEASUREMENT_ATTR_NUM, temperature_measurement_attrTbl, zcl_temperature_measurement_register, NULL},
#endif
#ifdef ZCL_RELATIVE_HUMIDITY
{ZCL_CLUSTER_MS_RELATIVE_HUMIDITY, MANUFACTURER_CODE_NONE, ZCL_RELATIVE_HUMIDITY_ATTR_NUM, relative_humdity_attrTbl, zcl_relative_humidity_register, NULL},
{ZCL_CLUSTER_MS_RELATIVE_HUMIDITY, MANUFACTURER_CODE_NONE, ZCL_RELATIVE_HUMIDITY_ATTR_NUM, relative_humdity_attrTbl, zcl_relative_humidity_register, NULL},
#endif
#ifdef ZCL_THERMOSTAT_UI_CFG
// typo in SDK
{ZCL_CLUSTER_HAVC_USER_INTERFACE_CONFIG, MANUFACTURER_CODE_NONE, ZCL_THERMOSTAT_UI_CFG_ATTR_NUM, thermostat_ui_cfg_attrTbl, zcl_thermostat_ui_cfg_register, NULL},
#endif
#ifdef ZCL_POLL_CTRL
{ZCL_CLUSTER_GEN_POLL_CONTROL, MANUFACTURER_CODE_NONE, ZCL_POLLCTRL_ATTR_NUM, pollCtrl_attrTbl, zcl_pollCtrl_register, sensorDevice_pollCtrlCb},
Expand Down

0 comments on commit f142a34

Please sign in to comment.