Sample GUI for LPC4088. Base code to begin dev
Dependencies: DMBasicGUI DMSupport
Fork of lpc4088_displaymodule_shipped_demo by
AppStatus.cpp@4:a7cbb22e4348, 2015-04-28 (annotated)
- Committer:
- alindvall
- Date:
- Tue Apr 28 12:21:14 2015 +0000
- Revision:
- 4:a7cbb22e4348
- Parent:
- 0:b94e330c98ac
Updated to latest version of the DMSupport and DMBasicGUI libraries
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alindvall | 0:b94e330c98ac | 1 | /* |
alindvall | 0:b94e330c98ac | 2 | * Copyright 2014 Embedded Artists AB |
alindvall | 0:b94e330c98ac | 3 | * |
alindvall | 0:b94e330c98ac | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
alindvall | 0:b94e330c98ac | 5 | * you may not use this file except in compliance with the License. |
alindvall | 0:b94e330c98ac | 6 | * You may obtain a copy of the License at |
alindvall | 0:b94e330c98ac | 7 | * |
alindvall | 0:b94e330c98ac | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
alindvall | 0:b94e330c98ac | 9 | * |
alindvall | 0:b94e330c98ac | 10 | * Unless required by applicable law or agreed to in writing, software |
alindvall | 0:b94e330c98ac | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
alindvall | 0:b94e330c98ac | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
alindvall | 0:b94e330c98ac | 13 | * See the License for the specific language governing permissions and |
alindvall | 0:b94e330c98ac | 14 | * limitations under the License. |
alindvall | 0:b94e330c98ac | 15 | */ |
alindvall | 0:b94e330c98ac | 16 | |
alindvall | 0:b94e330c98ac | 17 | |
alindvall | 0:b94e330c98ac | 18 | #include "mbed.h" |
alindvall | 0:b94e330c98ac | 19 | #include "EthernetInterface.h" |
alindvall | 0:b94e330c98ac | 20 | #include "AppStatus.h" |
alindvall | 0:b94e330c98ac | 21 | #include "lpc_swim_image.h" |
alindvall | 0:b94e330c98ac | 22 | #include "lpc_swim_font.h" |
alindvall | 0:b94e330c98ac | 23 | #include "BiosLoader.h" |
alindvall | 0:b94e330c98ac | 24 | |
alindvall | 0:b94e330c98ac | 25 | /****************************************************************************** |
alindvall | 0:b94e330c98ac | 26 | * Defines and typedefs |
alindvall | 0:b94e330c98ac | 27 | *****************************************************************************/ |
alindvall | 0:b94e330c98ac | 28 | |
alindvall | 0:b94e330c98ac | 29 | #define HEADER_X_OFF (20-5) |
alindvall | 0:b94e330c98ac | 30 | #define HEADER_Y_SPACING (20-5) |
alindvall | 0:b94e330c98ac | 31 | #define ITEM_CAPTION_X_OFF (40-15) |
alindvall | 0:b94e330c98ac | 32 | #define ITEM_CAPTION_Y_SPACING (swim_get_font_height(_win) + 5) |
alindvall | 0:b94e330c98ac | 33 | #define ITEM_VALUE_X_OFF (140-25) |
alindvall | 0:b94e330c98ac | 34 | #define COL3_OFF (230+70) |
alindvall | 0:b94e330c98ac | 35 | #define COL4 (COL3_OFF + ITEM_VALUE_X_OFF - 5) |
alindvall | 0:b94e330c98ac | 36 | |
alindvall | 0:b94e330c98ac | 37 | #define BIG_HEADER_X_OFF (25) |
alindvall | 0:b94e330c98ac | 38 | #define BIG_HEADER_Y_SPACING (25) |
alindvall | 0:b94e330c98ac | 39 | #define BIG_ITEM_CAPTION_X_OFF (BIG_HEADER_X_OFF + 10) |
alindvall | 0:b94e330c98ac | 40 | #define BIG_ITEM_CAPTION_Y_SPACING (swim_get_font_height(_win) + 10) |
alindvall | 0:b94e330c98ac | 41 | #define BIG_ITEM_VALUE_X_OFF (160) |
alindvall | 0:b94e330c98ac | 42 | #define BIG_COL3_OFF (520) |
alindvall | 0:b94e330c98ac | 43 | #define BIG_COL4 (BIG_COL3_OFF + BIG_ITEM_VALUE_X_OFF - 5) |
alindvall | 0:b94e330c98ac | 44 | |
alindvall | 0:b94e330c98ac | 45 | #define BTN_OFF 20 |
alindvall | 0:b94e330c98ac | 46 | |
alindvall | 0:b94e330c98ac | 47 | #define DEMO_VERSION "v1.0" |
alindvall | 0:b94e330c98ac | 48 | #define DEMO_BUILD_INFO __DATE__ " " __TIME__ |
alindvall | 0:b94e330c98ac | 49 | |
alindvall | 0:b94e330c98ac | 50 | #define DESCR(__res, __disp) \ |
alindvall | 0:b94e330c98ac | 51 | (((__res) == ((__disp)->currentResolution())) ? ("Active") : (((__disp)->isSupported(__res)) ? ("Supported") : ("N/A"))) |
alindvall | 0:b94e330c98ac | 52 | |
alindvall | 0:b94e330c98ac | 53 | |
alindvall | 0:b94e330c98ac | 54 | /****************************************************************************** |
alindvall | 0:b94e330c98ac | 55 | * Global variables |
alindvall | 0:b94e330c98ac | 56 | *****************************************************************************/ |
alindvall | 0:b94e330c98ac | 57 | |
alindvall | 0:b94e330c98ac | 58 | extern EthernetInterface eth; |
alindvall | 0:b94e330c98ac | 59 | extern bool ethInitialized; |
alindvall | 0:b94e330c98ac | 60 | extern bool ethUsingDHCP; |
alindvall | 0:b94e330c98ac | 61 | |
alindvall | 0:b94e330c98ac | 62 | /****************************************************************************** |
alindvall | 0:b94e330c98ac | 63 | * Private functions |
alindvall | 0:b94e330c98ac | 64 | *****************************************************************************/ |
alindvall | 0:b94e330c98ac | 65 | |
alindvall | 0:b94e330c98ac | 66 | static void buttonClicked(uint32_t x) |
alindvall | 0:b94e330c98ac | 67 | { |
alindvall | 0:b94e330c98ac | 68 | bool* done = (bool*)x; |
alindvall | 0:b94e330c98ac | 69 | *done = true; |
alindvall | 0:b94e330c98ac | 70 | } |
alindvall | 0:b94e330c98ac | 71 | |
alindvall | 0:b94e330c98ac | 72 | void AppStatus::draw() |
alindvall | 0:b94e330c98ac | 73 | { |
alindvall | 0:b94e330c98ac | 74 | swim_window_open(_win, |
alindvall | 0:b94e330c98ac | 75 | _disp->width(), _disp->height(), // full size |
alindvall | 0:b94e330c98ac | 76 | (COLOR_T*)_fb, |
alindvall | 0:b94e330c98ac | 77 | 0,0,_disp->width()-1, _disp->height()-1, // window position and size |
alindvall | 0:b94e330c98ac | 78 | 1, // border |
alindvall | 0:b94e330c98ac | 79 | BLACK, WHITE, BLACK); // colors: pen, backgr, forgr |
alindvall | 0:b94e330c98ac | 80 | |
alindvall | 0:b94e330c98ac | 81 | |
alindvall | 0:b94e330c98ac | 82 | swim_put_image_xy(_win, _bgImg.pixels, _bgImg.width, _bgImg.height, |
alindvall | 0:b94e330c98ac | 83 | (_disp->width()-_bgImg.width)/2, (_disp->height()-_bgImg.height)/2); |
alindvall | 0:b94e330c98ac | 84 | |
alindvall | 0:b94e330c98ac | 85 | if (_disp->width() == 480) { |
alindvall | 0:b94e330c98ac | 86 | draw480x272(); |
alindvall | 0:b94e330c98ac | 87 | } else { |
alindvall | 0:b94e330c98ac | 88 | draw800x480(); |
alindvall | 0:b94e330c98ac | 89 | } |
alindvall | 0:b94e330c98ac | 90 | |
alindvall | 0:b94e330c98ac | 91 | _btn = new ImageButton(_win->fb, _win->xpmax - BTN_OFF - _resOk->width(), _win->ypmax - BTN_OFF - _resOk->height(), _resOk->width(), _resOk->height()); |
alindvall | 0:b94e330c98ac | 92 | _btn->loadImages(_resOk); |
alindvall | 0:b94e330c98ac | 93 | _btn->draw(); |
alindvall | 0:b94e330c98ac | 94 | } |
alindvall | 0:b94e330c98ac | 95 | |
alindvall | 0:b94e330c98ac | 96 | void AppStatus::draw480x272() |
alindvall | 0:b94e330c98ac | 97 | { |
alindvall | 0:b94e330c98ac | 98 | char buff[120]; |
alindvall | 0:b94e330c98ac | 99 | |
alindvall | 0:b94e330c98ac | 100 | // Column 1 |
alindvall | 0:b94e330c98ac | 101 | swim_put_text_xy(_win, "Demo:", HEADER_X_OFF, HEADER_Y_SPACING); |
alindvall | 0:b94e330c98ac | 102 | swim_put_text_xy(_win, "Version:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1); |
alindvall | 0:b94e330c98ac | 103 | swim_put_text_xy(_win, "Build:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 2); |
alindvall | 0:b94e330c98ac | 104 | |
alindvall | 0:b94e330c98ac | 105 | swim_put_text_xy(_win, "Network:", HEADER_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4); |
alindvall | 0:b94e330c98ac | 106 | swim_put_text_xy(_win, "DHCP/Static:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5); |
alindvall | 0:b94e330c98ac | 107 | swim_put_text_xy(_win, "IP Address:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 6); |
alindvall | 0:b94e330c98ac | 108 | swim_put_text_xy(_win, "NetMask:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 7); |
alindvall | 0:b94e330c98ac | 109 | swim_put_text_xy(_win, "Gateway:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 8); |
alindvall | 0:b94e330c98ac | 110 | swim_put_text_xy(_win, "MAC Address:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 9); |
alindvall | 0:b94e330c98ac | 111 | |
alindvall | 0:b94e330c98ac | 112 | char mac[6]; |
alindvall | 0:b94e330c98ac | 113 | mbed_mac_address(mac); |
alindvall | 0:b94e330c98ac | 114 | snprintf(buff, 19, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
alindvall | 0:b94e330c98ac | 115 | swim_put_text_xy(_win, buff, ITEM_CAPTION_X_OFF+10, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 10); |
alindvall | 0:b94e330c98ac | 116 | |
alindvall | 0:b94e330c98ac | 117 | // Column 2 |
alindvall | 0:b94e330c98ac | 118 | swim_put_text_xy(_win, DEMO_VERSION, ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1); |
alindvall | 0:b94e330c98ac | 119 | swim_put_text_xy(_win, DEMO_BUILD_INFO, ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 2); |
alindvall | 0:b94e330c98ac | 120 | |
alindvall | 0:b94e330c98ac | 121 | swim_put_text_xy(_win, ethUsingDHCP?"DHCP":"Static IP", ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5); |
alindvall | 0:b94e330c98ac | 122 | if (ethInitialized) { |
alindvall | 0:b94e330c98ac | 123 | swim_put_text_xy(_win, eth.getIPAddress(), ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 6); |
alindvall | 0:b94e330c98ac | 124 | swim_put_text_xy(_win, eth.getNetworkMask(), ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 7); |
alindvall | 0:b94e330c98ac | 125 | swim_put_text_xy(_win, eth.getGateway(), ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 8); |
alindvall | 0:b94e330c98ac | 126 | //swim_put_text_xy(_win, eth.getMACAddress(), ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4); |
alindvall | 0:b94e330c98ac | 127 | } else { |
alindvall | 0:b94e330c98ac | 128 | swim_put_text_xy(_win, "Not Initialized", ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 6); |
alindvall | 0:b94e330c98ac | 129 | swim_put_text_xy(_win, "Not Initialized", ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 7); |
alindvall | 0:b94e330c98ac | 130 | swim_put_text_xy(_win, "Not Initialized", ITEM_VALUE_X_OFF-20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 8); |
alindvall | 0:b94e330c98ac | 131 | } |
alindvall | 0:b94e330c98ac | 132 | |
alindvall | 0:b94e330c98ac | 133 | // Column 3 |
alindvall | 0:b94e330c98ac | 134 | swim_put_text_xy(_win, "Display:", COL3_OFF+HEADER_X_OFF, HEADER_Y_SPACING); |
alindvall | 0:b94e330c98ac | 135 | swim_put_text_xy(_win, "Size:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1); |
alindvall | 0:b94e330c98ac | 136 | swim_put_text_xy(_win, "Landscape:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 2); |
alindvall | 0:b94e330c98ac | 137 | swim_put_text_xy(_win, "Resolutions:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 3); |
alindvall | 0:b94e330c98ac | 138 | swim_put_text_xy(_win, "16bit rgb565:", COL3_OFF+ITEM_CAPTION_X_OFF+10, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4); |
alindvall | 0:b94e330c98ac | 139 | swim_put_text_xy(_win, "18bit rgb666:", COL3_OFF+ITEM_CAPTION_X_OFF+10, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5); |
alindvall | 0:b94e330c98ac | 140 | swim_put_text_xy(_win, "24bit rgb888:", COL3_OFF+ITEM_CAPTION_X_OFF+10, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 6); |
alindvall | 0:b94e330c98ac | 141 | |
alindvall | 0:b94e330c98ac | 142 | swim_put_text_xy(_win, "BIOS:", COL3_OFF+HEADER_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 8); |
alindvall | 0:b94e330c98ac | 143 | { |
alindvall | 0:b94e330c98ac | 144 | uint8_t type, maj, min, rev; |
alindvall | 0:b94e330c98ac | 145 | BiosLoader::instance().getBiosStats(type, maj, min, rev); |
alindvall | 0:b94e330c98ac | 146 | snprintf(buff, 25, "v%u.%u.%u (board type %u)", maj, min, rev, type); |
alindvall | 0:b94e330c98ac | 147 | swim_put_text_xy(_win, buff, COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 9); |
alindvall | 0:b94e330c98ac | 148 | } |
alindvall | 0:b94e330c98ac | 149 | |
alindvall | 0:b94e330c98ac | 150 | // Column 4 |
alindvall | 0:b94e330c98ac | 151 | sprintf(buff, "%d x %d pixels", _disp->width(), _disp->height()); |
alindvall | 0:b94e330c98ac | 152 | swim_put_text_xy(_win, buff, COL4 -20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1); |
alindvall | 0:b94e330c98ac | 153 | |
alindvall | 0:b94e330c98ac | 154 | sprintf(buff, "%s", _disp->landscape()?"YES":"NO"); |
alindvall | 0:b94e330c98ac | 155 | swim_put_text_xy(_win, buff, COL4 -20, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 2); |
alindvall | 0:b94e330c98ac | 156 | |
alindvall | 0:b94e330c98ac | 157 | sprintf(buff, "%s", DESCR(Display::Resolution_16bit_rgb565, _disp)); |
alindvall | 0:b94e330c98ac | 158 | swim_put_text_xy(_win, buff, COL4, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4); |
alindvall | 0:b94e330c98ac | 159 | |
alindvall | 0:b94e330c98ac | 160 | sprintf(buff, "%s", DESCR(Display::Resolution_18bit_rgb666, _disp)); |
alindvall | 0:b94e330c98ac | 161 | swim_put_text_xy(_win, buff, COL4, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5); |
alindvall | 0:b94e330c98ac | 162 | |
alindvall | 0:b94e330c98ac | 163 | sprintf(buff, "%s", DESCR(Display::Resolution_24bit_rgb888, _disp)); |
alindvall | 0:b94e330c98ac | 164 | swim_put_text_xy(_win, buff, COL4, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 6); |
alindvall | 0:b94e330c98ac | 165 | } |
alindvall | 0:b94e330c98ac | 166 | |
alindvall | 0:b94e330c98ac | 167 | void AppStatus::draw800x480() |
alindvall | 0:b94e330c98ac | 168 | { |
alindvall | 0:b94e330c98ac | 169 | char buff[120]; |
alindvall | 0:b94e330c98ac | 170 | |
alindvall | 0:b94e330c98ac | 171 | // Column 1 |
alindvall | 0:b94e330c98ac | 172 | swim_put_text_xy(_win, "Demo:", BIG_HEADER_X_OFF, BIG_HEADER_Y_SPACING); |
alindvall | 0:b94e330c98ac | 173 | swim_put_text_xy(_win, "Version:", BIG_ITEM_CAPTION_X_OFF, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 1); |
alindvall | 0:b94e330c98ac | 174 | swim_put_text_xy(_win, "Build:", BIG_ITEM_CAPTION_X_OFF, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 2); |
alindvall | 0:b94e330c98ac | 175 | |
alindvall | 0:b94e330c98ac | 176 | swim_put_text_xy(_win, "Network:", BIG_HEADER_X_OFF, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 4); |
alindvall | 0:b94e330c98ac | 177 | swim_put_text_xy(_win, "DHCP/Static:", BIG_ITEM_CAPTION_X_OFF, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 5); |
alindvall | 0:b94e330c98ac | 178 | swim_put_text_xy(_win, "IP Address:", BIG_ITEM_CAPTION_X_OFF, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 6); |
alindvall | 0:b94e330c98ac | 179 | swim_put_text_xy(_win, "NetMask:", BIG_ITEM_CAPTION_X_OFF, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 7); |
alindvall | 0:b94e330c98ac | 180 | swim_put_text_xy(_win, "Gateway:", BIG_ITEM_CAPTION_X_OFF, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 8); |
alindvall | 0:b94e330c98ac | 181 | swim_put_text_xy(_win, "MAC Address:", BIG_ITEM_CAPTION_X_OFF, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 9); |
alindvall | 0:b94e330c98ac | 182 | |
alindvall | 0:b94e330c98ac | 183 | // Column 2 |
alindvall | 0:b94e330c98ac | 184 | swim_put_text_xy(_win, DEMO_VERSION, BIG_ITEM_VALUE_X_OFF-20, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 1); |
alindvall | 0:b94e330c98ac | 185 | swim_put_text_xy(_win, DEMO_BUILD_INFO, BIG_ITEM_VALUE_X_OFF-20, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 2); |
alindvall | 0:b94e330c98ac | 186 | |
alindvall | 0:b94e330c98ac | 187 | swim_put_text_xy(_win, ethUsingDHCP?"DHCP":"Static IP", BIG_ITEM_VALUE_X_OFF-20, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 5); |
alindvall | 0:b94e330c98ac | 188 | if (ethInitialized) { |
alindvall | 0:b94e330c98ac | 189 | swim_put_text_xy(_win, eth.getIPAddress(), BIG_ITEM_VALUE_X_OFF-20, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 6); |
alindvall | 0:b94e330c98ac | 190 | swim_put_text_xy(_win, eth.getNetworkMask(), BIG_ITEM_VALUE_X_OFF-20, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 7); |
alindvall | 0:b94e330c98ac | 191 | swim_put_text_xy(_win, eth.getGateway(), BIG_ITEM_VALUE_X_OFF-20, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 8); |
alindvall | 0:b94e330c98ac | 192 | } else { |
alindvall | 0:b94e330c98ac | 193 | swim_put_text_xy(_win, "Not Initialized", BIG_ITEM_VALUE_X_OFF-20, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 6); |
alindvall | 0:b94e330c98ac | 194 | swim_put_text_xy(_win, "Not Initialized", BIG_ITEM_VALUE_X_OFF-20, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 7); |
alindvall | 0:b94e330c98ac | 195 | swim_put_text_xy(_win, "Not Initialized", BIG_ITEM_VALUE_X_OFF-20, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 8); |
alindvall | 0:b94e330c98ac | 196 | } |
alindvall | 0:b94e330c98ac | 197 | char mac[6]; |
alindvall | 0:b94e330c98ac | 198 | mbed_mac_address(mac); |
alindvall | 0:b94e330c98ac | 199 | snprintf(buff, 19, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
alindvall | 0:b94e330c98ac | 200 | swim_put_text_xy(_win, buff, BIG_ITEM_VALUE_X_OFF-20, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 9); |
alindvall | 0:b94e330c98ac | 201 | |
alindvall | 0:b94e330c98ac | 202 | // Column 3 |
alindvall | 0:b94e330c98ac | 203 | swim_put_text_xy(_win, "Display:", BIG_COL3_OFF+BIG_HEADER_X_OFF, BIG_HEADER_Y_SPACING); |
alindvall | 0:b94e330c98ac | 204 | swim_put_text_xy(_win, "Size:", BIG_COL3_OFF+BIG_ITEM_CAPTION_X_OFF, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 1); |
alindvall | 0:b94e330c98ac | 205 | swim_put_text_xy(_win, "Landscape:", BIG_COL3_OFF+BIG_ITEM_CAPTION_X_OFF, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 2); |
alindvall | 0:b94e330c98ac | 206 | swim_put_text_xy(_win, "Resolutions:", BIG_COL3_OFF+BIG_ITEM_CAPTION_X_OFF, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 3); |
alindvall | 0:b94e330c98ac | 207 | swim_put_text_xy(_win, "16bit rgb565:", BIG_COL3_OFF+BIG_ITEM_CAPTION_X_OFF+10, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 4); |
alindvall | 0:b94e330c98ac | 208 | swim_put_text_xy(_win, "18bit rgb666:", BIG_COL3_OFF+BIG_ITEM_CAPTION_X_OFF+10, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 5); |
alindvall | 0:b94e330c98ac | 209 | swim_put_text_xy(_win, "24bit rgb888:", BIG_COL3_OFF+BIG_ITEM_CAPTION_X_OFF+10, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 6); |
alindvall | 0:b94e330c98ac | 210 | |
alindvall | 0:b94e330c98ac | 211 | swim_put_text_xy(_win, "BIOS:", BIG_COL3_OFF+BIG_HEADER_X_OFF, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 8); |
alindvall | 0:b94e330c98ac | 212 | { |
alindvall | 0:b94e330c98ac | 213 | uint8_t type, maj, min, rev; |
alindvall | 0:b94e330c98ac | 214 | BiosLoader::instance().getBiosStats(type, maj, min, rev); |
alindvall | 0:b94e330c98ac | 215 | snprintf(buff, 25, "v%u.%u.%u (board type %u)", maj, min, rev, type); |
alindvall | 0:b94e330c98ac | 216 | swim_put_text_xy(_win, buff, BIG_COL3_OFF+BIG_ITEM_CAPTION_X_OFF, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 9); |
alindvall | 0:b94e330c98ac | 217 | } |
alindvall | 0:b94e330c98ac | 218 | |
alindvall | 0:b94e330c98ac | 219 | // Column 4 |
alindvall | 0:b94e330c98ac | 220 | sprintf(buff, "%d x %d pixels", _disp->width(), _disp->height()); |
alindvall | 0:b94e330c98ac | 221 | swim_put_text_xy(_win, buff, BIG_COL4 -20, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 1); |
alindvall | 0:b94e330c98ac | 222 | |
alindvall | 0:b94e330c98ac | 223 | sprintf(buff, "%s", _disp->landscape()?"YES":"NO"); |
alindvall | 0:b94e330c98ac | 224 | swim_put_text_xy(_win, buff, BIG_COL4 -20, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 2); |
alindvall | 0:b94e330c98ac | 225 | |
alindvall | 0:b94e330c98ac | 226 | sprintf(buff, "%s", DESCR(Display::Resolution_16bit_rgb565, _disp)); |
alindvall | 0:b94e330c98ac | 227 | swim_put_text_xy(_win, buff, BIG_COL4, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 4); |
alindvall | 0:b94e330c98ac | 228 | |
alindvall | 0:b94e330c98ac | 229 | sprintf(buff, "%s", DESCR(Display::Resolution_18bit_rgb666, _disp)); |
alindvall | 0:b94e330c98ac | 230 | swim_put_text_xy(_win, buff, BIG_COL4, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 5); |
alindvall | 0:b94e330c98ac | 231 | |
alindvall | 0:b94e330c98ac | 232 | sprintf(buff, "%s", DESCR(Display::Resolution_24bit_rgb888, _disp)); |
alindvall | 0:b94e330c98ac | 233 | swim_put_text_xy(_win, buff, BIG_COL4, BIG_HEADER_Y_SPACING + BIG_ITEM_CAPTION_Y_SPACING * 6); |
alindvall | 0:b94e330c98ac | 234 | } |
alindvall | 0:b94e330c98ac | 235 | |
alindvall | 0:b94e330c98ac | 236 | /****************************************************************************** |
alindvall | 0:b94e330c98ac | 237 | * Public functions |
alindvall | 0:b94e330c98ac | 238 | *****************************************************************************/ |
alindvall | 0:b94e330c98ac | 239 | |
alindvall | 0:b94e330c98ac | 240 | AppStatus::AppStatus() : _disp(NULL), _win(NULL), _fb(NULL), _btn(NULL) |
alindvall | 0:b94e330c98ac | 241 | { |
alindvall | 0:b94e330c98ac | 242 | _bgImg.pointerToFree = NULL; |
alindvall | 0:b94e330c98ac | 243 | _bgImg.pixels = NULL; |
alindvall | 0:b94e330c98ac | 244 | } |
alindvall | 0:b94e330c98ac | 245 | |
alindvall | 0:b94e330c98ac | 246 | AppStatus::~AppStatus() |
alindvall | 0:b94e330c98ac | 247 | { |
alindvall | 0:b94e330c98ac | 248 | teardown(); |
alindvall | 0:b94e330c98ac | 249 | } |
alindvall | 0:b94e330c98ac | 250 | |
alindvall | 0:b94e330c98ac | 251 | bool AppStatus::setup() |
alindvall | 0:b94e330c98ac | 252 | { |
alindvall | 0:b94e330c98ac | 253 | RtosLog* log = DMBoard::instance().logger(); |
alindvall | 0:b94e330c98ac | 254 | |
alindvall | 0:b94e330c98ac | 255 | _disp = DMBoard::instance().display(); |
alindvall | 0:b94e330c98ac | 256 | _win = (SWIM_WINDOW_T*)malloc(sizeof(SWIM_WINDOW_T)); |
alindvall | 0:b94e330c98ac | 257 | _fb = _disp->allocateFramebuffer(); |
alindvall | 0:b94e330c98ac | 258 | |
alindvall | 0:b94e330c98ac | 259 | if (_win == NULL || _fb == NULL) { |
alindvall | 0:b94e330c98ac | 260 | log->printf("Failed to allocate memory for framebuffer\r\n"); |
alindvall | 0:b94e330c98ac | 261 | return false; |
alindvall | 0:b94e330c98ac | 262 | } |
alindvall | 0:b94e330c98ac | 263 | |
alindvall | 0:b94e330c98ac | 264 | if (Image::decode(_resAbout, Image::RES_16BIT, &_bgImg) != 0) { |
alindvall | 0:b94e330c98ac | 265 | log->printf("Failed to load background image\n"); |
alindvall | 0:b94e330c98ac | 266 | return false; |
alindvall | 0:b94e330c98ac | 267 | } |
alindvall | 0:b94e330c98ac | 268 | |
alindvall | 0:b94e330c98ac | 269 | return true; |
alindvall | 0:b94e330c98ac | 270 | } |
alindvall | 0:b94e330c98ac | 271 | |
alindvall | 0:b94e330c98ac | 272 | void AppStatus::runToCompletion() |
alindvall | 0:b94e330c98ac | 273 | { |
alindvall | 0:b94e330c98ac | 274 | bool done = false; |
alindvall | 0:b94e330c98ac | 275 | draw(); |
alindvall | 0:b94e330c98ac | 276 | _btn->setAction(buttonClicked, (uint32_t)&done); |
alindvall | 0:b94e330c98ac | 277 | void* oldFB = _disp->swapFramebuffer(_fb); |
alindvall | 0:b94e330c98ac | 278 | |
alindvall | 0:b94e330c98ac | 279 | // Wait for touches, but the AppLauncher is already listening |
alindvall | 0:b94e330c98ac | 280 | // for new touch event and sends a signal to its thread which |
alindvall | 0:b94e330c98ac | 281 | // is the same as runs this function so it is enough to wait |
alindvall | 0:b94e330c98ac | 282 | // for that signal. |
alindvall | 0:b94e330c98ac | 283 | TouchPanel* touch = DMBoard::instance().touchPanel(); |
alindvall | 0:b94e330c98ac | 284 | touch_coordinate_t coord; |
alindvall | 0:b94e330c98ac | 285 | while(!done) { |
alindvall | 0:b94e330c98ac | 286 | Thread::signal_wait(0x1); |
alindvall | 0:b94e330c98ac | 287 | if (touch->read(coord) == TouchPanel::TouchError_Ok) { |
alindvall | 0:b94e330c98ac | 288 | if (_btn->handle(coord.x, coord.y, coord.z > 0)) { |
alindvall | 0:b94e330c98ac | 289 | _btn->draw(); |
alindvall | 0:b94e330c98ac | 290 | } |
alindvall | 0:b94e330c98ac | 291 | } |
alindvall | 0:b94e330c98ac | 292 | } |
alindvall | 0:b94e330c98ac | 293 | |
alindvall | 0:b94e330c98ac | 294 | // User has clicked the button, restore the original FB |
alindvall | 0:b94e330c98ac | 295 | _disp->swapFramebuffer(oldFB); |
alindvall | 0:b94e330c98ac | 296 | swim_window_close(_win); |
alindvall | 0:b94e330c98ac | 297 | } |
alindvall | 0:b94e330c98ac | 298 | |
alindvall | 0:b94e330c98ac | 299 | bool AppStatus::teardown() |
alindvall | 0:b94e330c98ac | 300 | { |
alindvall | 0:b94e330c98ac | 301 | if (_win != NULL) { |
alindvall | 0:b94e330c98ac | 302 | free(_win); |
alindvall | 0:b94e330c98ac | 303 | _win = NULL; |
alindvall | 0:b94e330c98ac | 304 | } |
alindvall | 0:b94e330c98ac | 305 | if (_fb != NULL) { |
alindvall | 0:b94e330c98ac | 306 | free(_fb); |
alindvall | 0:b94e330c98ac | 307 | _fb = NULL; |
alindvall | 0:b94e330c98ac | 308 | } |
alindvall | 0:b94e330c98ac | 309 | if (_btn != NULL) { |
alindvall | 0:b94e330c98ac | 310 | delete _btn; |
alindvall | 0:b94e330c98ac | 311 | _btn = NULL; |
alindvall | 0:b94e330c98ac | 312 | } |
alindvall | 0:b94e330c98ac | 313 | if (_bgImg.pointerToFree != NULL) { |
alindvall | 0:b94e330c98ac | 314 | free(_bgImg.pointerToFree); |
alindvall | 0:b94e330c98ac | 315 | _bgImg.pointerToFree = NULL; |
alindvall | 0:b94e330c98ac | 316 | } |
alindvall | 0:b94e330c98ac | 317 | return true; |
alindvall | 0:b94e330c98ac | 318 | } |
alindvall | 0:b94e330c98ac | 319 | |
alindvall | 0:b94e330c98ac | 320 | void AppStatus::addResource(Resources id, Resource* res) |
alindvall | 0:b94e330c98ac | 321 | { |
alindvall | 0:b94e330c98ac | 322 | if (id == Resource_Ok_button) { |
alindvall | 0:b94e330c98ac | 323 | _resOk = res; |
alindvall | 0:b94e330c98ac | 324 | } else { |
alindvall | 0:b94e330c98ac | 325 | _resAbout = res; |
alindvall | 0:b94e330c98ac | 326 | } |
alindvall | 0:b94e330c98ac | 327 | } |
alindvall | 0:b94e330c98ac | 328 | |
alindvall | 0:b94e330c98ac | 329 | |
alindvall | 0:b94e330c98ac | 330 | |
alindvall | 0:b94e330c98ac | 331 |