You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
5.3 KiB
162 lines
5.3 KiB
7 years ago
|
#include "screen.h"
|
||
|
|
||
|
void Screen::next() { Serial.println("unhandled next"); }
|
||
|
void Screen::previous() { Serial.println("unhandled previous"); }
|
||
|
uint8_t Screen::select() { Serial.println("unhandled select"); }
|
||
|
|
||
|
SelectionList::SelectionList() {}
|
||
|
|
||
|
SelectionList::SelectionList(const char* title, uint8_t start_pos, const char* string_list) {}
|
||
|
|
||
|
void SelectionList::draw() {
|
||
|
uint8_t item_x_offset = 15;
|
||
|
uint8_t header_height = 12;
|
||
|
uint8_t item_height = 12;
|
||
|
uint8_t num_active_item = current_pos - top_item;
|
||
|
|
||
|
u8g2.clearBuffer();
|
||
|
|
||
|
/* draw Title */
|
||
|
u8g2.setFont(u8g2_font_guildenstern_nbp_tr);
|
||
|
u8g2.drawUTF8(2,header_height-2,title);
|
||
|
u8g2.drawLine(0,header_height,u8g2.getDisplayWidth(),header_height);
|
||
|
|
||
|
/* draw menu items */
|
||
|
u8g2.setFont(u8g2_font_9x18B_tr);
|
||
|
for (int i=0; i<visible; i++) {
|
||
|
u8g2.drawUTF8(item_x_offset,header_height+2+(i+1)*item_height,string_list[top_item+i].c_str());
|
||
|
}
|
||
|
|
||
|
u8g2.drawFrame(0,header_height+1+num_active_item*item_height,u8g2.getDisplayWidth(),item_height+2 );
|
||
|
u8g2.sendBuffer(); // transfer internal memory to the display
|
||
|
}
|
||
|
|
||
|
void SelectionList::next() {
|
||
|
if (current_pos < string_list.size()-1) current_pos++;
|
||
|
if (current_pos > top_item+visible-1) top_item++;
|
||
|
}
|
||
|
|
||
|
void SelectionList::previous() {
|
||
|
if (current_pos > 0 ) current_pos--;
|
||
|
if (current_pos < top_item) top_item--;
|
||
|
}
|
||
|
|
||
|
uint8_t SelectionList::select() {
|
||
|
return current_pos;
|
||
|
}
|
||
|
|
||
|
namespace {
|
||
|
|
||
|
void Drawgauge(int x, byte y, byte r, byte p, int v, int minVal, int maxVal ) {
|
||
|
int n=(r/100.00)*p; // calculate needle percent lenght
|
||
|
|
||
|
float gs_rad=-1.572; //-90 degrees in radiant
|
||
|
float ge_rad=0;
|
||
|
float i=((v-minVal)*(ge_rad-gs_rad)/(maxVal-minVal)+gs_rad);
|
||
|
int xp = x+(sin(i) * n);
|
||
|
int yp = y-(cos(i) * n);
|
||
|
u8g2.drawCircle(x,y,r, U8G2_DRAW_UPPER_LEFT );
|
||
|
u8g2.drawLine(x,y,xp,yp);
|
||
|
|
||
|
gs_rad=0;
|
||
|
ge_rad=1.572; //90 degrees in radiant
|
||
|
i=((v-minVal)*(ge_rad-gs_rad)/(maxVal-minVal)+gs_rad);
|
||
|
xp = x+(cos(i) * n);
|
||
|
yp = y-(sin(i) * n);
|
||
|
u8g2.drawCircle(x,y,r, U8G2_DRAW_UPPER_RIGHT );
|
||
|
u8g2.drawLine(x,y,xp,yp);
|
||
|
|
||
|
gs_rad=-1.572;
|
||
|
ge_rad=1.572;
|
||
|
i=((v-minVal)*(ge_rad-gs_rad)/(maxVal-minVal)+gs_rad);
|
||
|
xp = x+(sin(i) * n);
|
||
|
yp = y-(cos(i) * n);
|
||
|
u8g2.drawCircle(x,y,r, U8G2_DRAW_UPPER_LEFT|U8G2_DRAW_UPPER_RIGHT );
|
||
|
u8g2.drawLine(x,y,xp,yp);
|
||
|
|
||
|
gs_rad=-3.142;
|
||
|
ge_rad=1.572;
|
||
|
i=((v-minVal)*(ge_rad-gs_rad)/(maxVal-minVal)+gs_rad);
|
||
|
xp = x+(sin(i) * n);
|
||
|
yp = y-(cos(i) * n);
|
||
|
u8g2.drawCircle(x,y,r, U8G2_DRAW_UPPER_LEFT|U8G2_DRAW_UPPER_RIGHT|U8G2_DRAW_LOWER_LEFT );
|
||
|
u8g2.drawLine(x,y,xp,yp);
|
||
|
|
||
|
gs_rad=-1.572;
|
||
|
ge_rad=3.141;
|
||
|
i=((v-minVal)*(ge_rad-gs_rad)/(maxVal-minVal)+gs_rad);
|
||
|
xp = x+(sin(i) * n);
|
||
|
yp = y-(cos(i) * n);
|
||
|
u8g2.drawCircle(x,y,r, U8G2_DRAW_UPPER_LEFT|U8G2_DRAW_UPPER_RIGHT|U8G2_DRAW_LOWER_RIGHT );
|
||
|
u8g2.drawLine(x,y,xp,yp);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void MainScreen::draw() {
|
||
|
u8g2.clearBuffer(); // clear the internal memory
|
||
|
|
||
|
if(millis() - lastVolumeChange <= 1000) {
|
||
|
//u8g2.drawXBMP(0,0, IMG_1872_width, IMG_1872_height, IMG_1872_bits);
|
||
|
u8g2.setFont(u8g2_font_inb19_mf);
|
||
|
u8g2.drawStr(20, 20, "Volume");
|
||
|
|
||
|
u8g2.drawRBox(10, 28, 108, 22, 5);
|
||
|
u8g2.setDrawColor(0);
|
||
|
u8g2.drawBox(14+volume, 31, 100-volume, 14);
|
||
|
char volumeStr[6];
|
||
|
sprintf(volumeStr, "%d %%", volume);
|
||
|
u8g2.setFont(u8g2_font_crox3cb_mf);
|
||
|
u8g2.setFontMode(1);
|
||
|
u8g2.setDrawColor(2);
|
||
|
u8g2.drawStr(40, 45, volumeStr);
|
||
|
u8g2.setFontMode(0);
|
||
|
u8g2.setDrawColor(1);
|
||
|
} else {
|
||
|
|
||
|
u8g2.setFont(u8g2_font_inb19_mf);
|
||
|
u8g2.drawStr(0, 20, timeStr);
|
||
|
|
||
|
char weather[32];
|
||
|
u8g2.setFont(u8g2_font_profont12_mf); // choose a suitable font
|
||
|
sprintf(weather, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure());
|
||
|
u8g2.drawUTF8(0, 30, weather);
|
||
|
u8g2.setFont(u8g2_font_prospero_bold_nbp_tf); // choose a suitable font
|
||
|
|
||
|
u8g2_uint_t width = u8g2.getUTF8Width(titleStr); // calculate the pixel width of the text
|
||
|
// repeated drawing of the scrolling text...
|
||
|
u8g2.drawUTF8(titleStr_offset, 54, titleStr); // draw the scolling text
|
||
|
|
||
|
titleStr_offset-=4; // scroll by one pixel
|
||
|
if ( (u8g2_uint_t)titleStr_offset < (u8g2_uint_t)-width )
|
||
|
titleStr_offset = 0; // start over again // u8g2.getDisplayWidth()
|
||
|
}
|
||
|
u8g2.sendBuffer();
|
||
|
// bme280.printValues();
|
||
|
}
|
||
|
|
||
|
uint8_t MainScreen::select() {
|
||
|
if(millis() - lastButtonPress >= 1000) {
|
||
|
Serial.println("Button pressed");
|
||
|
lastButtonPress = millis();
|
||
|
if (mp3.playing) {
|
||
|
mp3.stop();
|
||
|
} else {
|
||
|
mp3.start();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void MainScreen::next() {
|
||
|
if (volume < 100) volume++;
|
||
|
lastVolumeChange = millis();
|
||
|
mp3.setVolume(volume);
|
||
|
Serial.printf("volume: %d\n", volume);
|
||
|
}
|
||
|
|
||
|
void MainScreen::previous() {
|
||
|
if (volume > 0) volume--;
|
||
|
lastVolumeChange = millis();
|
||
|
mp3.setVolume(volume);
|
||
|
Serial.printf("volume: %d\n", volume);
|
||
|
}
|