![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
V.062 11/3
Dependencies: FT6206 SDFileSystem ILI9341_t3
Fork of ATT_AWS_IoT_demo_v06 by
TextField.cpp@32:62a026c88e22, 2017-11-16 (annotated)
- Committer:
- eggsylah
- Date:
- Thu Nov 16 21:49:45 2017 +0000
- Revision:
- 32:62a026c88e22
- Parent:
- 30:8c979815f533
V08 used in demo unigs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eggsylah | 30:8c979815f533 | 1 | #include "TextField.h" |
eggsylah | 30:8c979815f533 | 2 | |
eggsylah | 30:8c979815f533 | 3 | |
eggsylah | 30:8c979815f533 | 4 | TextField::TextField() { |
eggsylah | 30:8c979815f533 | 5 | } |
eggsylah | 30:8c979815f533 | 6 | |
eggsylah | 30:8c979815f533 | 7 | void TextField::setDisplay(ILI9341_t3 *pNewTft) |
eggsylah | 30:8c979815f533 | 8 | { |
eggsylah | 30:8c979815f533 | 9 | pTft = pNewTft; |
eggsylah | 30:8c979815f533 | 10 | } |
eggsylah | 30:8c979815f533 | 11 | |
eggsylah | 30:8c979815f533 | 12 | void TextField::setupField(ILI9341_t3 *pNewTft, const char* buf) |
eggsylah | 30:8c979815f533 | 13 | { |
eggsylah | 30:8c979815f533 | 14 | pTft = pNewTft; |
eggsylah | 30:8c979815f533 | 15 | pTft->getCursor(&x, &y); |
eggsylah | 30:8c979815f533 | 16 | w = pTft->strPixelLen(buf); |
eggsylah | 30:8c979815f533 | 17 | pTft->printf("\n"); |
eggsylah | 30:8c979815f533 | 18 | h = pTft->getCursorY() - y; |
eggsylah | 30:8c979815f533 | 19 | pTft->setCursor(x+w, y); |
eggsylah | 30:8c979815f533 | 20 | } |
eggsylah | 30:8c979815f533 | 21 | |
eggsylah | 30:8c979815f533 | 22 | void TextField::setFieldInt(ILI9341_t3 *pNewTft, const char* fmt, int32_t data) |
eggsylah | 30:8c979815f533 | 23 | { |
eggsylah | 30:8c979815f533 | 24 | char buf[64]; |
eggsylah | 30:8c979815f533 | 25 | sprintf(buf, fmt, data); |
eggsylah | 30:8c979815f533 | 26 | this->fmt = fmt; |
eggsylah | 30:8c979815f533 | 27 | setupField(pNewTft, &buf[0]); |
eggsylah | 30:8c979815f533 | 28 | } |
eggsylah | 30:8c979815f533 | 29 | |
eggsylah | 30:8c979815f533 | 30 | void TextField::setFieldStr(ILI9341_t3 *pNewTft, const char* fmt, const char* data) |
eggsylah | 30:8c979815f533 | 31 | { |
eggsylah | 30:8c979815f533 | 32 | char buf[64]; |
eggsylah | 30:8c979815f533 | 33 | sprintf(buf, fmt, data); |
eggsylah | 30:8c979815f533 | 34 | this->fmt = fmt; |
eggsylah | 30:8c979815f533 | 35 | setupField(pNewTft, &buf[0]); |
eggsylah | 30:8c979815f533 | 36 | }; |
eggsylah | 30:8c979815f533 | 37 | |
eggsylah | 30:8c979815f533 | 38 | |
eggsylah | 30:8c979815f533 | 39 | void TextField::setFieldFloat(ILI9341_t3 *pNewTft, const char* fmt, float data) |
eggsylah | 30:8c979815f533 | 40 | { |
eggsylah | 30:8c979815f533 | 41 | char buf[64]; |
eggsylah | 30:8c979815f533 | 42 | sprintf(buf, fmt, data); |
eggsylah | 30:8c979815f533 | 43 | this->fmt = fmt; |
eggsylah | 30:8c979815f533 | 44 | setupField(pNewTft, buf); |
eggsylah | 30:8c979815f533 | 45 | } |
eggsylah | 30:8c979815f533 | 46 | |
eggsylah | 30:8c979815f533 | 47 | |
eggsylah | 30:8c979815f533 | 48 | void TextField::setFieldLine(ILI9341_t3 *pNewTft, const char* fmt) |
eggsylah | 30:8c979815f533 | 49 | { |
eggsylah | 30:8c979815f533 | 50 | char buf[] = { '\x00' }; |
eggsylah | 30:8c979815f533 | 51 | this->fmt = fmt; |
eggsylah | 30:8c979815f533 | 52 | setupField(pNewTft, buf); |
eggsylah | 30:8c979815f533 | 53 | w = pTft->width() - pTft->getCursorX(); |
eggsylah | 30:8c979815f533 | 54 | } |
eggsylah | 30:8c979815f533 | 55 | |
eggsylah | 30:8c979815f533 | 56 | |
eggsylah | 30:8c979815f533 | 57 | /* erase the text area of the field */ |
eggsylah | 30:8c979815f533 | 58 | void TextField::eraseField(bool erase) |
eggsylah | 30:8c979815f533 | 59 | { |
eggsylah | 30:8c979815f533 | 60 | if (erase) |
eggsylah | 30:8c979815f533 | 61 | pTft->fillRect(x, y, w, h, ILI9341_BLACK); |
eggsylah | 30:8c979815f533 | 62 | pTft->setCursor(x, y); |
eggsylah | 30:8c979815f533 | 63 | |
eggsylah | 30:8c979815f533 | 64 | } |
eggsylah | 30:8c979815f533 | 65 | |
eggsylah | 30:8c979815f533 | 66 | void TextField::drawFieldInt(int32_t data) |
eggsylah | 30:8c979815f533 | 67 | { |
eggsylah | 30:8c979815f533 | 68 | eraseField(); |
eggsylah | 30:8c979815f533 | 69 | pTft->printf(fmt, data); |
eggsylah | 30:8c979815f533 | 70 | } |
eggsylah | 30:8c979815f533 | 71 | |
eggsylah | 30:8c979815f533 | 72 | void TextField::drawFieldStr(const char* data, bool erase) |
eggsylah | 30:8c979815f533 | 73 | { |
eggsylah | 30:8c979815f533 | 74 | eraseField(erase); |
eggsylah | 30:8c979815f533 | 75 | pTft->printf(fmt, data); |
eggsylah | 30:8c979815f533 | 76 | } |
eggsylah | 30:8c979815f533 | 77 | |
eggsylah | 30:8c979815f533 | 78 | |
eggsylah | 30:8c979815f533 | 79 | void TextField::drawFieldFloat(float data) |
eggsylah | 30:8c979815f533 | 80 | { |
eggsylah | 30:8c979815f533 | 81 | eraseField(); |
eggsylah | 30:8c979815f533 | 82 | pTft->printf(fmt, data); |
eggsylah | 30:8c979815f533 | 83 | } |