Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MaximInterface
src/WifiConnectWindow.cpp@17:5926077e5345, 2019-10-04 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Fri Oct 04 12:10:11 2019 -0500
- Revision:
- 17:5926077e5345
- Parent:
- 16:a004191a79ab
Set pin maps through the mbed configuration system. Added support for MAX32625MBED target. Updated mbed-os to version 5.7.7 for MAX32625 I2C fixes. Consolidated simplelink hook definitions.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| IanBenzMaxim | 0:33d4e66780c0 | 1 | /******************************************************************************* |
| IanBenzMaxim | 16:a004191a79ab | 2 | * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. |
| IanBenzMaxim | 0:33d4e66780c0 | 3 | * |
| IanBenzMaxim | 0:33d4e66780c0 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| IanBenzMaxim | 0:33d4e66780c0 | 5 | * copy of this software and associated documentation files (the "Software"), |
| IanBenzMaxim | 0:33d4e66780c0 | 6 | * to deal in the Software without restriction, including without limitation |
| IanBenzMaxim | 0:33d4e66780c0 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| IanBenzMaxim | 0:33d4e66780c0 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| IanBenzMaxim | 0:33d4e66780c0 | 9 | * Software is furnished to do so, subject to the following conditions: |
| IanBenzMaxim | 0:33d4e66780c0 | 10 | * |
| IanBenzMaxim | 0:33d4e66780c0 | 11 | * The above copyright notice and this permission notice shall be included |
| IanBenzMaxim | 0:33d4e66780c0 | 12 | * in all copies or substantial portions of the Software. |
| IanBenzMaxim | 0:33d4e66780c0 | 13 | * |
| IanBenzMaxim | 0:33d4e66780c0 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| IanBenzMaxim | 0:33d4e66780c0 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| IanBenzMaxim | 0:33d4e66780c0 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| IanBenzMaxim | 0:33d4e66780c0 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
| IanBenzMaxim | 0:33d4e66780c0 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| IanBenzMaxim | 0:33d4e66780c0 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| IanBenzMaxim | 0:33d4e66780c0 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| IanBenzMaxim | 0:33d4e66780c0 | 21 | * |
| IanBenzMaxim | 0:33d4e66780c0 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
| IanBenzMaxim | 0:33d4e66780c0 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
| IanBenzMaxim | 0:33d4e66780c0 | 24 | * Products, Inc. Branding Policy. |
| IanBenzMaxim | 0:33d4e66780c0 | 25 | * |
| IanBenzMaxim | 0:33d4e66780c0 | 26 | * The mere transfer of this software does not imply any licenses |
| IanBenzMaxim | 0:33d4e66780c0 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
| IanBenzMaxim | 0:33d4e66780c0 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
| IanBenzMaxim | 0:33d4e66780c0 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
| IanBenzMaxim | 0:33d4e66780c0 | 30 | * ownership rights. |
| IanBenzMaxim | 0:33d4e66780c0 | 31 | *******************************************************************************/ |
| IanBenzMaxim | 0:33d4e66780c0 | 32 | |
| IanBenzMaxim | 0:33d4e66780c0 | 33 | #include <memory> |
| IanBenzMaxim | 16:a004191a79ab | 34 | #include <mbed-os/features/netsocket/TCPSocket.h> |
| IanBenzMaxim | 16:a004191a79ab | 35 | #include <mbed-os/platform/mbed_wait_api.h> |
| IanBenzMaxim | 0:33d4e66780c0 | 36 | #include "CC3100.hpp" |
| IanBenzMaxim | 0:33d4e66780c0 | 37 | #include "DisplayIdWindow.hpp" |
| IanBenzMaxim | 13:6a6225690c2e | 38 | #include "ErrorWindow.hpp" |
| IanBenzMaxim | 13:6a6225690c2e | 39 | #include "MakeFunction.hpp" |
| IanBenzMaxim | 0:33d4e66780c0 | 40 | #include "NormalOperationWindow.hpp" |
| IanBenzMaxim | 0:33d4e66780c0 | 41 | #include "WifiConnectWindow.hpp" |
| IanBenzMaxim | 13:6a6225690c2e | 42 | #include "WindowManager.hpp" |
| IanBenzMaxim | 0:33d4e66780c0 | 43 | |
| IanBenzMaxim | 5:d2c852569e9d | 44 | static const char wifiSsid[] = "MAXREFDES155"; |
| IanBenzMaxim | 5:d2c852569e9d | 45 | static const char wifiPassword[] = "maxim1234"; |
| IanBenzMaxim | 0:33d4e66780c0 | 46 | static const char serverAddress[] = "www.maxim-security.com"; |
| IanBenzMaxim | 0:33d4e66780c0 | 47 | static const uint16_t serverPort = 3900; |
| IanBenzMaxim | 0:33d4e66780c0 | 48 | |
| IanBenzMaxim | 16:a004191a79ab | 49 | WifiConnectWindow::WifiConnectWindow() : state(NotStarted) { |
| IanBenzMaxim | 16:a004191a79ab | 50 | description.setParent(this); |
| IanBenzMaxim | 16:a004191a79ab | 51 | description.setText("WiFi SSID: " + std::string(wifiSsid) + |
| IanBenzMaxim | 16:a004191a79ab | 52 | "\nWiFi Password: " + std::string(wifiPassword)); |
| IanBenzMaxim | 16:a004191a79ab | 53 | description.setWordWrap(true); |
| IanBenzMaxim | 16:a004191a79ab | 54 | backButton.setParent(this); |
| IanBenzMaxim | 16:a004191a79ab | 55 | backButton.setText("Back"); |
| IanBenzMaxim | 16:a004191a79ab | 56 | backButton.setClickedHandler( |
| IanBenzMaxim | 13:6a6225690c2e | 57 | makeFunction(this, &WifiConnectWindow::backButtonClicked)); |
| IanBenzMaxim | 16:a004191a79ab | 58 | continueButton.setParent(this); |
| IanBenzMaxim | 16:a004191a79ab | 59 | continueButton.setText("Connect to WiFi"); |
| IanBenzMaxim | 16:a004191a79ab | 60 | continueButton.setClickedHandler( |
| IanBenzMaxim | 13:6a6225690c2e | 61 | makeFunction(this, &WifiConnectWindow::continueButtonClicked)); |
| IanBenzMaxim | 16:a004191a79ab | 62 | continueButton.setFocused(); |
| IanBenzMaxim | 0:33d4e66780c0 | 63 | } |
| IanBenzMaxim | 0:33d4e66780c0 | 64 | |
| IanBenzMaxim | 13:6a6225690c2e | 65 | void WifiConnectWindow::updated() { |
| IanBenzMaxim | 16:a004191a79ab | 66 | switch (state) { |
| IanBenzMaxim | 13:6a6225690c2e | 67 | case NotStarted: |
| IanBenzMaxim | 13:6a6225690c2e | 68 | break; |
| IanBenzMaxim | 13:6a6225690c2e | 69 | |
| IanBenzMaxim | 13:6a6225690c2e | 70 | case PreConnect: |
| IanBenzMaxim | 16:a004191a79ab | 71 | backButton.setParent(NULL); |
| IanBenzMaxim | 16:a004191a79ab | 72 | continueButton.setParent(NULL); |
| IanBenzMaxim | 16:a004191a79ab | 73 | description.setText("Connecting to WiFi network..."); |
| IanBenzMaxim | 16:a004191a79ab | 74 | state = WiFiConnect; |
| IanBenzMaxim | 13:6a6225690c2e | 75 | break; |
| IanBenzMaxim | 13:6a6225690c2e | 76 | |
| IanBenzMaxim | 16:a004191a79ab | 77 | case WiFiConnect: |
| IanBenzMaxim | 13:6a6225690c2e | 78 | // Connect to AP. |
| IanBenzMaxim | 16:a004191a79ab | 79 | if (CC3100::instance().connect(wifiSsid, wifiPassword, |
| IanBenzMaxim | 16:a004191a79ab | 80 | NSAPI_SECURITY_WPA2) != 0) { |
| IanBenzMaxim | 16:a004191a79ab | 81 | if (windowManager()) { |
| IanBenzMaxim | 13:6a6225690c2e | 82 | std::auto_ptr<Window> window(new ErrorWindow("WiFi connect failed")); |
| IanBenzMaxim | 13:6a6225690c2e | 83 | windowManager()->push(window); |
| IanBenzMaxim | 13:6a6225690c2e | 84 | } |
| IanBenzMaxim | 13:6a6225690c2e | 85 | break; |
| IanBenzMaxim | 0:33d4e66780c0 | 86 | } |
| IanBenzMaxim | 13:6a6225690c2e | 87 | |
| IanBenzMaxim | 16:a004191a79ab | 88 | description.setText("Connecting to server..."); |
| IanBenzMaxim | 16:a004191a79ab | 89 | state = ServerConnect; |
| IanBenzMaxim | 16:a004191a79ab | 90 | break; |
| IanBenzMaxim | 13:6a6225690c2e | 91 | |
| IanBenzMaxim | 13:6a6225690c2e | 92 | case ServerConnect: { |
| IanBenzMaxim | 13:6a6225690c2e | 93 | // Get IP address from DNS lookup. |
| IanBenzMaxim | 13:6a6225690c2e | 94 | SocketAddress socketAddress; |
| IanBenzMaxim | 16:a004191a79ab | 95 | if (CC3100::instance().gethostbyname(serverAddress, &socketAddress) != 0) { |
| IanBenzMaxim | 16:a004191a79ab | 96 | if (windowManager()) { |
| IanBenzMaxim | 13:6a6225690c2e | 97 | std::auto_ptr<Window> window(new ErrorWindow("Hostname lookup failed")); |
| IanBenzMaxim | 13:6a6225690c2e | 98 | windowManager()->push(window); |
| IanBenzMaxim | 13:6a6225690c2e | 99 | } |
| IanBenzMaxim | 13:6a6225690c2e | 100 | break; |
| IanBenzMaxim | 13:6a6225690c2e | 101 | } |
| IanBenzMaxim | 13:6a6225690c2e | 102 | |
| IanBenzMaxim | 13:6a6225690c2e | 103 | // Open socket connection. |
| IanBenzMaxim | 13:6a6225690c2e | 104 | std::auto_ptr<TCPSocket> socket(new TCPSocket(&CC3100::instance())); |
| IanBenzMaxim | 13:6a6225690c2e | 105 | socket->set_blocking(false); |
| IanBenzMaxim | 13:6a6225690c2e | 106 | socketAddress.set_port(serverPort); |
| IanBenzMaxim | 16:a004191a79ab | 107 | if (socket->connect(socketAddress) != 0) { |
| IanBenzMaxim | 16:a004191a79ab | 108 | if (windowManager()) { |
| IanBenzMaxim | 13:6a6225690c2e | 109 | std::auto_ptr<Window> window(new ErrorWindow("Socket connect failed")); |
| IanBenzMaxim | 13:6a6225690c2e | 110 | windowManager()->push(window); |
| IanBenzMaxim | 13:6a6225690c2e | 111 | } |
| IanBenzMaxim | 13:6a6225690c2e | 112 | break; |
| IanBenzMaxim | 13:6a6225690c2e | 113 | } |
| IanBenzMaxim | 13:6a6225690c2e | 114 | |
| IanBenzMaxim | 16:a004191a79ab | 115 | if (windowManager()) { |
| IanBenzMaxim | 13:6a6225690c2e | 116 | windowManager()->pop(); |
| IanBenzMaxim | 13:6a6225690c2e | 117 | std::auto_ptr<Window> window(new NormalOperationWindow(socket)); |
| IanBenzMaxim | 13:6a6225690c2e | 118 | windowManager()->push(window); |
| IanBenzMaxim | 13:6a6225690c2e | 119 | } |
| IanBenzMaxim | 16:a004191a79ab | 120 | break; |
| IanBenzMaxim | 16:a004191a79ab | 121 | } |
| IanBenzMaxim | 13:6a6225690c2e | 122 | } |
| IanBenzMaxim | 0:33d4e66780c0 | 123 | } |
| IanBenzMaxim | 0:33d4e66780c0 | 124 | |
| IanBenzMaxim | 13:6a6225690c2e | 125 | void WifiConnectWindow::resized() { |
| IanBenzMaxim | 16:a004191a79ab | 126 | backButton.resize(backButton.preferredWidth(), |
| IanBenzMaxim | 16:a004191a79ab | 127 | backButton.preferredHeight()); |
| IanBenzMaxim | 16:a004191a79ab | 128 | backButton.move(0, height() - backButton.height()); |
| IanBenzMaxim | 16:a004191a79ab | 129 | continueButton.resize(continueButton.preferredWidth(), |
| IanBenzMaxim | 16:a004191a79ab | 130 | continueButton.preferredHeight()); |
| IanBenzMaxim | 16:a004191a79ab | 131 | continueButton.move(width() - continueButton.width(), |
| IanBenzMaxim | 16:a004191a79ab | 132 | height() - continueButton.height()); |
| IanBenzMaxim | 16:a004191a79ab | 133 | description.resize(width(), |
| IanBenzMaxim | 16:a004191a79ab | 134 | std::min(backButton.y(), continueButton.y())); |
| IanBenzMaxim | 0:33d4e66780c0 | 135 | } |
| IanBenzMaxim | 0:33d4e66780c0 | 136 | |
| IanBenzMaxim | 13:6a6225690c2e | 137 | bool WifiConnectWindow::doProcessKey(Key key) { |
| IanBenzMaxim | 13:6a6225690c2e | 138 | bool handled; |
| IanBenzMaxim | 13:6a6225690c2e | 139 | switch (key) { |
| IanBenzMaxim | 13:6a6225690c2e | 140 | case LeftKey: |
| IanBenzMaxim | 16:a004191a79ab | 141 | backButton.setFocused(); |
| IanBenzMaxim | 13:6a6225690c2e | 142 | handled = true; |
| IanBenzMaxim | 13:6a6225690c2e | 143 | break; |
| IanBenzMaxim | 13:6a6225690c2e | 144 | |
| IanBenzMaxim | 13:6a6225690c2e | 145 | case RightKey: |
| IanBenzMaxim | 16:a004191a79ab | 146 | continueButton.setFocused(); |
| IanBenzMaxim | 13:6a6225690c2e | 147 | handled = true; |
| IanBenzMaxim | 13:6a6225690c2e | 148 | break; |
| IanBenzMaxim | 13:6a6225690c2e | 149 | |
| IanBenzMaxim | 13:6a6225690c2e | 150 | default: |
| IanBenzMaxim | 13:6a6225690c2e | 151 | handled = false; |
| IanBenzMaxim | 13:6a6225690c2e | 152 | break; |
| IanBenzMaxim | 13:6a6225690c2e | 153 | } |
| IanBenzMaxim | 13:6a6225690c2e | 154 | return handled; |
| IanBenzMaxim | 0:33d4e66780c0 | 155 | } |
| IanBenzMaxim | 0:33d4e66780c0 | 156 | |
| IanBenzMaxim | 13:6a6225690c2e | 157 | void WifiConnectWindow::continueButtonClicked(Button *) { |
| IanBenzMaxim | 16:a004191a79ab | 158 | if (state == NotStarted) { |
| IanBenzMaxim | 16:a004191a79ab | 159 | state = PreConnect; |
| IanBenzMaxim | 13:6a6225690c2e | 160 | } |
| IanBenzMaxim | 0:33d4e66780c0 | 161 | } |
| IanBenzMaxim | 0:33d4e66780c0 | 162 | |
| IanBenzMaxim | 13:6a6225690c2e | 163 | void WifiConnectWindow::backButtonClicked(Button *) { |
| IanBenzMaxim | 16:a004191a79ab | 164 | if (windowManager()) { |
| IanBenzMaxim | 13:6a6225690c2e | 165 | windowManager()->pop(); |
| IanBenzMaxim | 13:6a6225690c2e | 166 | std::auto_ptr<Window> window( |
| IanBenzMaxim | 13:6a6225690c2e | 167 | new DisplayIdWindow(DisplayIdWindow::PreConnectMode)); |
| IanBenzMaxim | 13:6a6225690c2e | 168 | windowManager()->push(window); |
| IanBenzMaxim | 13:6a6225690c2e | 169 | } |
| IanBenzMaxim | 0:33d4e66780c0 | 170 | } |