diff --git a/examples/application.h b/examples/application.h deleted file mode 100755 index faf14ff..0000000 --- a/examples/application.h +++ /dev/null @@ -1,71 +0,0 @@ -/** - ****************************************************************************** - * @file application.h - * @authors Satish Nair, Zachary Crockett, Zach Supalla and Mohit Bhoite - * @version V1.0.0 - * @date 30-April-2013 - * @brief User Application File Header - ****************************************************************************** - Copyright (c) 2013-2015 Particle Industries, Inc. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation, either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - ****************************************************************************** - */ - -#ifndef APPLICATION_H_ -#define APPLICATION_H_ - -#include "particle_version.h" - -#ifdef SPARK_PLATFORM -#include "platform_headers.h" -#endif - - -#include "spark_wiring.h" -#include "spark_wiring_cloud.h" -#include "spark_wiring_interrupts.h" -#include "spark_wiring_string.h" -#include "spark_wiring_print.h" -#include "spark_wiring_usartserial.h" -#include "spark_wiring_usbserial.h" -#include "spark_wiring_usbmouse.h" -#include "spark_wiring_usbkeyboard.h" -#include "spark_wiring_spi.h" -#include "spark_wiring_i2c.h" -#include "spark_wiring_servo.h" -#include "spark_wiring_wifi.h" -#include "spark_wiring_network.h" -#include "spark_wiring_client.h" -#include "spark_wiring_tcpclient.h" -#include "spark_wiring_tcpserver.h" -#include "spark_wiring_udp.h" -#include "spark_wiring_time.h" -#include "spark_wiring_tone.h" -#include "spark_wiring_eeprom.h" -#include "spark_wiring_version.h" -#include "spark_wiring_thread.h" -#include "fast_pin.h" -#include "string_convert.h" -#include "NCD8Relay.h" -// this was being implicitly pulled in by some of the other headers -// adding here for backwards compatibility. -#include "system_task.h" -#include "system_user.h" - -#include "stdio.h" - -using namespace spark; - -#endif /* APPLICATION_H_ */ diff --git a/firmware/examples/CloudControl.cpp b/firmware/examples/CloudControl.cpp new file mode 100644 index 0000000..e87d8d9 --- /dev/null +++ b/firmware/examples/CloudControl.cpp @@ -0,0 +1,71 @@ +/* Includes ------------------------------------------------------------------*/ +#include "application.h" +#include "spark_wiring_print.h" + +SYSTEM_MODE(AUTOMATIC); +NCD8Relay relayController; +int triggerRelay(String command); + +/* This function is called once at start up ----------------------------------*/ +void setup() +{ + Serial.begin(115200); + relayController.setAddress(0,0,0); + Spark.function("controlRelay", triggerRelay); +} + +/* This function loops forever --------------------------------------------*/ +void loop() +{ +} + +int triggerRelay(String command){ + if(command.equalsIgnoreCase("turnonallrelays")){ + relayController.turnOnAllRelays(); + return 1; + } + if(command.equalsIgnoreCase("turnoffallrelays")){ + relayController.turnOffAllRelays(); + return 1; + } + if(command.startsWith("setBankStatus:")){ + int status = command.substring(14).toInt(); + if(status < 0 || status > 255){ + return 0; + } + Serial.print("Setting bank status to: "); + Serial.println(status); + relayController.setBankStatus(status); + Serial.println("done"); + return 1; + } + //Relay Specific Command + int relayNumber = command.substring(0,1).toInt(); + Serial.print("relayNumber: "); + Serial.println(relayNumber); + String relayCommand = command.substring(1); + Serial.print("relayCommand:"); + Serial.print(relayCommand); + Serial.println("."); + if(relayCommand.equalsIgnoreCase("on")){ + Serial.println("Turning on relay"); + relayController.turnOnRelay(relayNumber); + Serial.println("returning"); + return 1; + } + if(relayCommand.equalsIgnoreCase("off")){ + relayController.turnOffRelay(relayNumber); + return 1; + } + if(relayCommand.equalsIgnoreCase("toggle")){ + relayController.toggleRelay(relayNumber); + return 1; + } + if(relayCommand.equalsIgnoreCase("momentary")){ + relayController.turnOnRelay(relayNumber); + delay(300); + relayController.turnOffRelay(relayNumber); + return 1; + } + return 0; +} diff --git a/examples/application.cpp b/firmware/examples/Loop_Test.cpp similarity index 98% rename from examples/application.cpp rename to firmware/examples/Loop_Test.cpp index ba51230..73e69b9 100644 --- a/examples/application.cpp +++ b/firmware/examples/Loop_Test.cpp @@ -1,5 +1,6 @@ /* Includes ------------------------------------------------------------------*/ #include "application.h" +#include "NCD8Relay.h" SYSTEM_MODE(MANUAL); NCD8Relay relayController;