Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PROGRAM_NAME='imp LED Color'
- (***********************************************************)
- (***********************************************************)
- (* FILE_LAST_MODIFIED_ON: 04/05/2006 AT: 09:00:25 *)
- (***********************************************************)
- (* System Type : NetLinx *)
- (***********************************************************)
- (* REV HISTORY: *)
- (***********************************************************)
- (*
- $History: $
- *)
- (***********************************************************)
- (* DEVICE NUMBER DEFINITIONS GO BELOW *)
- (***********************************************************)
- DEFINE_DEVICE
- dvIPAD = 12001:01:00;
- dvEthernet = 00000:05:00;
- (***********************************************************)
- (* CONSTANT DEFINITIONS GO BELOW *)
- (***********************************************************)
- define_constant
- (***********************************************************)
- (* DATA TYPE DEFINITIONS GO BELOW *)
- (***********************************************************)
- define_type
- (***********************************************************)
- (* VARIABLE DEFINITIONS GO BELOW *)
- (***********************************************************)
- define_variable
- volatile char s_colorValue[80];
- volatile char i_online;
- (***********************************************************)
- (* LATCHING DEFINITIONS GO BELOW *)
- (***********************************************************)
- define_latching
- (***********************************************************)
- (* SUBROUTINE/FUNCTION DEFINITIONS GO BELOW *)
- (***********************************************************)
- (* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
- (* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)
- define_function fnSendColor()
- {
- // Cancel the wait below
- cancel_wait_until 'ONLINE';
- // If we're offline, connect
- if(i_online == 0)
- {
- ip_client_open(dvEthernet.port,'api.electricimp.com',80,1);
- }
- // Wait until we're online
- wait_until(i_online) 'ONLINE'
- {
- #warn 'You must fill in your values from your HTTP IN vimp.';
- send_string dvEthernet,"'POST /v1/<YOUR VALUES>/<YOUR VALUES>?value=',s_colorValue,' HTTP/1.1',$0d,$0a,
- 'Host: api.electricimp.com',$0d,$0a,
- 'User-Agent: Netlinx',$0d,$0a,$0d,$0a"
- }
- }
- (***********************************************************)
- (* STARTUP CODE GOES BELOW *)
- (***********************************************************)
- define_start
- (***********************************************************)
- (* THE EVENTS GO BELOW *)
- (***********************************************************)
- define_event
- data_event[dvEthernet]
- {
- online:
- {
- // Flag as online
- on[i_online];
- }
- offline:
- {
- // Flag as offline
- off[i_online];
- // Clear the
- s_colorValue = '';
- }
- string:
- {
- // Once we find the ack from the server, disconnect
- if(find_string(data.text,"'OK',$0d,$0a",1) && i_online == 1)
- {
- // Close the socket
- ip_client_close(dvEthernet.port);
- }
- }
- onerror:
- {
- // We probably never made it online, but clear it just incase.
- off[i_online];
- }
- }
- // Set LED Color
- button_event[dvIPAD,1]
- {
- push:
- {
- // Copy the color to an invisible button
- send_command dvIPAD, "'^BMC-200,0,0,93,1,CF'"
- // Get the invisible button's color - see custom_event
- send_command dvIPAD,"'?BCF-200,1'";
- }
- }
- // Triggered when requesting the button's color fill
- custom_event[dvIPAD,200,1012]
- {
- // Value returned as
- s_colorValue = "'HEX-',mid_string(custom.text,2,6)";
- // Set the color
- fnSendColor();
- }
- (***********************************************************)
- (* RUNTIME LOOP GOES BELOW *)
- (***********************************************************)
- // Do not use this secion unless absolutely necessary
- // define_program
- (***********************************************************)
- (* END OF PROGRAM *)
- (* DO NOT PUT ANY CODE BELOW THIS COMMENT *)
- (***********************************************************)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement