1. /**
    2. * @Author: jinlu
    3. * @file name: device_config_load.h
    4. * @Copyright: HANGZHOU TUYA INFORMATION TECHNOLOGY CO.,LTD
    5. * @Company: http://www.tuya.com
    6. */
    7. #ifndef __DEVICE_CONFIG_LOAD__
    8. #define __DEVICE_CONFIG_LOAD__
    9. #include "stdio.h"
    10. #include "stdlib.h"
    11. #include "light_types.h"
    12. #include "light_cfg.h"
    13. #ifdef __cplusplus
    14. extern "C" {
    15. #endif /* __cplusplus */
    16. typedef enum{
    17. CMOD_C = 0x01,
    18. CMOD_CW = 0x02,
    19. CMOD_RGB = 0x03,
    20. CMOD_RGBC = 0x04,
    21. CMOD_RGBCW = 0x05
    22. }CMODE_T;
    23. typedef enum{
    24. DMOD_PWM = 0x00,
    25. DMOD_IIC_SM16726 = 0x01,
    26. DMOD_IIC_SM2135 = 0x02,
    27. DMOD_IIC_SM2135EH = 0x03,
    28. DMOD_IIC_SM2135EJ = 0x04,
    29. DMOD_IIC_NP1658CJ = 0x05
    30. }DMODE_T;
    31. typedef enum{
    32. GWCM_OLD = 0x00,
    33. GWCM_LOW_POWER = 0x01,
    34. GWCM_SPCL_MODE = 0x02,
    35. GWCM_OLD_PROD = 0x03,
    36. GWCM_SPCL_AUTOCFG = 0x05
    37. }WFCFG_T;
    38. typedef enum{
    39. COLOR_C = 0x00,
    40. COLOR_W = 0x01,
    41. COLOR_R = 0x02,
    42. COLOR_G = 0x03,
    43. COLOR_B = 0x04,
    44. COLOR_RGB = 0x05
    45. }COLOR_T;
    46. typedef enum{
    47. CW_TYPE = 0,
    48. CCT_TYPE = 1
    49. }CWTYPE_T;
    50. typedef enum{
    51. CHANGE_GRADUALLY = 0,
    52. CHANGE_DIRECTLY = 1
    53. }ONOFFMODE_T;
    54. typedef enum{
    55. MEM_SAVE_NOT = 0,
    56. MEM_SAVE = 1
    57. }MEMORY_T;
    58. #pragma pack(1)
    59. typedef struct {
    60. //common
    61. CHAR_T Jsonver[5]; // json version
    62. CHAR_T category[5]; // ble(sigmesh) dedicated
    63. //device function
    64. CHAR_T module[15]; // module choosed for the light
    65. CHAR_T cmod[6]; // Color model: 1 -> C; 2 -> CW; 3 -> RGB; 4 -> RGBC; 5 ->RGBCW;
    66. UCHAR_T dmod; // Color driver mode: 0->pwm; 1->sm16726b; 2->sm2135;
    67. UCHAR_T cwtype; // Color temperature drive mode: 0 -> CW; 1: -> CCT;
    68. UCHAR_T onoffmode; // Is there a gradient when switching: 0 -> turn on gradually; 1 -> turn ondirectly;
    69. UCHAR_T pmemory; // Is there a power-off memory: 1 -> save app data; 0 -> don't save
    70. UCHAR_T ctrl_pin; // CTRL pin:
    71. UCHAR_T ctrl_lv; // CTRL pin level
    72. //light config
    73. CHAR_T defcolor; // light color after connected
    74. UCHAR_T defbright; // light brightness after connected
    75. UCHAR_T deftemp; // light default temperature
    76. UCHAR_T cwmaxp; // Maximum Power configuration of Cold and warm Light mixing
    77. UCHAR_T brightmin; // Minimum brightness: 1~100
    78. UCHAR_T brightmax; // Maximum brightness: 1~100
    79. UCHAR_T colormax; // Minimum brightness: 1~100
    80. UCHAR_T colormin; // Maximum brightness: 1~100
    81. //connection config
    82. CHAR_T wfcfg[10]; // Low power / flash, value: spcl,prod
    83. UCHAR_T remdmode; // light reset pairing mode
    84. UCHAR_T rstnum; // number of times required to reset by switching on and off
    85. CHAR_T rstcor; // light color while connecting
    86. UCHAR_T rstbr; // light brightness while connecting
    87. UCHAR_T rsttemp; // light brightness while connecting
    88. USHORT_T remdtime; // light reset pairing reminde time,unit:sec
    89. UCHAR_T wfptime; // light pairing time,unit:min
    90. //pwm config
    91. UINT_T pwmhz; // PWM frequency
    92. UCHAR_T r_pin; // Red color control pin
    93. UCHAR_T r_lv; // Red color control pin level
    94. UCHAR_T g_pin; // Green color control pin
    95. UCHAR_T g_lv; // Green color control pin level
    96. UCHAR_T b_pin; // Blue color control pin
    97. UCHAR_T b_lv; // Blue color control pin level
    98. UCHAR_T c_pin; // Cold white color control pin
    99. UCHAR_T c_lv; // Cold white color control pin level
    100. UCHAR_T w_pin; // Warm white color control pin
    101. UCHAR_T w_lv; // Warm white color control pin level
    102. #if(LIGHT_CFG_SUPPORT_LOWPOWER == 1)
    103. UCHAR_T title20; // title20 flag: 0 -> don't support T20; 1 -> support T20
    104. #endif
    105. #if LIGHT_CFG_ENABLE_GAMMA
    106. //Gamma param
    107. UCHAR_T ucGammaRedbuf;
    108. UCHAR_T ucGammaGreenbuf;
    109. UCHAR_T ucGammaBluebuf;
    110. #endif
    111. #if (LIGHT_CFG_GAMMA_CAL == 1)
    112. UCHAR_T gammakr;
    113. UCHAR_T gammakg;
    114. UCHAR_T gammakb;
    115. UCHAR_T gammawr;
    116. UCHAR_T gammawg;
    117. UCHAR_T gammawb;
    118. #endif
    119. }DEVICE_CONFIG_T;
    120. #pragma pack()
    121. /**
    122. * @brief: set device configuration data.
    123. * @param {IN DEVICE_CONFIG_T *ptConfig -> light cfg data}
    124. * @retval: OPERATE_LIGHT
    125. */
    126. OPERATE_LIGHT opDeviceCfgDataDefaultSet(IN DEVICE_CONFIG_T *ptConfig);
    127. /**
    128. * @brief: set device configuration data.
    129. * @param {IN USHORT_T usLen -> oem cfg len}
    130. * @param {IN CHAR_T *pConfig -> oem cfg data}
    131. * @retval: OPERATE_LIGHT
    132. */
    133. OPERATE_LIGHT opDeviceCfgDataSet(IN USHORT_T usLen, IN CONST CHAR_T *pConfig);
    134. /**
    135. * @brief: load device configuration data.
    136. * @param {none}
    137. * @retval: OPERATE_LIGHT
    138. */
    139. OPERATE_LIGHT opDeviceCfgDataLoad(VOID);
    140. /**
    141. * @brief: get json version string
    142. * @param {out UCHAR_T *pJsonVer -> json version string }
    143. * @retval: OPERATE_LIGHT
    144. */
    145. CHAR_T cDeviceCfgGetJsonVer(OUT CHAR_T *pJsonVer);
    146. /**
    147. * @brief: get json config data :category
    148. * @param {OUT CHAR_T *pCategory -> category}
    149. * @retval: OPERATE_LIGHT
    150. */
    151. CHAR_T cDeviceCfgGetCategory(OUT CHAR_T *pCategory);
    152. /**
    153. * @brief: get json config data: module name string.
    154. * @param {out} module: module name string.
    155. * @param {out} len: length of module name string.
    156. * @retval: OPERATE_LIGHT
    157. */
    158. CHAR_T cDeviceCfgGetModule(OUT CHAR_T *pModule, OUT UCHAR_T *pLen);
    159. /**
    160. * @brief: get color mode -- production is RGBCW/RGBC/RGB/CW/C
    161. * @param {type} none
    162. * @return:
    163. * 0x01 -> C,
    164. * 0x02 -> CW
    165. * 0x03 -> RGB
    166. * 0x04 -> RGBC
    167. * 0x05 -> RGBCW
    168. * -1 -> not find light way,error
    169. */
    170. CHAR_T cDeviceCfgGetColorMode(VOID);
    171. /**
    172. * @brief: get json config data: driver mode
    173. * @param {type} none
    174. * @return:
    175. * 0x00 -> PWM
    176. * 0x01 -> SM16726B
    177. * 0x02 -> SM2135
    178. * -1 -> configure not load, error
    179. */
    180. CHAR_T cDeviceCfgGetDriverMode(VOID);
    181. /**
    182. * @brief: get json config data: cwtype
    183. * @param {type} none
    184. * @return:
    185. * 0x00 -> CW drive
    186. * 0x01 -> CCT drive
    187. * -1 -> configure not load, error
    188. */
    189. CHAR_T cDeviceCfgGetCWType(VOID);
    190. /**
    191. * @brief: get json config data: onoffmode
    192. * @param {type} none
    193. * @return:
    194. * 0x00 -> turn on/off change gradually
    195. * 0x01 -> turn on/off change directly
    196. * -1 -> configure not load, error
    197. */
    198. CHAR_T cDeviceCfgGetOnOffMode(VOID);
    199. /**
    200. * @brief: get memory cfg -- if not save app control data
    201. * @param {type} none
    202. * @return:
    203. * 0x00 -> don't save app data in flash
    204. * 0x01 -> save app data in flash
    205. * -1 -> configure not load, error
    206. */
    207. CHAR_T cDeviceCfgGetPmemoryCfg(VOID);
    208. /**
    209. * @brief: get ctrl pin number
    210. * @param {type} none
    211. * @return: ctrl pin number, -1 -> configure not load, error
    212. */
    213. CHAR_T cDeviceCfgGetCtrlPin(VOID);
    214. /**
    215. * @brief: get ctrl pin level
    216. * @param {type} none
    217. * @return: ctrl pin level, -1 -> configure not load, error
    218. */
    219. CHAR_T cDeviceCfgGetCtrlPinLevel(VOID);
    220. /**
    221. * @brief: get title20 flag
    222. * @param {type} none
    223. * @return:
    224. * 0x00 -> don't support lowpower mode
    225. * 0x01 -> support lowpower mode
    226. * -1 -> configure not load, error
    227. */
    228. CHAR_T cDeviceCfgGetTitle20(VOID);
    229. /**
    230. * @brief: get json config data: color set when connected.
    231. * @param {type} none
    232. * @return:
    233. * 0x00 -> default bright is C when connected.
    234. * 0x01 -> default bright is W when connected.
    235. * 0x02 -> default bright is R when connected.
    236. * 0x03 -> default bright is G when connected.
    237. * 0x04 -> default bright is B when connected.
    238. * -1 -> configure not load, error
    239. */
    240. CHAR_T cDeviceCfgGetDefColor(VOID);
    241. /**
    242. * @brief: get json config data: brightness when connected.
    243. * @param {type} none
    244. * @return: brightness, -1 -> configure not load, error
    245. */
    246. CHAR_T cDeviceCfgGetDefBrightness(VOID);
    247. /**
    248. * @brief: get json config data: deftemp when connected.
    249. * @param {type} none
    250. * @return: default temperature when connected. -1 -> configure not load, error
    251. */
    252. CHAR_T cDeviceCfgGetDefTemperature(VOID);
    253. /**
    254. * @brief: get json config data: white max power
    255. * @param {type} none
    256. * @return: white max power, -1 -> configure not load, error
    257. */
    258. CHAR_T cDeviceCfgGetCWMaxPower(VOID);
    259. /**
    260. * @brief: get the CW minimum brightness
    261. * @param {type} none
    262. * @return: CW minimum brightness, -1 -> configure not load, error
    263. */
    264. CHAR_T cDeviceCfgGetWhiteMin(VOID);
    265. /**
    266. * @brief: get the CW maxinum brightness
    267. * @param {type} none
    268. * @return: CW maxinum brightness,-1 -> configure not load, error
    269. */
    270. CHAR_T cDeviceCfgGetWhiteMax(VOID);
    271. /**
    272. * @brief: get the RGB minimum brightness
    273. * @param {type} none
    274. * @return: RGB mininum brightness,-1 -> configure not load, error
    275. */
    276. CHAR_T cDeviceCfgGetColorMin(VOID);
    277. /**
    278. * @brief: get the RGB maxinum brightness
    279. * @param {type} none
    280. * @return: RGB maxinum brightness,-1 -> configure not load, error
    281. */
    282. CHAR_T cDeviceCfgGetColorMax(VOID);
    283. /**
    284. * @brief: get wifi pair mode config
    285. * @param {type} none
    286. * @return:
    287. * GWCM_OLD ->
    288. * GWCM_LOW_POWER ->
    289. * GWCM_SPCL_MODE ->
    290. * GWCM_OLD_PROD ->
    291. * -1 -> not find, error
    292. */
    293. CHAR_T cDeviceCfgGetWificfg(VOID);
    294. /**
    295. * @brief: remind mode when pairing(blink or breath)
    296. * @param {type} none
    297. * @return:
    298. */
    299. CHAR_T cDeviceCfgGetRemindMode(VOID);
    300. /**
    301. * @brief: get pairing reset number.
    302. * @param {type} none
    303. * @return: reset number,-1 -> configure not load, error
    304. */
    305. CHAR_T cDeviceCfgGetResetNum(VOID);
    306. /**
    307. * @brief: get color set when pairing.
    308. * @param {type} none
    309. * @return:
    310. * 0x00 -> default bright is C when pairing.
    311. * 0x01 -> default bright is W when pairing.
    312. * 0x02 -> default bright is R when pairing.
    313. * 0x03 -> default bright is G when pairing.
    314. * 0x04 -> default bright is B when pairing.
    315. * -1 -> not find, error
    316. */
    317. CHAR_T cDeviceCfgGetResetColor(VOID);
    318. /**
    319. * @brief: get reset brightness when pairing
    320. * @param {type} none
    321. * @return: brightness when pairing,-1 -> not find, error
    322. */
    323. CHAR_T cDeviceCfgGetResetBrightness(VOID);
    324. /**
    325. * @brief: get reset temperature(reset color is white) when pairing
    326. * @param {type} none
    327. * @return: reset temperature(reset color is white) when pairing,-1 -> not find, error
    328. */
    329. CHAR_T cDeviceCfgGetResetTemperature(VOID);
    330. /**
    331. * @brief: get remind time when remind mode is breathing,unit:sec
    332. * @param {type} none
    333. * @return:remind time
    334. */
    335. SHORT_T sDeviceCfgGetRemindTime(VOID);
    336. /**
    337. * @brief: get pairing time,unit:min
    338. * @param {type} none
    339. * @return: pairting time
    340. */
    341. CHAR_T cDeviceCfgGetPairingTime(VOID);
    342. /**
    343. * @brief: get pwm frequency
    344. * @param {type} none
    345. * @return: pwm frequency,-1 -> not find, error
    346. */
    347. USHORT_T usDeviceCfgGetPwmHz(VOID);
    348. /**
    349. * @brief: get red pin number
    350. * @param {type} none
    351. * @return: red pin number,-1 -> not find, error
    352. */
    353. CHAR_T cDeviceCfgGetRedPin(VOID);
    354. /**
    355. * @brief: get red pin effective level.
    356. * @param {type} none
    357. * @return: red pin effective level,-1 -> not find, error
    358. */
    359. CHAR_T cDeviceCfgGetRedPinLevel(VOID);
    360. /**
    361. * @brief: get green pin number
    362. * @param {type} none
    363. * @return: green pin number,-1 -> not find, error
    364. */
    365. CHAR_T cDeviceCfgGetGreenPin(VOID);
    366. /**
    367. * @brief: get green pin effective level.
    368. * @param {type} none
    369. * @return: green pin effective level,-1 -> not find, error
    370. */
    371. CHAR_T cDeviceCfgGetGreenPinLevel(VOID);
    372. /**
    373. * @brief: get blue pin number
    374. * @param {type} none
    375. * @return: blue pin number,-1 -> not find, error
    376. */
    377. CHAR_T cDeviceCfgGetBluePin(VOID);
    378. /**
    379. * @brief: get blue pin effective level.
    380. * @param {type} none
    381. * @return: blue pin effective level,-1 -> not find, error
    382. */
    383. CHAR_T cDeviceCfgGetBluePinLevel(VOID);
    384. /**
    385. * @brief: get cold white pin number
    386. * @param {type} none
    387. * @return: cold white pin number,-1 -> not find, error
    388. */
    389. CHAR_T cDeviceCfgGetColdPin(VOID);
    390. /**
    391. * @brief: get cold white pin pin effective level.
    392. * @param {type} none
    393. * @return: cold white pin effective level,-1 -> not find, error
    394. */
    395. CHAR_T cDeviceCfgGetColdPinLevel(VOID);
    396. /**
    397. * @brief: get warm white pin number
    398. * @param {type} none
    399. * @return: warm white pin number
    400. */
    401. CHAR_T cDeviceCfgGetWarmPin(VOID);
    402. /**
    403. * @brief: get warm white effective level.
    404. * @param {type} none
    405. * @return: warm white pin effective level,-1 -> not find, error
    406. */
    407. CHAR_T cDeviceCfgGetWarmPinLevel(VOID);
    408. #if (LIGHT_CFG_ENABLE_GAMMA == 1)
    409. /**
    410. * @brief: get red gamma
    411. * @param {type} none
    412. * @return: red gamma
    413. */
    414. UCHAR_T ucDeviceCfgGetGammaRed(IN UCHAR_T ucIndex);
    415. /**
    416. * @brief: get green gamma
    417. * @param {type} none
    418. * @return: green gamma
    419. */
    420. UCHAR_T ucDeviceCfgGetGammaGreen(IN UCHAR_T ucIndex);
    421. /**
    422. * @brief: get blue gamma
    423. * @param {type} none
    424. * @return: blue gamma
    425. */
    426. UCHAR_T ucDeviceCfgGetGammaBlue(IN UCHAR_T ucIndex);
    427. #endif
    428. #ifdef __cplusplus
    429. }
    430. #endif /* __cplusplus */
    431. #endif /* __DEVICE_CONFIG_LOAD__ */