HEXIWEAR Battery driver and example.
Dependencies: Hexi_OLED_SSD1351
main.cpp@0:579e15da3834, 2016-10-29 (annotated)
- Committer:
- fredlak
- Date:
- Sat Oct 29 17:13:31 2016 +0000
- Revision:
- 0:579e15da3834
Hexiwear battery driver for mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fredlak | 0:579e15da3834 | 1 | #include "mbed.h" |
fredlak | 0:579e15da3834 | 2 | #include "Hexi_OLED_SSD1351.h" |
fredlak | 0:579e15da3834 | 3 | #include "string.h" |
fredlak | 0:579e15da3834 | 4 | #include "Hexi_Battery/hexi_battery.h" |
fredlak | 0:579e15da3834 | 5 | |
fredlak | 0:579e15da3834 | 6 | char text[20]; /* Text Buffer */ |
fredlak | 0:579e15da3834 | 7 | |
fredlak | 0:579e15da3834 | 8 | /* Instantiate the SSD1351 OLED Driver */ |
fredlak | 0:579e15da3834 | 9 | SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); /* (MOSI,SCLK,POWER,CS,RST,DC) */ |
fredlak | 0:579e15da3834 | 10 | |
fredlak | 0:579e15da3834 | 11 | void OLED_Init() |
fredlak | 0:579e15da3834 | 12 | { |
fredlak | 0:579e15da3834 | 13 | /* Get OLED Class Default Text Properties */ |
fredlak | 0:579e15da3834 | 14 | oled_text_properties_t textProperties = {0}; |
fredlak | 0:579e15da3834 | 15 | oled.GetTextProperties(&textProperties); |
fredlak | 0:579e15da3834 | 16 | |
fredlak | 0:579e15da3834 | 17 | /* Turn on the backlight of the OLED Display */ |
fredlak | 0:579e15da3834 | 18 | oled.DimScreenON(); |
fredlak | 0:579e15da3834 | 19 | |
fredlak | 0:579e15da3834 | 20 | /* Fills the screen with solid black */ |
fredlak | 0:579e15da3834 | 21 | oled.FillScreen(COLOR_BLACK); |
fredlak | 0:579e15da3834 | 22 | |
fredlak | 0:579e15da3834 | 23 | /* Display Text at (x=7,y=0) */ |
fredlak | 0:579e15da3834 | 24 | strcpy((char *) text,"BATT EXAMPLE"); |
fredlak | 0:579e15da3834 | 25 | oled.Label((uint8_t *)text,7,0); |
fredlak | 0:579e15da3834 | 26 | |
fredlak | 0:579e15da3834 | 27 | /* Change font color to blue */ |
fredlak | 0:579e15da3834 | 28 | textProperties.fontColor = COLOR_BLUE; |
fredlak | 0:579e15da3834 | 29 | oled.SetTextProperties(&textProperties); |
fredlak | 0:579e15da3834 | 30 | |
fredlak | 0:579e15da3834 | 31 | /* Display text at (x=5,y=40) */ |
fredlak | 0:579e15da3834 | 32 | strcpy(text,"Level:"); |
fredlak | 0:579e15da3834 | 33 | oled.Label((uint8_t *)text,5,40); |
fredlak | 0:579e15da3834 | 34 | |
fredlak | 0:579e15da3834 | 35 | /* Set text properties to white and right aligned for the dynamic text */ |
fredlak | 0:579e15da3834 | 36 | textProperties.fontColor = COLOR_WHITE; |
fredlak | 0:579e15da3834 | 37 | textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; |
fredlak | 0:579e15da3834 | 38 | oled.SetTextProperties(&textProperties); |
fredlak | 0:579e15da3834 | 39 | } |
fredlak | 0:579e15da3834 | 40 | |
fredlak | 0:579e15da3834 | 41 | int main() |
fredlak | 0:579e15da3834 | 42 | { |
fredlak | 0:579e15da3834 | 43 | |
fredlak | 0:579e15da3834 | 44 | OLED_Init(); |
fredlak | 0:579e15da3834 | 45 | |
fredlak | 0:579e15da3834 | 46 | |
fredlak | 0:579e15da3834 | 47 | HexiwearBattery battery; |
fredlak | 0:579e15da3834 | 48 | battery.sensorOn(); |
fredlak | 0:579e15da3834 | 49 | |
fredlak | 0:579e15da3834 | 50 | while (true) { |
fredlak | 0:579e15da3834 | 51 | |
fredlak | 0:579e15da3834 | 52 | if (battery.isBatteryCharging()) { |
fredlak | 0:579e15da3834 | 53 | sprintf(text, "%s", "chrg"); |
fredlak | 0:579e15da3834 | 54 | } else { |
fredlak | 0:579e15da3834 | 55 | sprintf(text, "%i%%", (uint8_t)battery.readLevelPercent()); |
fredlak | 0:579e15da3834 | 56 | } |
fredlak | 0:579e15da3834 | 57 | oled.TextBox((uint8_t *)text,55,40,35,15); //show level value of battery |
fredlak | 0:579e15da3834 | 58 | |
fredlak | 0:579e15da3834 | 59 | Thread::wait(1000); |
fredlak | 0:579e15da3834 | 60 | } |
fredlak | 0:579e15da3834 | 61 | } |
fredlak | 0:579e15da3834 | 62 | |
fredlak | 0:579e15da3834 | 63 | |
fredlak | 0:579e15da3834 | 64 |