1 | /*
|
---|
2 | ****************************************************************************
|
---|
3 | * Copyright (c) 2015 Arduino srl. All right reserved.
|
---|
4 | *
|
---|
5 | * File : Ciao.h
|
---|
6 | * Date : 2016/02/16
|
---|
7 | * Revision : 0.0.2 $
|
---|
8 | * Author: andrea[at]arduino[dot]org
|
---|
9 | * Author: adriano[at]arduino[dot]org
|
---|
10 | *
|
---|
11 | ****************************************************************************
|
---|
12 |
|
---|
13 | This library is free software; you can redistribute it and/or
|
---|
14 | modify it under the terms of the GNU Lesser General Public
|
---|
15 | License as published by the Free Software Foundation; either
|
---|
16 | version 2.1 of the License, or (at your option) any later version.
|
---|
17 |
|
---|
18 | This library is distributed in the hope that it will be useful,
|
---|
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | Lesser General Public License for more details.
|
---|
22 |
|
---|
23 | You should have received a copy of the GNU Lesser General Public
|
---|
24 | License along with this library; if not, write to the Free Software
|
---|
25 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef CIAO_H_
|
---|
29 | #define CIAO_H_
|
---|
30 |
|
---|
31 | #include <Arduino.h>
|
---|
32 | #include <Stream.h>
|
---|
33 | #include "lib/CiaoData.h"
|
---|
34 | #if defined(__AVR_ATmega328P__)
|
---|
35 | #include "lib/SC16IS750.h"
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | #if defined(__AVR_ATmega32U4__) || defined(ARDUINO_ARCH_SAMD)
|
---|
39 |
|
---|
40 | #if defined(__AVR_ATmega32U4__)
|
---|
41 | #define BAUDRATE 250000
|
---|
42 | #elif defined(ARDUINO_ARCH_SAMD)
|
---|
43 | #define BAUDRATE 4000000
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | class CiaoClass {
|
---|
47 | public:
|
---|
48 | void begin();
|
---|
49 | CiaoData read( String protocol, String param1 = "", String param2 = "", String param3 = "");
|
---|
50 | CiaoData write( String protocol, String param1, String param2 = "", String param3 = "");
|
---|
51 | CiaoData writeResponse( String protocol, String id, String param1="", String param2 = "", String param3 = "");
|
---|
52 | CiaoData parse( String, String);
|
---|
53 | void println(String log){};
|
---|
54 | CiaoClass(Stream &_stream);
|
---|
55 |
|
---|
56 | private:
|
---|
57 | void dropAll();
|
---|
58 | bool started;
|
---|
59 | Stream &stream;
|
---|
60 | };
|
---|
61 |
|
---|
62 | // This subclass uses a serial port Stream
|
---|
63 | class SerialCiaoClass : public CiaoClass {
|
---|
64 | public:
|
---|
65 | #if defined(__AVR_ATmega32U4__)
|
---|
66 | SerialCiaoClass(HardwareSerial &_serial)
|
---|
67 | : CiaoClass(_serial), serial(_serial) {
|
---|
68 | // Empty
|
---|
69 | }
|
---|
70 | #elif defined(ARDUINO_ARCH_SAMD)
|
---|
71 | SerialCiaoClass(Serial_ &_serial)
|
---|
72 | : CiaoClass(_serial), serial(_serial) {
|
---|
73 | // Empty
|
---|
74 | }
|
---|
75 | #endif
|
---|
76 | void begin( unsigned long baudrate = BAUDRATE) {
|
---|
77 | serial.begin(baudrate);
|
---|
78 | CiaoClass::begin();
|
---|
79 | }
|
---|
80 | private:
|
---|
81 | #if defined(__AVR_ATmega32U4__)
|
---|
82 | HardwareSerial &serial;
|
---|
83 | #elif defined(ARDUINO_ARCH_SAMD)
|
---|
84 | Serial_ &serial;
|
---|
85 | #endif
|
---|
86 | };
|
---|
87 |
|
---|
88 | void splitString(String, String, String[], int size);
|
---|
89 |
|
---|
90 | extern SerialCiaoClass Ciao;
|
---|
91 |
|
---|
92 | #else
|
---|
93 |
|
---|
94 | class ArduinoWifiClass : public WifiData
|
---|
95 | {
|
---|
96 |
|
---|
97 | public:
|
---|
98 | void begin();
|
---|
99 |
|
---|
100 | boolean connected();
|
---|
101 | void connect(char* , char*);
|
---|
102 |
|
---|
103 | void powerON();
|
---|
104 | void powerOFF();
|
---|
105 |
|
---|
106 |
|
---|
107 | };
|
---|
108 |
|
---|
109 | class CiaoClass : public WifiData
|
---|
110 | {
|
---|
111 | public:
|
---|
112 | void begin();
|
---|
113 |
|
---|
114 | CiaoData read( char*, char*, String ); // ârestâ, âhostnameâ, âStringoneâ,
|
---|
115 | CiaoData read( char*, char*, String, char*); // ârestâ, âhostnameâ, âStringoneâ, âmethodâ
|
---|
116 |
|
---|
117 | CiaoData write( char*, char*, String ); // ârestâ, âhostnameâ, âStringoneâ,
|
---|
118 | CiaoData write( char*, char*, String, char*); // ârestâ, âhostnameâ, âStringoneâ, âmethodâ
|
---|
119 |
|
---|
120 | };
|
---|
121 |
|
---|
122 |
|
---|
123 | extern CiaoClass Ciao;
|
---|
124 | extern ArduinoWifiClass Wifi;
|
---|
125 |
|
---|
126 | #endif
|
---|
127 |
|
---|
128 |
|
---|
129 | #endif /* CIAO_H_ */
|
---|