Advertisement
Guest User

Untitled

a guest
Aug 15th, 2012
104
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PROGRAM_NAME='imp LED Color'
  2. (***********************************************************)
  3. (***********************************************************)
  4. (* FILE_LAST_MODIFIED_ON: 04/05/2006 AT: 09:00:25 *)
  5. (***********************************************************)
  6. (* System Type : NetLinx *)
  7. (***********************************************************)
  8. (* REV HISTORY: *)
  9. (***********************************************************)
  10. (*
  11. $History: $
  12. *)
  13. (***********************************************************)
  14. (* DEVICE NUMBER DEFINITIONS GO BELOW *)
  15. (***********************************************************)
  16. DEFINE_DEVICE
  17. dvIPAD = 12001:01:00;
  18. dvEthernet = 00000:05:00;
  19.  
  20. (***********************************************************)
  21. (* CONSTANT DEFINITIONS GO BELOW *)
  22. (***********************************************************)
  23. define_constant
  24.  
  25. (***********************************************************)
  26. (* DATA TYPE DEFINITIONS GO BELOW *)
  27. (***********************************************************)
  28. define_type
  29.  
  30. (***********************************************************)
  31. (* VARIABLE DEFINITIONS GO BELOW *)
  32. (***********************************************************)
  33. define_variable
  34. volatile char s_colorValue[80];
  35. volatile char i_online;
  36. (***********************************************************)
  37. (* LATCHING DEFINITIONS GO BELOW *)
  38. (***********************************************************)
  39. define_latching
  40.  
  41. (***********************************************************)
  42. (* SUBROUTINE/FUNCTION DEFINITIONS GO BELOW *)
  43. (***********************************************************)
  44. (* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
  45. (* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)
  46. define_function fnSendColor()
  47. {
  48. // Cancel the wait below
  49. cancel_wait_until 'ONLINE';
  50.  
  51. // If we're offline, connect
  52. if(i_online == 0)
  53. {
  54. ip_client_open(dvEthernet.port,'api.electricimp.com',80,1);
  55. }
  56.  
  57. // Wait until we're online
  58. wait_until(i_online) 'ONLINE'
  59. {
  60. #warn 'You must fill in your values from your HTTP IN vimp.';
  61.  
  62. send_string dvEthernet,"'POST /v1/<YOUR VALUES>/<YOUR VALUES>?value=',s_colorValue,' HTTP/1.1',$0d,$0a,
  63. 'Host: api.electricimp.com',$0d,$0a,
  64. 'User-Agent: Netlinx',$0d,$0a,$0d,$0a"
  65. }
  66. }
  67. (***********************************************************)
  68. (* STARTUP CODE GOES BELOW *)
  69. (***********************************************************)
  70. define_start
  71.  
  72. (***********************************************************)
  73. (* THE EVENTS GO BELOW *)
  74. (***********************************************************)
  75. define_event
  76. data_event[dvEthernet]
  77. {
  78. online:
  79. {
  80. // Flag as online
  81. on[i_online];
  82. }
  83.  
  84. offline:
  85. {
  86. // Flag as offline
  87. off[i_online];
  88.  
  89. // Clear the
  90. s_colorValue = '';
  91. }
  92.  
  93. string:
  94. {
  95. // Once we find the ack from the server, disconnect
  96. if(find_string(data.text,"'OK',$0d,$0a",1) && i_online == 1)
  97. {
  98. // Close the socket
  99. ip_client_close(dvEthernet.port);
  100. }
  101. }
  102.  
  103. onerror:
  104. {
  105. // We probably never made it online, but clear it just incase.
  106. off[i_online];
  107. }
  108. }
  109.  
  110. // Set LED Color
  111. button_event[dvIPAD,1]
  112. {
  113. push:
  114. {
  115. // Copy the color to an invisible button
  116. send_command dvIPAD, "'^BMC-200,0,0,93,1,CF'"
  117.  
  118. // Get the invisible button's color - see custom_event
  119. send_command dvIPAD,"'?BCF-200,1'";
  120. }
  121. }
  122.  
  123. // Triggered when requesting the button's color fill
  124. custom_event[dvIPAD,200,1012]
  125. {
  126. // Value returned as
  127. s_colorValue = "'HEX-',mid_string(custom.text,2,6)";
  128.  
  129. // Set the color
  130. fnSendColor();
  131. }
  132.  
  133. (***********************************************************)
  134. (* RUNTIME LOOP GOES BELOW *)
  135. (***********************************************************)
  136. // Do not use this secion unless absolutely necessary
  137. // define_program
  138.  
  139. (***********************************************************)
  140. (* END OF PROGRAM *)
  141. (* DO NOT PUT ANY CODE BELOW THIS COMMENT *)
  142. (***********************************************************)
Advertisement
RAW Paste Data Copied
Advertisement