|
2 | 2 |
|
3 | 3 | char data[1024]; |
4 | 4 |
|
5 | | -boolean GoogleHomeNotifier::device(const char * name) |
6 | | -{ |
7 | | - return this->device(name, "en"); |
8 | | -} |
9 | | - |
10 | | -boolean GoogleHomeNotifier::device(const char * name, const char * locale) |
11 | | -{ |
12 | | - return GoogleHomeNotifier::device(name, locale, 10000); |
13 | | -} |
14 | | - |
15 | | -boolean GoogleHomeNotifier::device(const char * name, const char * locale, int to) |
| 5 | +boolean GoogleHomeNotifier::device(const char *name, const char *locale = "en", int to = 10000) |
16 | 6 | { |
17 | 7 | int timeout = millis() + to; |
18 | 8 | int n; |
@@ -57,25 +47,29 @@ boolean GoogleHomeNotifier::device(const char * name, const char * locale, int t |
57 | 47 | return true; |
58 | 48 | } |
59 | 49 |
|
60 | | -boolean GoogleHomeNotifier::ip(IPAddress ip, const char *locale) |
| 50 | +boolean GoogleHomeNotifier::ip(IPAddress ip, const char *locale = "en", uint16_t port = 8009) |
61 | 51 | { |
62 | 52 | this->m_ipaddress = ip; |
63 | | - this->m_port = 8009; |
| 53 | + this->m_port = port; |
64 | 54 | sprintf(this->m_locale, "%s", locale); |
65 | 55 | return true; |
66 | 56 | } |
67 | 57 |
|
68 | | -boolean GoogleHomeNotifier::notify(const char * phrase) { |
| 58 | +boolean GoogleHomeNotifier::notify(const char *phrase) { |
69 | 59 | return this->cast(phrase, NULL); |
70 | 60 | } |
71 | 61 |
|
72 | | -boolean GoogleHomeNotifier::play(const char * mp3Url) { |
| 62 | +boolean GoogleHomeNotifier::play(const char *mp3Url) { |
73 | 63 | return this->cast(NULL, mp3Url); |
74 | 64 | } |
75 | 65 |
|
76 | | -boolean GoogleHomeNotifier::cast(const char * phrase, const char * mp3Url) |
| 66 | +boolean GoogleHomeNotifier::cast(const char *phrase, const char *mp3Url) |
77 | 67 | { |
78 | 68 | char error[128]; |
| 69 | + if((this->m_ipaddress[0] == 0 && this->m_ipaddress[1] == 0 && this->m_ipaddress[2] == 0 && this->m_ipaddress[3] == 0) || this->m_port == 0) { |
| 70 | + this->setLastError("Google Home's IP address/port is not set. Call 'device' or 'ip' method before calling 'cast' method."); |
| 71 | + return false; |
| 72 | + } |
79 | 73 | String speechUrl; |
80 | 74 | if (phrase != NULL) { |
81 | 75 | speechUrl = tts.getSpeechUrl(phrase, m_locale); |
@@ -131,7 +125,7 @@ const uint16_t GoogleHomeNotifier::getPort() |
131 | 125 | return m_port; |
132 | 126 | } |
133 | 127 |
|
134 | | -boolean GoogleHomeNotifier::sendMessage(const char* sourceId, const char* destinationId, const char* ns, const char* data) |
| 128 | +boolean GoogleHomeNotifier::sendMessage(const char *sourceId, const char *destinationId, const char *ns, const char *data) |
135 | 129 | { |
136 | 130 | extensions_api_cast_channel_CastMessage message = extensions_api_cast_channel_CastMessage_init_default; |
137 | 131 |
|
@@ -267,7 +261,7 @@ boolean GoogleHomeNotifier::connect() |
267 | 261 | return true; |
268 | 262 | } |
269 | 263 |
|
270 | | -boolean GoogleHomeNotifier::_play(const char * mp3url) |
| 264 | +boolean GoogleHomeNotifier::_play(const char *mp3url) |
271 | 265 | { |
272 | 266 | // send 'CONNECT' again |
273 | 267 | sprintf(data, CASTV2_DATA_CONNECT); |
|
0 commit comments