![](/media/cache/group/quattro-II-150930.jpg.50x50_q85.jpg)
Strength of Irradiance and the UV Index chart page added
Dependencies: TFT_fonts UniGraphic VEML6075 mbed vt100
Fork of quattro_vishay_6075 by
This is a forked version of quattro_vishay_6075.
An additional Strength of Irradiance and the UV Index page added.
NOTE: Please update the VEML6075.lib before compile.
main.cpp@1:6b82f17ff8e0, 2017-10-18 (annotated)
- Committer:
- Rhyme
- Date:
- Wed Oct 18 05:19:39 2017 +0000
- Revision:
- 1:6b82f17ff8e0
- Parent:
- 0:11b872c2badc
Strength of Irradiance and the UV Index page added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shockey | 0:11b872c2badc | 1 | #include "mbed.h" |
shockey | 0:11b872c2badc | 2 | #include "vt100.h" |
shockey | 0:11b872c2badc | 3 | #include "quattro.h" |
shockey | 0:11b872c2badc | 4 | #include "SEPS225.h" |
shockey | 0:11b872c2badc | 5 | #include "Arial12x12.h" |
shockey | 0:11b872c2badc | 6 | #include "Arial24x23.h" |
shockey | 0:11b872c2badc | 7 | #include "Arial28x28.h" |
shockey | 0:11b872c2badc | 8 | #include "font_big.h" |
shockey | 0:11b872c2badc | 9 | #include "VEML6075.h" |
shockey | 0:11b872c2badc | 10 | |
shockey | 0:11b872c2badc | 11 | #include "kinetis_raw128x128.h" |
shockey | 0:11b872c2badc | 12 | |
shockey | 0:11b872c2badc | 13 | // dummy assign for RESET PIN |
shockey | 0:11b872c2badc | 14 | #define PIN_RESET_TFT PTC5 |
shockey | 0:11b872c2badc | 15 | |
shockey | 0:11b872c2badc | 16 | #define VEML6075_I2C_ADDRESS (0x10) |
shockey | 0:11b872c2badc | 17 | |
shockey | 0:11b872c2badc | 18 | VEML6075 *veml6075 = 0 ; |
shockey | 0:11b872c2badc | 19 | |
shockey | 0:11b872c2badc | 20 | SEPS225 TFT(SPI_8, 10000000, |
shockey | 0:11b872c2badc | 21 | PIN_OLED_MOSI, PIN_OLED_MISO, PIN_OLED_SCLK, |
shockey | 0:11b872c2badc | 22 | PIN_OLED_CS, PIN_RESET_TFT, PIN_OLED_RS, "OLED SEPS225") ; |
shockey | 0:11b872c2badc | 23 | |
shockey | 0:11b872c2badc | 24 | Serial pc(PTE0, PTE1) ; |
shockey | 0:11b872c2badc | 25 | vt100 *tty = 0 ; |
shockey | 0:11b872c2badc | 26 | int page = 0 ; |
shockey | 0:11b872c2badc | 27 | int prevPage = 0 ; |
shockey | 0:11b872c2badc | 28 | int numPages = 6 ; |
shockey | 0:11b872c2badc | 29 | |
shockey | 0:11b872c2badc | 30 | void enableSW(void) |
shockey | 0:11b872c2badc | 31 | { |
shockey | 0:11b872c2badc | 32 | int3_r->enable_irq() ; |
shockey | 0:11b872c2badc | 33 | int4_g->enable_irq() ; |
shockey | 0:11b872c2badc | 34 | int5_b->enable_irq() ; |
shockey | 0:11b872c2badc | 35 | } |
shockey | 0:11b872c2badc | 36 | |
shockey | 0:11b872c2badc | 37 | void disableSW(void) |
shockey | 0:11b872c2badc | 38 | { |
shockey | 0:11b872c2badc | 39 | int3_r->disable_irq() ; |
shockey | 0:11b872c2badc | 40 | int4_g->disable_irq() ; |
shockey | 0:11b872c2badc | 41 | int5_b->disable_irq() ; |
shockey | 0:11b872c2badc | 42 | } |
shockey | 0:11b872c2badc | 43 | |
shockey | 0:11b872c2badc | 44 | void swRPressed(void) |
shockey | 0:11b872c2badc | 45 | { |
shockey | 0:11b872c2badc | 46 | int3_r->disable_irq() ; |
shockey | 0:11b872c2badc | 47 | *led3_org = !(*led3_org) ; |
shockey | 0:11b872c2badc | 48 | page++ ; |
shockey | 0:11b872c2badc | 49 | page %= numPages ; |
shockey | 0:11b872c2badc | 50 | wait(0.25) ; |
shockey | 0:11b872c2badc | 51 | int3_r->enable_irq() ; |
shockey | 0:11b872c2badc | 52 | } |
shockey | 0:11b872c2badc | 53 | |
shockey | 0:11b872c2badc | 54 | void swGPressed(void) |
shockey | 0:11b872c2badc | 55 | { |
shockey | 0:11b872c2badc | 56 | int4_g->disable_irq() ; |
shockey | 0:11b872c2badc | 57 | *led4_org = !(*led4_org) ; |
shockey | 0:11b872c2badc | 58 | page = 0 ; |
shockey | 0:11b872c2badc | 59 | wait(0.25) ; |
shockey | 0:11b872c2badc | 60 | int4_g->enable_irq() ; |
shockey | 0:11b872c2badc | 61 | } |
shockey | 0:11b872c2badc | 62 | |
shockey | 0:11b872c2badc | 63 | void swBPressed(void) |
shockey | 0:11b872c2badc | 64 | { |
shockey | 0:11b872c2badc | 65 | int5_b->disable_irq() ; |
shockey | 0:11b872c2badc | 66 | *led5_org = !(*led5_org) ; |
shockey | 0:11b872c2badc | 67 | page-- ; |
shockey | 0:11b872c2badc | 68 | if (page < 0) { |
shockey | 0:11b872c2badc | 69 | page = numPages - 1 ; |
shockey | 0:11b872c2badc | 70 | } |
shockey | 0:11b872c2badc | 71 | wait(0.25) ; |
shockey | 0:11b872c2badc | 72 | int5_b->enable_irq() ; |
shockey | 0:11b872c2badc | 73 | } |
shockey | 0:11b872c2badc | 74 | |
shockey | 0:11b872c2badc | 75 | void doLines(unsigned short color) |
shockey | 0:11b872c2badc | 76 | { |
shockey | 0:11b872c2badc | 77 | TFT.cls() ; |
shockey | 0:11b872c2badc | 78 | for (int i = 0 ; i < 128 ; i += 8) { |
shockey | 0:11b872c2badc | 79 | TFT.line(i, 0, 127-i, 127, color) ; |
shockey | 0:11b872c2badc | 80 | } |
shockey | 0:11b872c2badc | 81 | } |
shockey | 0:11b872c2badc | 82 | |
shockey | 0:11b872c2badc | 83 | void doCircles(unsigned short color) |
shockey | 0:11b872c2badc | 84 | { |
shockey | 0:11b872c2badc | 85 | TFT.cls() ; |
shockey | 0:11b872c2badc | 86 | for (int i = 0 ; i < 64 ; i+= 4) { |
shockey | 0:11b872c2badc | 87 | TFT.circle(64, 64, i, color) ; |
shockey | 0:11b872c2badc | 88 | } |
shockey | 0:11b872c2badc | 89 | } |
shockey | 0:11b872c2badc | 90 | |
shockey | 0:11b872c2badc | 91 | void doRects(unsigned short color) |
shockey | 0:11b872c2badc | 92 | { |
shockey | 0:11b872c2badc | 93 | |
shockey | 0:11b872c2badc | 94 | *oled_cs = 0 ; |
shockey | 0:11b872c2badc | 95 | TFT.cls() ; |
shockey | 0:11b872c2badc | 96 | TFT.line(32, 32, 100, 100, color) ; |
shockey | 0:11b872c2badc | 97 | TFT.rect(32, 32, 100, 100, color) ; |
shockey | 0:11b872c2badc | 98 | /* |
shockey | 0:11b872c2badc | 99 | for (i = 0 ; i < 64 ; i += 4) { |
shockey | 0:11b872c2badc | 100 | x0 = 64 - i ; |
shockey | 0:11b872c2badc | 101 | x1 = 64 + i ; |
shockey | 0:11b872c2badc | 102 | y0 = 64 - i ; |
shockey | 0:11b872c2badc | 103 | y1 = 64 + i ; |
shockey | 0:11b872c2badc | 104 | TFT.rect(x0, y0, x1, y1, color) ; |
shockey | 0:11b872c2badc | 105 | } |
shockey | 0:11b872c2badc | 106 | */ |
shockey | 0:11b872c2badc | 107 | *oled_cs = 1 ; |
shockey | 0:11b872c2badc | 108 | } |
shockey | 0:11b872c2badc | 109 | |
shockey | 0:11b872c2badc | 110 | void doText(void) |
shockey | 0:11b872c2badc | 111 | { |
shockey | 0:11b872c2badc | 112 | TFT.cls() ; |
shockey | 0:11b872c2badc | 113 | // *oled_cs = 0 ; |
shockey | 0:11b872c2badc | 114 | // TFT.line(0, 64, 127, 64, 0xFF00) ; |
shockey | 0:11b872c2badc | 115 | TFT.set_font((unsigned char*) Arial12x12); |
shockey | 0:11b872c2badc | 116 | TFT.foreground(0xFFFF) ; |
shockey | 0:11b872c2badc | 117 | TFT.background(0x0000) ; |
shockey | 0:11b872c2badc | 118 | TFT.locate(10, 20) ; |
shockey | 0:11b872c2badc | 119 | TFT.printf("MBED") ; |
shockey | 0:11b872c2badc | 120 | TFT.foreground(0xFFFF); |
shockey | 0:11b872c2badc | 121 | TFT.locate(20, 60) ; |
shockey | 0:11b872c2badc | 122 | TFT.printf("2.8\"TFT") ; |
shockey | 0:11b872c2badc | 123 | TFT.locate(20, 80) ; |
shockey | 0:11b872c2badc | 124 | TFT.printf("ABCDEF") ; |
shockey | 0:11b872c2badc | 125 | |
shockey | 0:11b872c2badc | 126 | // *oled_cs = 1 ; |
shockey | 0:11b872c2badc | 127 | } |
shockey | 0:11b872c2badc | 128 | |
shockey | 0:11b872c2badc | 129 | void doSplash(void) |
shockey | 0:11b872c2badc | 130 | { |
shockey | 0:11b872c2badc | 131 | TFT.cls() ; |
shockey | 0:11b872c2badc | 132 | TFT.foreground(0xFFFF) ; |
shockey | 0:11b872c2badc | 133 | TFT.background(0x0000) ; |
shockey | 0:11b872c2badc | 134 | TFT.set_font((unsigned char*) Arial28x28); |
shockey | 0:11b872c2badc | 135 | TFT.locate(5, 5) ; |
shockey | 0:11b872c2badc | 136 | TFT.printf("Marubun") ; |
shockey | 0:11b872c2badc | 137 | TFT.set_font((unsigned char*) Arial12x12); |
shockey | 0:11b872c2badc | 138 | TFT.locate(35, 40) ; |
shockey | 0:11b872c2badc | 139 | TFT.printf("quattro-II") ; |
shockey | 0:11b872c2badc | 140 | TFT.locate(50, 60) ; |
shockey | 0:11b872c2badc | 141 | TFT.printf("&") ; |
shockey | 0:11b872c2badc | 142 | TFT.locate(40, 80) ; |
shockey | 0:11b872c2badc | 143 | TFT.printf("shaft-II") ; |
shockey | 0:11b872c2badc | 144 | TFT.foreground(0xFD20) ; |
shockey | 0:11b872c2badc | 145 | TFT.set_font((unsigned char*) Arial24x23); |
shockey | 0:11b872c2badc | 146 | TFT.locate(10, 100) ; |
shockey | 0:11b872c2badc | 147 | TFT.printf("Kinetis") ; |
shockey | 0:11b872c2badc | 148 | TFT.foreground(0xFFFF) ; |
shockey | 0:11b872c2badc | 149 | TFT.set_font((unsigned char*) Arial12x12); |
shockey | 0:11b872c2badc | 150 | } |
shockey | 0:11b872c2badc | 151 | |
shockey | 0:11b872c2badc | 152 | void doPict(unsigned short pict[]) |
shockey | 0:11b872c2badc | 153 | { |
shockey | 0:11b872c2badc | 154 | int x, y ; |
shockey | 0:11b872c2badc | 155 | TFT.display(0) ; |
shockey | 0:11b872c2badc | 156 | // TFT.window(0, 0, 127, 127) ; |
shockey | 0:11b872c2badc | 157 | TFT.cls() ; |
shockey | 0:11b872c2badc | 158 | for (y = 0 ; y < 128 ; y++ ) { |
shockey | 0:11b872c2badc | 159 | for (x = 0 ; x < 128 ; x++ ) { |
shockey | 0:11b872c2badc | 160 | TFT.pixel(x, y, pict[128*y + x]) ; |
shockey | 0:11b872c2badc | 161 | } |
shockey | 0:11b872c2badc | 162 | } |
shockey | 0:11b872c2badc | 163 | // TFT.window_pushpixelbuf(pict, 128*128) ; |
shockey | 0:11b872c2badc | 164 | TFT.display(1) ; |
shockey | 0:11b872c2badc | 165 | } |
shockey | 0:11b872c2badc | 166 | |
shockey | 0:11b872c2badc | 167 | void init_sensors(void) |
shockey | 0:11b872c2badc | 168 | { |
shockey | 0:11b872c2badc | 169 | veml6075 = new VEML6075(PTB3, PTB2, VEML6075_I2C_ADDRESS) ; // for FRDM-K22F |
shockey | 0:11b872c2badc | 170 | veml6075->setUVConf(0x00) ; |
shockey | 0:11b872c2badc | 171 | // veml6040 = new VEML6040(PTB3, PTB2, VEML6040_I2C_ADDRESS) ; // for FRDM-K22F |
shockey | 0:11b872c2badc | 172 | // veml6040->setCOLORConf(0x00) ; |
shockey | 0:11b872c2badc | 173 | } |
shockey | 0:11b872c2badc | 174 | |
shockey | 0:11b872c2badc | 175 | void reportVEML6075(VEML6075 *veml,int x, int y) |
shockey | 0:11b872c2badc | 176 | { |
shockey | 0:11b872c2badc | 177 | uint8_t uvconf = 0x00 ; |
shockey | 0:11b872c2badc | 178 | uint16_t id = 0 ; |
shockey | 0:11b872c2badc | 179 | uint16_t uvadata = 0 ; |
shockey | 0:11b872c2badc | 180 | uint16_t uvbdata = 0 ; |
shockey | 0:11b872c2badc | 181 | uint16_t uvcomp1data = 0 ; |
shockey | 0:11b872c2badc | 182 | uint16_t uvcomp2data = 0 ; |
shockey | 0:11b872c2badc | 183 | float fUVA = 0.0 ; |
shockey | 0:11b872c2badc | 184 | float fUVA_CIE = 0.0 ; |
shockey | 0:11b872c2badc | 185 | float fUVB = 0.0 ; |
shockey | 0:11b872c2badc | 186 | float fUVB_CIE = 0.0 ; |
shockey | 0:11b872c2badc | 187 | float uvi = 0 ; |
shockey | 0:11b872c2badc | 188 | |
Rhyme | 1:6b82f17ff8e0 | 189 | veml6075->setUVConf(uvconf) ; |
Rhyme | 1:6b82f17ff8e0 | 190 | veml6075->getUVConf(&uvconf) ; |
Rhyme | 1:6b82f17ff8e0 | 191 | veml6075->getID(&id) ; |
shockey | 0:11b872c2badc | 192 | |
Rhyme | 1:6b82f17ff8e0 | 193 | veml6075->getUVAData(&uvadata) ; |
Rhyme | 1:6b82f17ff8e0 | 194 | veml6075->getUVBData(&uvbdata) ; |
Rhyme | 1:6b82f17ff8e0 | 195 | veml6075->getUVCOMP1Data(&uvcomp1data) ; |
Rhyme | 1:6b82f17ff8e0 | 196 | veml6075->getUVCOMP2Data(&uvcomp2data) ; |
Rhyme | 1:6b82f17ff8e0 | 197 | fUVA = veml6075->getUVA() ; |
Rhyme | 1:6b82f17ff8e0 | 198 | fUVA_CIE = veml6075->getUVA_CIE() ; |
Rhyme | 1:6b82f17ff8e0 | 199 | fUVB = veml6075->getUVB() ; |
Rhyme | 1:6b82f17ff8e0 | 200 | fUVB_CIE = veml6075->getUVB_CIE() ; |
Rhyme | 1:6b82f17ff8e0 | 201 | uvi = veml6075->UVI() ; |
shockey | 0:11b872c2badc | 202 | |
shockey | 0:11b872c2badc | 203 | TFT.foreground(White); |
shockey | 0:11b872c2badc | 204 | TFT.locate(x+30, y) ; |
shockey | 0:11b872c2badc | 205 | TFT.printf("VEML6075\n") ; |
shockey | 0:11b872c2badc | 206 | TFT.locate(x, y+10) ; |
shockey | 0:11b872c2badc | 207 | TFT.printf("ID = 0x%04X\n", id) ; |
shockey | 0:11b872c2badc | 208 | TFT.locate(x, y+20) ; |
shockey | 0:11b872c2badc | 209 | TFT.printf("uvconf = 0x%02X\n", uvconf) ; |
shockey | 0:11b872c2badc | 210 | TFT.locate(x, y+40) ; |
shockey | 0:11b872c2badc | 211 | TFT.printf("UVLED:NCSU033X\n") ; |
shockey | 0:11b872c2badc | 212 | TFT.locate(x, y+50) ; |
shockey | 0:11b872c2badc | 213 | TFT.printf("UVA [%08.2f uW/cm2]\n", fUVA ) ; |
shockey | 0:11b872c2badc | 214 | // TFT.locate(x, y+50) ; |
shockey | 0:11b872c2badc | 215 | // TFT.printf("UVA [%.7f W/m2]\n", fUVA_CIE ) ; |
shockey | 0:11b872c2badc | 216 | TFT.locate(x, y+70) ; |
shockey | 0:11b872c2badc | 217 | TFT.printf("UVLED:UVTOP310TO39HS\n") ; |
shockey | 0:11b872c2badc | 218 | TFT.locate(x, y+80) ; |
shockey | 0:11b872c2badc | 219 | TFT.printf("UVB [%08.2f uW/cm2]\n", fUVB ) ; |
shockey | 0:11b872c2badc | 220 | // TFT.locate(x, y+80) ; |
shockey | 0:11b872c2badc | 221 | // TFT.printf("UVB [%.7f W/m2]\n", fUVB_CIE ) ; |
shockey | 0:11b872c2badc | 222 | TFT.locate(x, y+100) ; |
shockey | 0:11b872c2badc | 223 | if (uvi >= 8.0 ) |
shockey | 0:11b872c2badc | 224 | TFT.foreground(Red); |
shockey | 0:11b872c2badc | 225 | else if (uvi < 8.0 && uvi > 3.0 ) |
shockey | 0:11b872c2badc | 226 | TFT.foreground(Yellow); |
shockey | 0:11b872c2badc | 227 | else |
shockey | 0:11b872c2badc | 228 | TFT.foreground(White); |
shockey | 0:11b872c2badc | 229 | // TFT.printf("UVI [ %.1f ] for Demo\n", uvi ) ; // For demo |
shockey | 0:11b872c2badc | 230 | TFT.printf("UVI [ %.1f ] \n", uvi ) ; |
shockey | 0:11b872c2badc | 231 | // TFT.printf("comp1 [ %6d ]", uvcomp1data) ; |
shockey | 0:11b872c2badc | 232 | // TFT.printf("comp2 [ %6d ]", uvcomp2data) ; |
shockey | 0:11b872c2badc | 233 | } |
shockey | 0:11b872c2badc | 234 | |
shockey | 0:11b872c2badc | 235 | void doReportVeml(void) |
shockey | 0:11b872c2badc | 236 | { |
shockey | 0:11b872c2badc | 237 | if (prevPage != page) { |
shockey | 0:11b872c2badc | 238 | TFT.cls() ; |
shockey | 0:11b872c2badc | 239 | wait(0.5) ; |
shockey | 0:11b872c2badc | 240 | } |
shockey | 0:11b872c2badc | 241 | TFT.set_font((unsigned char*) Terminal6x8); |
shockey | 0:11b872c2badc | 242 | reportVEML6075(veml6075, 5, 10) ; |
shockey | 0:11b872c2badc | 243 | // reportVEML6040(veml6040, 5, 10) ; |
shockey | 0:11b872c2badc | 244 | } |
shockey | 0:11b872c2badc | 245 | |
Rhyme | 1:6b82f17ff8e0 | 246 | void drawUVIArrow(float value, uint16_t color) |
Rhyme | 1:6b82f17ff8e0 | 247 | { |
Rhyme | 1:6b82f17ff8e0 | 248 | int x, y ; |
Rhyme | 1:6b82f17ff8e0 | 249 | x = 116 ; |
Rhyme | 1:6b82f17ff8e0 | 250 | y = 110 - (value * 8.0) ; |
Rhyme | 1:6b82f17ff8e0 | 251 | if (y > 108) y = 108 ; |
Rhyme | 1:6b82f17ff8e0 | 252 | if (y < 17) y = 17 ; |
Rhyme | 1:6b82f17ff8e0 | 253 | TFT.line(x, y, x+7, y, color) ; |
Rhyme | 1:6b82f17ff8e0 | 254 | TFT.line(x, y, x+2, y-2, color) ; |
Rhyme | 1:6b82f17ff8e0 | 255 | TFT.line(x, y, x+2, y+2, color) ; |
Rhyme | 1:6b82f17ff8e0 | 256 | } |
Rhyme | 1:6b82f17ff8e0 | 257 | /* |
Rhyme | 1:6b82f17ff8e0 | 258 | * UV index |
Rhyme | 1:6b82f17ff8e0 | 259 | * 11~ Extreme |
Rhyme | 1:6b82f17ff8e0 | 260 | * 8~10 Very High |
Rhyme | 1:6b82f17ff8e0 | 261 | * 6~7 High |
Rhyme | 1:6b82f17ff8e0 | 262 | * 3~5 Moderate |
Rhyme | 1:6b82f17ff8e0 | 263 | * 0~2 Low |
Rhyme | 1:6b82f17ff8e0 | 264 | */ |
Rhyme | 1:6b82f17ff8e0 | 265 | void drawUVIFrame(void) |
Rhyme | 1:6b82f17ff8e0 | 266 | { |
Rhyme | 1:6b82f17ff8e0 | 267 | int x, y, i ; |
Rhyme | 1:6b82f17ff8e0 | 268 | uint16_t color ; |
Rhyme | 1:6b82f17ff8e0 | 269 | |
Rhyme | 1:6b82f17ff8e0 | 270 | TFT.set_font((unsigned char*) Terminal6x8); |
Rhyme | 1:6b82f17ff8e0 | 271 | |
Rhyme | 1:6b82f17ff8e0 | 272 | TFT.rect(0, 0, 127, 111, White) ; |
Rhyme | 1:6b82f17ff8e0 | 273 | TFT.line(32, 0, 32, 111, White) ; |
Rhyme | 1:6b82f17ff8e0 | 274 | TFT.line(96, 0, 96, 111, White) ; |
Rhyme | 1:6b82f17ff8e0 | 275 | TFT.line(0, 16, 127, 16, White) ; |
Rhyme | 1:6b82f17ff8e0 | 276 | color = Purple ; |
Rhyme | 1:6b82f17ff8e0 | 277 | TFT.fillrect(33, 17, 95, 33, color) ; /* extreme */ |
Rhyme | 1:6b82f17ff8e0 | 278 | TFT.locate(44, 21) ; TFT.background(color) ; |
Rhyme | 1:6b82f17ff8e0 | 279 | TFT.printf("Extreme") ; |
Rhyme | 1:6b82f17ff8e0 | 280 | color = Red ; |
Rhyme | 1:6b82f17ff8e0 | 281 | TFT.fillrect(33, 34, 95, 54, color) ; |
Rhyme | 1:6b82f17ff8e0 | 282 | TFT.locate(38, 40) ; TFT.background(color) ; |
Rhyme | 1:6b82f17ff8e0 | 283 | TFT.printf("Very High") ; |
Rhyme | 1:6b82f17ff8e0 | 284 | color = Orange ; |
Rhyme | 1:6b82f17ff8e0 | 285 | TFT.fillrect(33, 55, 95, 70, color) ; |
Rhyme | 1:6b82f17ff8e0 | 286 | TFT.locate(50, 59) ; TFT.background(color) ; |
Rhyme | 1:6b82f17ff8e0 | 287 | TFT.foreground(Black) ; |
Rhyme | 1:6b82f17ff8e0 | 288 | TFT.printf("High") ; |
Rhyme | 1:6b82f17ff8e0 | 289 | color = Yellow ; |
Rhyme | 1:6b82f17ff8e0 | 290 | TFT.fillrect(33, 71, 95, 95, color) ; |
Rhyme | 1:6b82f17ff8e0 | 291 | TFT.locate(40, 79) ; TFT.background(color) ; |
Rhyme | 1:6b82f17ff8e0 | 292 | TFT.printf("Moderate") ; |
Rhyme | 1:6b82f17ff8e0 | 293 | |
Rhyme | 1:6b82f17ff8e0 | 294 | color = Green ; |
Rhyme | 1:6b82f17ff8e0 | 295 | TFT.fillrect(33, 96, 95, 110, color) ; |
Rhyme | 1:6b82f17ff8e0 | 296 | TFT.locate(56, 100) ; TFT.background(color) ; |
Rhyme | 1:6b82f17ff8e0 | 297 | TFT.printf("Low") ; |
Rhyme | 1:6b82f17ff8e0 | 298 | |
Rhyme | 1:6b82f17ff8e0 | 299 | TFT.foreground(White) ; |
Rhyme | 1:6b82f17ff8e0 | 300 | TFT.background(Black) ; |
Rhyme | 1:6b82f17ff8e0 | 301 | TFT.locate(10, 6) ; |
Rhyme | 1:6b82f17ff8e0 | 302 | TFT.printf("Ee") ; |
Rhyme | 1:6b82f17ff8e0 | 303 | TFT.locate(40, 6) ; |
Rhyme | 1:6b82f17ff8e0 | 304 | TFT.printf("Strength") ; |
Rhyme | 1:6b82f17ff8e0 | 305 | TFT.locate(102, 6) ; |
Rhyme | 1:6b82f17ff8e0 | 306 | TFT.printf("UVI") ; |
Rhyme | 1:6b82f17ff8e0 | 307 | |
Rhyme | 1:6b82f17ff8e0 | 308 | i = 1 ; |
Rhyme | 1:6b82f17ff8e0 | 309 | for (y = 111 - 8 ; y > 16 ; y -= 8) { |
Rhyme | 1:6b82f17ff8e0 | 310 | TFT.line(28, y, 34, y, White) ; |
Rhyme | 1:6b82f17ff8e0 | 311 | TFT.line(94, y, 100, y, White) ; |
Rhyme | 1:6b82f17ff8e0 | 312 | TFT.locate(102, y-4) ; TFT.printf("%2d",i) ; |
Rhyme | 1:6b82f17ff8e0 | 313 | i++ ; |
Rhyme | 1:6b82f17ff8e0 | 314 | } |
Rhyme | 1:6b82f17ff8e0 | 315 | TFT.locate(8, 100) ; TFT.printf("0.0") ; |
Rhyme | 1:6b82f17ff8e0 | 316 | TFT.locate(8, 76) ; TFT.printf("0.1") ; |
Rhyme | 1:6b82f17ff8e0 | 317 | TFT.locate(8, 46) ; TFT.printf("0.2") ; |
Rhyme | 1:6b82f17ff8e0 | 318 | TFT.locate(8, 18) ; TFT.printf("0.3") ; |
Rhyme | 1:6b82f17ff8e0 | 319 | } |
Rhyme | 1:6b82f17ff8e0 | 320 | |
Rhyme | 1:6b82f17ff8e0 | 321 | void drawVemlUVI(void) |
Rhyme | 1:6b82f17ff8e0 | 322 | { |
Rhyme | 1:6b82f17ff8e0 | 323 | uint8_t uvconf = 0x00 ; |
Rhyme | 1:6b82f17ff8e0 | 324 | float uvi = 0 ; |
Rhyme | 1:6b82f17ff8e0 | 325 | static float prev_uvi = 0 ; |
Rhyme | 1:6b82f17ff8e0 | 326 | |
Rhyme | 1:6b82f17ff8e0 | 327 | veml6075->setUVConf(uvconf) ; |
Rhyme | 1:6b82f17ff8e0 | 328 | veml6075->getUVConf(&uvconf) ; |
Rhyme | 1:6b82f17ff8e0 | 329 | uvi = veml6075->UVI() ; |
Rhyme | 1:6b82f17ff8e0 | 330 | |
Rhyme | 1:6b82f17ff8e0 | 331 | TFT.set_font((unsigned char*) Terminal6x8); |
Rhyme | 1:6b82f17ff8e0 | 332 | TFT.locate(16, 117) ; |
Rhyme | 1:6b82f17ff8e0 | 333 | TFT.printf("UV Index = %2.3f", uvi) ; |
Rhyme | 1:6b82f17ff8e0 | 334 | drawUVIArrow(prev_uvi, Black) ; |
Rhyme | 1:6b82f17ff8e0 | 335 | drawUVIArrow(uvi, White) ; |
Rhyme | 1:6b82f17ff8e0 | 336 | prev_uvi = uvi ; |
Rhyme | 1:6b82f17ff8e0 | 337 | } |
Rhyme | 1:6b82f17ff8e0 | 338 | |
Rhyme | 1:6b82f17ff8e0 | 339 | void doDrawUVI(void) |
Rhyme | 1:6b82f17ff8e0 | 340 | { |
Rhyme | 1:6b82f17ff8e0 | 341 | if (prevPage != page) { |
Rhyme | 1:6b82f17ff8e0 | 342 | TFT.cls() ; |
Rhyme | 1:6b82f17ff8e0 | 343 | wait(0.5) ; |
Rhyme | 1:6b82f17ff8e0 | 344 | drawUVIFrame() ; |
Rhyme | 1:6b82f17ff8e0 | 345 | } |
Rhyme | 1:6b82f17ff8e0 | 346 | drawVemlUVI() ; |
Rhyme | 1:6b82f17ff8e0 | 347 | } |
Rhyme | 1:6b82f17ff8e0 | 348 | |
shockey | 0:11b872c2badc | 349 | double clip(double src) |
shockey | 0:11b872c2badc | 350 | { |
shockey | 0:11b872c2badc | 351 | double value ; |
shockey | 0:11b872c2badc | 352 | value = src ; |
shockey | 0:11b872c2badc | 353 | if (value < 0.0) { |
shockey | 0:11b872c2badc | 354 | value = 0.0 ; |
shockey | 0:11b872c2badc | 355 | } else if (value > 2.0) { |
shockey | 0:11b872c2badc | 356 | value = 2.0 ; |
shockey | 0:11b872c2badc | 357 | } |
shockey | 0:11b872c2badc | 358 | return( value ) ; |
shockey | 0:11b872c2badc | 359 | } |
shockey | 0:11b872c2badc | 360 | |
shockey | 0:11b872c2badc | 361 | void updatePage(void) |
shockey | 0:11b872c2badc | 362 | { |
shockey | 0:11b872c2badc | 363 | switch(page) { |
shockey | 0:11b872c2badc | 364 | case 0: // splash |
shockey | 0:11b872c2badc | 365 | if (page != prevPage) { |
shockey | 0:11b872c2badc | 366 | doSplash() ; |
shockey | 0:11b872c2badc | 367 | } |
shockey | 0:11b872c2badc | 368 | break ; |
shockey | 0:11b872c2badc | 369 | case 1: |
shockey | 0:11b872c2badc | 370 | if (page != prevPage) { |
shockey | 0:11b872c2badc | 371 | doPict(kinetis_logo) ; |
shockey | 0:11b872c2badc | 372 | } |
shockey | 0:11b872c2badc | 373 | break ; |
shockey | 0:11b872c2badc | 374 | case 2: |
shockey | 0:11b872c2badc | 375 | doReportVeml() ; |
Rhyme | 1:6b82f17ff8e0 | 376 | break ; |
Rhyme | 1:6b82f17ff8e0 | 377 | case 3: |
Rhyme | 1:6b82f17ff8e0 | 378 | doDrawUVI() ; |
shockey | 0:11b872c2badc | 379 | break ; |
shockey | 0:11b872c2badc | 380 | default: |
shockey | 0:11b872c2badc | 381 | page = 0 ; |
shockey | 0:11b872c2badc | 382 | doPict(kinetis_logo) ; |
shockey | 0:11b872c2badc | 383 | break ; |
shockey | 0:11b872c2badc | 384 | } |
shockey | 0:11b872c2badc | 385 | prevPage = page ; |
shockey | 0:11b872c2badc | 386 | } |
shockey | 0:11b872c2badc | 387 | |
shockey | 0:11b872c2badc | 388 | int main() |
shockey | 0:11b872c2badc | 389 | { |
shockey | 0:11b872c2badc | 390 | oled_cs = new DigitalOut(PIN_OLED_CS, 1) ; |
shockey | 0:11b872c2badc | 391 | oled_rs = new DigitalOut(PIN_OLED_RS, 1) ; |
shockey | 0:11b872c2badc | 392 | tty = new vt100() ; |
shockey | 0:11b872c2badc | 393 | tty->cls() ; |
shockey | 0:11b872c2badc | 394 | |
shockey | 0:11b872c2badc | 395 | init_quattro() ; |
shockey | 0:11b872c2badc | 396 | int3_r->fall(swRPressed) ; |
shockey | 0:11b872c2badc | 397 | int4_g->fall(swGPressed) ; |
shockey | 0:11b872c2badc | 398 | int5_b->fall(swBPressed) ; |
shockey | 0:11b872c2badc | 399 | |
shockey | 0:11b872c2badc | 400 | init_sensors() ; |
shockey | 0:11b872c2badc | 401 | |
shockey | 0:11b872c2badc | 402 | printf("quattro (%s)\n\r", __DATE__) ; |
shockey | 0:11b872c2badc | 403 | TFT.set_font((unsigned char*) Arial12x12); |
shockey | 0:11b872c2badc | 404 | TFT.window(0,0,128,128) ; |
shockey | 0:11b872c2badc | 405 | |
shockey | 0:11b872c2badc | 406 | doSplash() ; |
shockey | 0:11b872c2badc | 407 | page = 0 ; |
shockey | 0:11b872c2badc | 408 | prevPage = 0 ; |
shockey | 0:11b872c2badc | 409 | TFT.display(1) ; |
shockey | 0:11b872c2badc | 410 | |
shockey | 0:11b872c2badc | 411 | wait(1) ; |
shockey | 0:11b872c2badc | 412 | while(1) { |
shockey | 0:11b872c2badc | 413 | disableSW() ; |
shockey | 0:11b872c2badc | 414 | updatePage() ; |
shockey | 0:11b872c2badc | 415 | enableSW() ; |
shockey | 0:11b872c2badc | 416 | wait(0.1) ; |
shockey | 0:11b872c2badc | 417 | } |
shockey | 0:11b872c2badc | 418 | } |