model_state_handler_pl.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**
  2. * \file model_state_handler_pl.c
  3. *
  4. *
  5. */
  6. /*
  7. * Copyright (C) 2013. Mindtree Limited.
  8. * All rights reserved.
  9. */
  10. /* --------------------------------------------- Header File Inclusion */
  11. #include "model_state_handler_pl.h"
  12. #include "led_light.h"
  13. /* --------------------------------------------- External Global Variables */
  14. /* --------------------------------------------- Exported Global Variables */
  15. /* --------------------------------------------- Static Global Variables */
  16. /* --------------------------------------------- Functions */
  17. void mesh_model_platform_init_pl(void)
  18. {
  19. /* Map Platform related initializations of GPIOs/LEDs etc here */
  20. }
  21. void mesh_model_device_bootup_ind_pl(void)
  22. {
  23. /* LED ON/OFF for BOOT UP Indication to be mapped here */
  24. }
  25. void mesh_model_device_provisioned_ind_pl(void)
  26. {
  27. /* LED ON/OFF for Provisioning Indication to be mapped here */
  28. }
  29. void generic_onoff_set_pl (UINT8 state)
  30. {
  31. /* LED ON/OFF for GENERIC ONOFF to be mapped here */
  32. if (state)
  33. {
  34. light_ctrl(LIGHT_RED , LIGHT_TOP_VALUE-1);
  35. light_ctrl(LIGHT_GREEN , LIGHT_TOP_VALUE-1);
  36. light_ctrl(LIGHT_BLUE , LIGHT_TOP_VALUE-1);
  37. }
  38. else
  39. {
  40. light_ctrl(LIGHT_RED , 0);
  41. light_ctrl(LIGHT_GREEN , 0);
  42. light_ctrl(LIGHT_BLUE , 0);
  43. }
  44. }
  45. void vendor_mode_mainlight_onoff_set_pl (UINT8 state)
  46. {
  47. /* LED ON/OFF for vendor model mainlight ONOFF to be mapped here */
  48. if (state)
  49. {
  50. light_ctrl(LIGHT_GREEN , LIGHT_TOP_VALUE-1);
  51. }
  52. else
  53. {
  54. light_ctrl(LIGHT_GREEN , 0);
  55. }
  56. }
  57. void vendor_mode_backlight_onoff_set_pl (UINT8 state)
  58. {
  59. /* LED ON/OFF for vendor model backlight ONOFF to be mapped here */
  60. if (state)
  61. {
  62. light_ctrl(LIGHT_RED , LIGHT_TOP_VALUE-1);
  63. }
  64. else
  65. {
  66. light_ctrl(LIGHT_RED , 0);
  67. }
  68. }
  69. void light_lightness_set_pl (uint16_t ligtnessValue)
  70. {
  71. light_ctrl(LIGHT_RED , ligtnessValue>>10);
  72. light_ctrl(LIGHT_GREEN , ligtnessValue>>10);
  73. light_ctrl(LIGHT_BLUE , ligtnessValue>>10);
  74. }
  75. void light_ctl_set_pl (uint16_t ctlValue,uint16_t dltUV)
  76. {
  77. if(ctlValue<6600)
  78. {
  79. light_ctrl(LIGHT_RED , 255);
  80. }
  81. else
  82. {
  83. light_ctrl(LIGHT_RED , 255-(ctlValue-6600)*(255-160)/(20000-6600));
  84. }
  85. if(ctlValue<6600)
  86. {
  87. light_ctrl(LIGHT_GREEN , 50+200*(6600-ctlValue)/6600);
  88. }
  89. else
  90. {
  91. light_ctrl(LIGHT_GREEN , 255-(ctlValue-6600)*(255-190)/(20000-6600));
  92. }
  93. if(ctlValue<2000)
  94. {
  95. light_ctrl(LIGHT_BLUE , 0);
  96. }
  97. else if(ctlValue<6500)
  98. {
  99. light_ctrl(LIGHT_BLUE , 255*(6600-ctlValue)/(6500-2000));
  100. }
  101. else
  102. {
  103. light_ctrl(LIGHT_BLUE , 255);
  104. }
  105. }
  106. static float Hue_2_RGB( float v1, float v2, float vH ) //Function Hue_2_RGB
  107. {
  108. if ( vH < 0 ) vH += 1;
  109. if ( vH > 1 ) vH -= 1;
  110. if (( 6 * vH ) < 1 ) return ( v1 + ( v2 - v1 ) * 6 * vH );
  111. if (( 2 * vH ) < 1 ) return ( v2 );
  112. if (( 3 * vH ) < 2 ) return ( v1 + ( v2 - v1 ) * ( ( 2/3.0 ) - vH ) * 6 );
  113. return ( v1 );
  114. }
  115. void light_hsl_set_pl (uint16_t H_int,uint16_t S_int,uint16_t L_int)
  116. {
  117. float H = (float)H_int / 65535.0;
  118. float S = (float)S_int / 65535.0;
  119. float L = (float)L_int / 65535.0;
  120. float R,G,B,var_1,var_2;
  121. if ( S == 0 )
  122. {
  123. R = L;
  124. G = L;
  125. B = L;
  126. }
  127. else
  128. {
  129. if ( L < 0.5 )
  130. var_2 = L * ( 1 + S );
  131. else
  132. var_2 = ( L + S ) - ( S * L );
  133. var_1 = 2 * L - var_2;
  134. R = Hue_2_RGB( var_1, var_2, H + ( 1/3.0 ));
  135. G = Hue_2_RGB( var_1, var_2, H );
  136. B = Hue_2_RGB( var_1, var_2, H - ( 1/3.0 ));
  137. }
  138. uint16_t R_int = (uint16_t)(R*LIGHT_TURN_ON);
  139. uint16_t G_int = (uint16_t)(G*LIGHT_TURN_ON);
  140. uint16_t B_int = (uint16_t)(B*LIGHT_TURN_ON);
  141. // printf("[HSL_f] %f %f %f\n",R,G,B);
  142. // printf("[HSL_I] %02x %02x %02x\n",R_int,G_int,B_int);
  143. light_ctrl(LIGHT_RED, R_int);
  144. light_ctrl(LIGHT_GREEN, G_int);
  145. light_ctrl(LIGHT_BLUE, B_int);
  146. }
  147. // light_hsl_set_pl(0x5555,0xffff,0x8000); // 0x00 0xFF 0x00 Green
  148. // light_hsl_set_pl(0xaaaa,0xffff,0x8000); // 0x00 0x00 0xFF Blue
  149. // light_hsl_set_pl(0x0000,0xffff,0x8000);// 0xFF 0x00 0x00 Red
  150. //