Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Adafruit_GFX BioroboticsMotorControl MODSERIAL BioroboticsEMGFilter
Screen.h
00001 #pragma once 00002 00003 #include "mbed.h" 00004 #include <string> 00005 00006 // Uncomment this in the adafruit config.h to turn off the builtin splash 00007 //#define NO_SPLASH_ADAFRUIT 00008 // Uncomment this in the adafruit config.h to enable all functionality 00009 //#define GFX_WANT_ABSTRACTS 00010 00011 #include "Adafruit_SSD1306.h" 00012 00013 00014 class Screen 00015 { 00016 private: 00017 I2C i2c; // Communicates to the OLED screen 00018 Adafruit_SSD1306_I2c oled; 00019 public: 00020 // The screen we use doesn't have a reset pin, but it needs one anyway. 00021 // Use a pin we don't use. 00022 Screen(PinName sda, PinName scl, PinName reset): 00023 i2c(sda, scl), 00024 oled(i2c, reset) { 00025 00026 // According to the spec the max bitrate for the SSD1308 is 400 kbit/s 00027 i2c.frequency(400000); 00028 00029 clear_display(); 00030 } 00031 00032 void clear_display() { 00033 oled.clearDisplay(); 00034 oled.setTextCursor(0, 0); 00035 display(); 00036 } 00037 00038 void display() { 00039 // Apparently the display only updates every 2 "display" calls. 00040 // This is a bug in the library. 00041 oled.display(); 00042 oled.display(); 00043 } 00044 00045 // State names can be a maximum of 17 characters long. 00046 void display_state_name(string name) { 00047 // Clear a previous title. 00048 oled.setTextCursor(0, 0); 00049 oled.printf(" "); 00050 oled.setTextCursor(0, 0); 00051 oled.printf("- "); 00052 oled.printf(name.c_str()); 00053 oled.printf(" -\r\n"); 00054 display(); 00055 } 00056 00057 void display_emg_state(bool left_tensed, bool right_tensed) { 00058 oled.setTextCursor(0, 8); 00059 if (left_tensed) { 00060 oled.printf("Left "); 00061 } else { 00062 oled.printf(" "); 00063 } 00064 if (right_tensed) { 00065 oled.printf("Right"); 00066 } else { 00067 oled.printf(" "); 00068 } 00069 } 00070 00071 // Returns a direct handle to the screen. 00072 // Be carefull while using the handle. 00073 Adafruit_SSD1306_I2c* get_screen_handle() { 00074 return &oled; 00075 } 00076 00077 void display_up_down_arrow(bool is_up) { 00078 int size_x = 20; 00079 int size_y = 10; 00080 int x_start = oled.width() - size_x; 00081 int x_end = x_start + size_x; 00082 int y_start = oled.height() - size_y; 00083 int y_end = y_start + size_y; 00084 00085 oled.fillRect(x_start, y_start, size_x, size_y, BLACK); 00086 00087 if (is_up) { 00088 oled.fillTriangle(x_start, y_end, x_end, y_end, x_start + size_x/2, y_start, WHITE); 00089 } else { 00090 oled.fillTriangle(x_start + size_x/2, y_end, x_start, y_start, x_end, y_start, WHITE); 00091 } 00092 00093 display(); 00094 } 00095 00096 void display_left_right_arrow(bool is_right) { 00097 int size_x = 20; 00098 int size_y = 10; 00099 int x_start = oled.width() - size_x * 2; 00100 int x_end = x_start + size_x; 00101 int y_start = oled.height() - size_y; 00102 int y_end = y_start + size_y; 00103 00104 oled.fillRect(x_start, y_start, size_x, size_y, BLACK); // Deletes triangle in order to make a new one 00105 00106 if (is_right) { 00107 oled.fillTriangle(x_start, y_end, x_end, y_start + size_y/2, x_start, y_start, WHITE); 00108 } else { 00109 oled.fillTriangle(x_end, y_start, x_start, y_start + size_y/2, x_end, y_end, WHITE); 00110 } 00111 00112 display(); 00113 } 00114 00115 };
Generated on Thu Jul 14 2022 19:50:50 by
1.7.2