display.cpp (1578B)
1 /* Display Utilities 2 * Handles all interactions with the external display. 3 */ 4 5 #include <Adafruit_SSD1306.h> 6 #include <Arduino.h> 7 #include <Wire.h> 8 9 #include "../include/display.h" 10 11 /* macros */ 12 13 /* enums */ 14 enum { 15 SCREEN_WIDTH = 128, 16 SCREEN_HEIGHT = 64, 17 SCREEN_ROW = SCREEN_HEIGHT / 4, 18 SCREEN_RESET = -1, 19 SCREEN_ADDRESS = 0x3D 20 }; 21 22 /* objects */ 23 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, SCREEN_RESET); 24 25 /* function declarations */ 26 27 /* function implementations */ 28 void 29 dsp_print_result(int res) 30 { 31 display.clearDisplay(); 32 dsp_write("RESULT:", 0, 0); 33 display.setCursor(0, SCREEN_ROW); 34 display.print(res); 35 display.display(); 36 } 37 38 void 39 dsp_print_main(void) 40 { 41 display.clearDisplay(); 42 dsp_write("1. Analyze", 0, 0); 43 dsp_write("2. Config", 0, SCREEN_ROW); 44 dsp_write("3. Params", 0, SCREEN_ROW * 2); 45 display.display(); 46 } 47 48 void 49 dsp_print_gotomain(void) 50 { 51 dsp_write("Continue?", 0, SCREEN_ROW * 3); 52 } 53 54 void 55 dsp_print_menu1(void) 56 { 57 display.clearDisplay(); 58 dsp_write("Wait for", 0, 0); 59 dsp_write("analysis", 0, SCREEN_ROW); 60 } 61 62 63 void 64 dsp_print_menu2(void) 65 { 66 display.clearDisplay(); 67 dsp_write("Menu 2", 0, 0); 68 } 69 70 void 71 dsp_print_menu3(void) 72 { 73 display.clearDisplay(); 74 dsp_write("Menu 3", 0, 0); 75 } 76 77 void 78 dsp_init(void) 79 { 80 if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { 81 Serial.println("Allocation failed"); 82 for(;;); 83 } 84 delay(2000); 85 display.clearDisplay(); 86 87 display.setTextColor(SSD1306_WHITE); 88 display.setTextSize(2); 89 } 90 91 void 92 dsp_write(char str[], int x, int y) 93 { 94 display.setCursor(x, y); 95 display.print(str); 96 display.display(); 97 }