Advertisement
tranthudo

app_device_config.c

Jun 4th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.62 KB | None | 0 0
  1. /*****************************************************************************
  2.  *
  3.  * MODULE:             JN-AN-1220 ZLO Sensor Demo
  4.  *
  5.  * COMPONENT:          app_device_config.c
  6.  *
  7.  * DESCRIPTION:        DK4 (DR1175) Button Press detection (Implementation)
  8.  *
  9.  ****************************************************************************
  10.  *
  11.  * This software is owned by NXP B.V. and/or its supplier and is protected
  12.  * under applicable copyright laws. All rights are reserved. We grant You,
  13.  * and any third parties, a license to use this software solely and
  14.  * exclusively on NXP products [NXP Microcontrollers such as JN5168, JN5179].
  15.  * You, and any third parties must reproduce the copyright and warranty notice
  16.  * and any other legend of ownership on each copy or partial copy of the
  17.  * software.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  23.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29.  * POSSIBILITY OF SUCH DAMAGE.
  30.  *
  31.  * Copyright NXP B.V. 2017. All rights reserved
  32.  *
  33.  ***************************************************************************/
  34.  
  35. /****************************************************************************/
  36. /***        Include files                                                 ***/
  37. /****************************************************************************/
  38. #include <jendefs.h>
  39. #include "dbg.h"
  40. #include "PDM_IDs.h"
  41. #include "app_device_config.h"
  42. #include "app_sensor_node.h"
  43.  
  44. /****************************************************************************/
  45. /***        Macro Definitions                                             ***/
  46. /****************************************************************************/
  47. #ifndef DEBUG_APP_DEVICE_CONFIG
  48.     #define TRACE_APP_DEVICE_CONFIG               FALSE
  49. #else
  50.     #define TRACE_APP_DEVICE_CONFIG               TRUE
  51. #endif
  52.  
  53. /****************************************************************************/
  54. /***        Type Definitions                                              ***/
  55. /****************************************************************************/
  56. /****************************************************************************/
  57. /***        Local Function Prototypes                                     ***/
  58. /****************************************************************************/
  59. PRIVATE tsDeviceConfig sDeviceConfig;
  60.  
  61. /****************************************************************************/
  62. /***        Exported Variables                                            ***/
  63. /****************************************************************************/
  64.  
  65. /****************************************************************************/
  66. /***        Local Variables                                               ***/
  67. /****************************************************************************/
  68.  
  69. /****************************************************************************/
  70. /***        Exported Functions                                            ***/
  71. /****************************************************************************/
  72. /****************************************************************************
  73.  *
  74.  * NAME: bDeviceConfig_UpdateConfig
  75.  *
  76.  * DESCRIPTION:
  77.  * Update device config when initialization or receiving new config
  78.  *
  79.  * PARAMETER:
  80.  *
  81.  * RETURNS:
  82.  *
  83.  ****************************************************************************/
  84. PUBLIC BOOL_T bDeviceConfig_UpdateConfig(uint8 u8ParamId,
  85.                                          void* pParam)
  86. {
  87.     uint8 u8UpdateMask = 0;
  88.  
  89.     /* Store new config to flash */
  90.     switch (u8ParamId)
  91.     {
  92. #ifdef DEVICE_CONFIG_LED_INTENSITY_BIT
  93.         case DEVICE_CONFIG_LED_INTENSITY_BIT:
  94.             sDeviceConfig.sDeviceConfigParams.u8LedIntensity = *((uint8*) pParam);
  95.             u8UpdateMask = DEVICE_CONFIG_LED_INTENSITY_BIT;
  96.             break;
  97. #endif
  98.  
  99. #ifdef DEVICE_CONFIG_VIBRATION_INTENSITY_BIT
  100.         case DEVICE_CONFIG_VIBRATION_INTENSITY_BIT:
  101.             sDeviceConfig.sDeviceConfigParams.u8VibrationIntensity = *((uint8*) pParam);
  102.             u8UpdateMask = DEVICE_CONFIG_VIBRATION_INTENSITY_BIT;
  103.         break;
  104. #endif
  105.  
  106.         default:
  107.             return FALSE;
  108.     }
  109.  
  110.     PDM_eSaveRecordData(PDM_ID_DEVICE_CONFIG,
  111.                         &sDeviceConfig.sDeviceConfigParams,
  112.                         sizeof(sDeviceConfig.sDeviceConfigParams));
  113.  
  114.  
  115.     /* Call callback function to apply config */
  116.     if (sDeviceConfig.pCallbackFunction == NULL)
  117.         return FALSE;
  118.  
  119.     sDeviceConfig.pCallbackFunction(u8UpdateMask, &sDeviceConfig.sDeviceConfigParams);
  120.  
  121.     return TRUE;
  122. }
  123.  
  124. /****************************************************************************
  125.  *
  126.  * NAME: vDeviceConfig_UpdateConfig
  127.  *
  128.  * DESCRIPTION:
  129.  * An Sensor specific Debounce task. In the real world this maybe
  130.  * removed as the digital input will be driven from a sensor.
  131.  *
  132.  * PARAMETER:
  133.  *
  134.  * RETURNS:
  135.  *
  136.  ****************************************************************************/
  137. PUBLIC BOOL_T bDeviceConfig_LoadConfig(tsCLD_Basic* psBasicServerCluster)
  138. {
  139.     uint16 u16BytesRead = 0;
  140.     uint8  u8UpdateMask = 0;
  141.  
  142.     if (psBasicServerCluster == NULL)
  143.         return FALSE;
  144.  
  145.     /* Load device config from memory */
  146.     PDM_eReadDataFromRecord(PDM_ID_DEVICE_CONFIG,
  147.                             &sDeviceConfig.sDeviceConfigParams,
  148.                             sizeof(sDeviceConfig.sDeviceConfigParams),
  149.                             &u16BytesRead);
  150.  
  151.     /* Update value to basic cluster */
  152. #ifdef CLD_BAS_ATTR_MAN_SPEC_LED_INTENSITY
  153.     psBasicServerCluster->u8LedIntensity = sDeviceConfig.sDeviceConfigParams.u8LedIntensity;
  154.     u8UpdateMask |= DEVICE_CONFIG_LED_INTENSITY_BIT;
  155.  
  156.     DBG_vPrintf(TRUE, "\nLED Intensity: %d", psBasicServerCluster->u8LedIntensity);
  157. #endif
  158.  
  159. #ifdef CLD_BAS_ATTR_MAN_SPEC_VIBRATION_INTENSITY
  160.     psBasicServerCluster->u8VibrationIntensity     = sDeviceConfig.sDeviceConfigParams.u8VibrationIntensity;
  161.     u8UpdateMask |= DEVICE_CONFIG_VIBRATION_INTENSITY_BIT;
  162.  
  163.     DBG_vPrintf(TRUE, "\nVibration Intensity: %d", psBasicServerCluster->u8VibrationIntensity);
  164. #endif
  165.  
  166.     /* Call callback function to apply config */
  167.     if (sDeviceConfig.pCallbackFunction == NULL)
  168.         return FALSE;
  169.  
  170.     sDeviceConfig.pCallbackFunction(u8UpdateMask, &sDeviceConfig.sDeviceConfigParams);
  171.  
  172.     return TRUE;
  173. }
  174.  
  175. /****************************************************************************
  176.  *
  177.  * NAME: bDeviceConfig_RegisterCallback
  178.  *
  179.  * DESCRIPTION:
  180.  * Register callback for device config purpose
  181.  *
  182.  * PARAMETER:
  183.  *
  184.  * RETURNS:
  185.  *
  186.  ****************************************************************************/
  187. PUBLIC BOOL_T bDeviceConfig_RegisterCallback(tfpDeviceConfigCb pfCallBack)
  188. {
  189.     if (pfCallBack == NULL)
  190.         return FALSE;
  191.  
  192.     sDeviceConfig.pCallbackFunction = pfCallBack;
  193.     return TRUE;
  194. }
  195.  
  196. /****************************************************************************/
  197. /***        Local Functions                                               ***/
  198. /****************************************************************************/
  199.  
  200. /****************************************************************************/
  201. /***        END OF FILE                                                   ***/
  202. /****************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement