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
InitWindow.cpp
00001 /******************************************************************************* 00002 * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 *******************************************************************************/ 00032 00033 #include <string> 00034 #include <MaximInterfaceCore/HexString.hpp> 00035 #include <MaximInterfaceCore/RomId.hpp> 00036 #include <MaximInterfaceDevices/DS28C36_DS2476.hpp> 00037 #include <mbed-os/platform/mbed_wait_api.h> 00038 #include "Bitmap.hpp" 00039 #include "DisplayIdWindow.hpp" 00040 #include "CC3100.hpp" 00041 #include "ErrorWindow.hpp" 00042 #include "HardwareTestWindow.hpp" 00043 #include "InitWindow.hpp" 00044 #include "MakeFunction.hpp" 00045 #include "SensorNode.hpp" 00046 #include "Text.hpp" 00047 #include "WindowManager.hpp" 00048 00049 using MaximInterfaceCore::Result; 00050 using MaximInterfaceDevices::DS2476; 00051 00052 extern DS2476 coproc; 00053 extern SensorNode sensorNode; 00054 extern std::string webId; 00055 00056 static const int maximLogoWidth = 128; 00057 static const int maximLogoHeight = 39; 00058 static const uint8_t maximLogoData[] = { 00059 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00060 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 00061 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xe0, 00062 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00063 0x00, 0x1f, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 00064 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 00065 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfe, 00066 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00067 0x01, 0xff, 0xff, 0xff, 0x00, 0x1b, 0x9c, 0x1f, 0x18, 0xcc, 0x6e, 0x70, 00068 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0x80, 0x1f, 0xfe, 0x3f, 00069 0x98, 0xcc, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 00070 0xc0, 0x1c, 0xe6, 0x31, 0x8d, 0x8c, 0x73, 0x98, 0x00, 0x00, 0x00, 0x00, 00071 0x0f, 0xff, 0xff, 0xff, 0xe0, 0x18, 0xc6, 0x01, 0x8f, 0x8c, 0x63, 0x18, 00072 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0xfe, 0x03, 0xe0, 0x18, 0xc6, 0x1f, 00073 0x87, 0x0c, 0x63, 0x18, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x7c, 0x01, 00074 0xf0, 0x18, 0xc6, 0x39, 0x8f, 0x8c, 0x63, 0x18, 0x00, 0x00, 0x00, 0x00, 00075 0x1f, 0x00, 0x3c, 0x01, 0xf0, 0x18, 0xc6, 0x31, 0x8d, 0x8c, 0x63, 0x18, 00076 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x38, 0x01, 0xf8, 0x18, 0xc6, 0x3f, 00077 0x98, 0xcc, 0x63, 0x18, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x04, 0x10, 0x41, 00078 0xf8, 0x18, 0xc6, 0x1d, 0x98, 0xcc, 0x63, 0x18, 0x00, 0x00, 0x00, 0x00, 00079 0x3f, 0x06, 0x30, 0xe1, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00080 0x00, 0x00, 0x00, 0x00, 0x7f, 0x06, 0x20, 0xe1, 0xfc, 0x00, 0x00, 0x00, 00081 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x07, 0x61, 0xe1, 00082 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 00083 0x7f, 0x07, 0xc1, 0xe1, 0xfc, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00084 0x00, 0x00, 0x00, 0x18, 0x7f, 0x07, 0xc3, 0xe1, 0xfc, 0x18, 0x00, 0x18, 00085 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x18, 0x7f, 0x07, 0x83, 0xe1, 00086 0xfc, 0x00, 0x00, 0x18, 0x00, 0x00, 0x40, 0x00, 0x06, 0x00, 0x00, 0x18, 00087 0x7f, 0x07, 0x81, 0xe1, 0xfc, 0x18, 0xde, 0x3e, 0x1e, 0x0f, 0xcd, 0x8f, 00088 0x8f, 0x87, 0x81, 0xd8, 0x3f, 0x07, 0x01, 0xe1, 0xf8, 0x18, 0xff, 0x3e, 00089 0x3f, 0x1f, 0xcf, 0x9f, 0xcf, 0x8f, 0xc3, 0xf8, 0x3f, 0x07, 0x00, 0xe1, 00090 0xf8, 0x18, 0xe3, 0x18, 0x73, 0x99, 0x8e, 0x18, 0xc6, 0x1c, 0xe7, 0x38, 00091 0x3f, 0x06, 0x00, 0xe1, 0xf8, 0x18, 0xc3, 0x18, 0x61, 0x99, 0x8c, 0x00, 00092 0xc6, 0x18, 0x66, 0x18, 0x1f, 0x06, 0x10, 0x61, 0xf0, 0x18, 0xc3, 0x18, 00093 0x7f, 0x9f, 0x8c, 0x0f, 0xc6, 0x1f, 0xe6, 0x18, 0x1f, 0x04, 0x38, 0x61, 00094 0xf0, 0x18, 0xc3, 0x18, 0x60, 0x0f, 0x0c, 0x1c, 0xc6, 0x18, 0x06, 0x18, 00095 0x1f, 0x04, 0x38, 0x21, 0xf0, 0x18, 0xc3, 0x18, 0x71, 0x98, 0x0c, 0x18, 00096 0xc6, 0x1c, 0x67, 0x38, 0x0f, 0xff, 0xff, 0xff, 0xe0, 0x18, 0xc3, 0x1e, 00097 0x3f, 0x9f, 0x8c, 0x1f, 0xc7, 0x8f, 0xe3, 0xf8, 0x07, 0xff, 0xff, 0xff, 00098 0xe0, 0x18, 0xc3, 0x0e, 0x1f, 0x3f, 0xcc, 0x0e, 0xc3, 0x87, 0xc1, 0xd8, 00099 0x07, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x30, 0xc0, 0x00, 00100 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 00101 0x00, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 00102 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00103 0x00, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00104 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 00105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xf0, 00106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00107 0x00, 0x0f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00108 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 00109 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00110 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 00111 00112 InitWindow::InitWindow(Mode mode) 00113 : state((mode == InitMode) ? NotStarted : Completed) { 00114 startButton.setParent(this); 00115 startButton.setText("Start"); 00116 startButton.setClickedHandler( 00117 makeFunction(this, &InitWindow::startButtonClicked)); 00118 hardwareTestButton.setParent(this); 00119 hardwareTestButton.setText("Hardware test"); 00120 hardwareTestButton.setClickedHandler( 00121 makeFunction(this, &InitWindow::hardwareTestButtonClicked)); 00122 startButton.setFocused(); 00123 } 00124 00125 void InitWindow::resized() { 00126 startButton.resize(startButton.preferredWidth(), 00127 startButton.preferredHeight()); 00128 startButton.move(0, height() - startButton.height()); 00129 hardwareTestButton.resize(hardwareTestButton.preferredWidth(), 00130 hardwareTestButton.preferredHeight()); 00131 hardwareTestButton.move(width() - hardwareTestButton.width(), 00132 height() - hardwareTestButton.height()); 00133 } 00134 00135 void InitWindow::doRender(Bitmap & bitmap, int xOffset, int yOffset) const { 00136 bitmap.overlay(xOffset + x(), yOffset + y(), maximLogoData, 00137 sizeof(maximLogoData) / sizeof(maximLogoData[0]), 00138 maximLogoWidth); 00139 Text description; 00140 description.setText("MAXREFDES155#"); 00141 if (state == Completed) { 00142 startButton.render(bitmap, xOffset + x(), yOffset + y()); 00143 hardwareTestButton.render(bitmap, xOffset + x(), yOffset + y()); 00144 } else { 00145 description.setText(description.text() + "\nInitializing..."); 00146 description.setLineSpacing(3); 00147 } 00148 description.resize(description.preferredWidth(), 00149 description.preferredHeight()); 00150 description.move(0, maximLogoHeight + 2); 00151 description.render(bitmap, xOffset + x(), yOffset + y()); 00152 } 00153 00154 void InitWindow::updated() { 00155 switch (state) { 00156 case NotStarted: 00157 state = Running; 00158 invalidate(); 00159 break; 00160 00161 case Running: { 00162 // Enable coprocessor. 00163 if (!enableCoprocessor(coproc)) { 00164 if (windowManager()) { 00165 std::auto_ptr<Window> window( 00166 new ErrorWindow("Failed to enable coprocessor")); 00167 windowManager()->push(window); 00168 } 00169 break; 00170 } 00171 00172 // Enable ROM ID. 00173 if (!enableRomId(coproc)) { 00174 if (windowManager()) { 00175 std::auto_ptr<Window> window( 00176 new ErrorWindow("Failed to enable ROM ID")); 00177 windowManager()->push(window); 00178 } 00179 break; 00180 } 00181 00182 // Read ROM ID. 00183 if (Result<DS2476::Page::array> page = 00184 coproc.readMemory(DS2476::romOptionsPage)) { 00185 const MaximInterfaceCore::RomId::const_span romId = 00186 DS2476::RomOptions(page.value()).romId(); 00187 if (!valid(romId)) { 00188 if (windowManager()) { 00189 std::auto_ptr<Window> window(new ErrorWindow("ROM ID is not valid")); 00190 windowManager()->push(window); 00191 } 00192 break; 00193 } 00194 webId = MaximInterfaceCore::toHexString(romId); 00195 } else { 00196 if (windowManager()) { 00197 std::auto_ptr<Window> window(new ErrorWindow("Failed to read ROM ID")); 00198 windowManager()->push(window); 00199 } 00200 break; 00201 } 00202 00203 // Always start with laser disabled. 00204 sensorNode.detect(); 00205 sensorNode.setLaserEnabled(false); 00206 00207 if (CC3100::instance().start() != 0) { 00208 if (windowManager()) { 00209 std::auto_ptr<Window> window( 00210 new ErrorWindow("Failed to start WiFi interface")); 00211 windowManager()->push(window); 00212 } 00213 break; 00214 } 00215 wait_ms(1500); 00216 invalidate(); 00217 state = Completed; 00218 break; 00219 } 00220 00221 case Completed: 00222 break; 00223 } 00224 } 00225 00226 bool InitWindow::doProcessKey(Key key) { 00227 bool handled = false; 00228 if (state == Completed) { 00229 switch (key) { 00230 case LeftKey: 00231 startButton.setFocused(); 00232 handled = true; 00233 break; 00234 00235 case RightKey: 00236 hardwareTestButton.setFocused(); 00237 handled = true; 00238 break; 00239 00240 default: 00241 break; 00242 } 00243 } 00244 return handled; 00245 } 00246 00247 void InitWindow::startButtonClicked(Button *) { 00248 if (windowManager()) { 00249 std::auto_ptr<Window> window( 00250 new DisplayIdWindow(DisplayIdWindow::PreConnectMode)); 00251 windowManager()->push(window); 00252 } 00253 } 00254 00255 void InitWindow::hardwareTestButtonClicked(Button *) { 00256 if (windowManager()) { 00257 windowManager()->pop(); 00258 std::auto_ptr<Window> window(new HardwareTestWindow); 00259 windowManager()->push(window); 00260 } 00261 }
Generated on Tue Jul 12 2022 12:06:48 by
1.7.2