Browse Source

use hardware i2s, fix various minor things

main
Hendrik Langer 7 years ago
parent
commit
03b28fc7c5
  1. 15
      src/main.cpp
  2. 106
      src/screen.cpp
  3. 26
      src/screen.h

15
src/main.cpp

@ -54,7 +54,7 @@
#include "rotary.h" #include "rotary.h"
#include "screen.h" #include "screen.h"
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16); U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 15, /* data=*/ 4);
//Create a new Basecamp instance called iot //Create a new Basecamp instance called iot
Basecamp iot; Basecamp iot;
@ -62,6 +62,7 @@ Basecamp iot;
WiFiUDP ntpUDP; WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "de.pool.ntp.org", 3600, 60000); NTPClient timeClient(ntpUDP, "de.pool.ntp.org", 3600, 60000);
char timeStr[20]; char timeStr[20];
char weatherStr[32];
BME280 bme280; BME280 bme280;
MP3 mp3; MP3 mp3;
@ -70,6 +71,7 @@ Screen* screen;
menuType menuChange = eNone; menuType menuChange = eNone;
uint32_t lastButtonPress = 0; uint32_t lastButtonPress = 0;
uint32_t lastUpdate = 0;
//Variables for the sensor and the battery //Variables for the sensor and the battery
static const int buttonPin = 0; static const int buttonPin = 0;
@ -283,17 +285,24 @@ void rotation(int i, int direction, int buttonPressed) {
void loop() void loop()
{ {
if(millis() - lastUpdate >= 1000) {
lastUpdate = millis();
timeClient.update(); timeClient.update();
timeClient.getFormattedTime().toCharArray(timeStr, 50); timeClient.getFormattedTime().toCharArray(timeStr, 50);
sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure());
}
if (menuChange != eNone) { if (menuChange != eNone) {
delete screen; delete screen;
if (menuChange == eMainScreen) screen = new MainScreen(); if (menuChange == eMainScreen) screen = new MainScreen();
if (menuChange == eMainMenu) screen = new MainMenu(); else if (menuChange == eMainMenu) screen = new MainMenu();
else if (menuChange == eStationMenu) screen = new StationMenu();
else screen = new MainScreen();
menuChange = eNone; menuChange = eNone;
} }
screen->draw(); screen->draw();
delay(200); delay(100);
} }

106
src/screen.cpp

@ -22,7 +22,7 @@ void SelectionList::draw() {
u8g2.drawLine(0,header_height,u8g2.getDisplayWidth(),header_height); u8g2.drawLine(0,header_height,u8g2.getDisplayWidth(),header_height);
/* draw menu items */ /* draw menu items */
u8g2.setFont(u8g2_font_9x18B_tr); u8g2.setFont(u8g2_font_8x13B_tr);
int length = std::min(visible, (uint8_t)string_list.size()); int length = std::min(visible, (uint8_t)string_list.size());
for (int i=0; i<length; i++) { for (int i=0; i<length; i++) {
u8g2.drawUTF8(item_x_offset,header_height+2+(i+1)*item_height,string_list[top_item+i].c_str()); u8g2.drawUTF8(item_x_offset,header_height+2+(i+1)*item_height,string_list[top_item+i].c_str());
@ -58,19 +58,10 @@ uint8_t SelectionList::select() {
MainMenu::MainMenu() { MainMenu::MainMenu() {
string_list = { string_list = {
"PLAY", "PLAY",
"80s Planet", "Radio Stations",
"Left Coast 70s",
"laradio Ska",
"French Quarter Jams",
"test", "test",
"test3", "test3",
"Radio Kol Yavne", "« Return"};
"ROCKIN626.COM",
"Jive Time Radio",
"Live Ireland",
"Ye Ol Celtic Pub",
"Gone Country - NZCMR",
"Return"};
if (mp3.playing) { if (mp3.playing) {
string_list[0] = "STOP"; string_list[0] = "STOP";
} }
@ -87,39 +78,77 @@ uint8_t MainMenu::select() {
} }
break; break;
case 1: case 1:
mp3.start("http://streaming.shoutcast.com/80sPlanet?lang=en-US"); menuChange = eStationMenu;
return current_pos;
break; break;
case 2: case 2:
mp3.start("http://ice1.somafm.com/seventies-128-mp3"); iot.mqtt.publish(topic.c_str(), 1, true, "test" );
break; break;
case 3: case 3:
mp3.start("http://streaming.radionomy.com/laradiostrong?lang=de"); iot.mqtt.publish(topic.c_str(), 1, true, "foo" );
break; break;
case 4: case 4:
menuChange = eMainScreen;
break;
default:
Serial.println("unknown entry selected");
break;
}
menuChange = eMainScreen;
return current_pos;
}
StationMenu::StationMenu() {
string_list = {
"80s Planet",
"Left Coast 70s",
"laradio Ska",
"French Quarter Jams",
"Radio Kol Yavne",
"ROCKIN626.COM",
"Jive Time Radio",
"Live Ireland",
"Ye Ol Celtic Pub",
"Gone Country - NZCMR",
"« Return"};
}
uint8_t StationMenu::select() {
switch (current_pos) {
case 0:
mp3.start("http://streaming.shoutcast.com/80sPlanet?lang=en-US");
break;
case 1:
mp3.start("http://ice1.somafm.com/seventies-128-mp3");
break;
case 2:
mp3.start("http://streaming.radionomy.com/laradiostrong?lang=de");
break;
case 3:
mp3.start("http://184.171.163.20:8162/stream"); mp3.start("http://184.171.163.20:8162/stream");
break; break;
case 5: case 4:
iot.mqtt.publish(topic.c_str(), 1, true, "test" );
case 6:
iot.mqtt.publish(topic.c_str(), 1, true, "foo" );
case 7:
mp3.start("http://212.83.129.92:8028/;?type=http&nocache=683"); mp3.start("http://212.83.129.92:8028/;?type=http&nocache=683");
break; break;
case 8: case 5:
mp3.start("http://192.99.4.210:3574/stream"); mp3.start("http://192.99.4.210:3574/stream");
break; break;
case 9: case 6:
mp3.start("http://188.165.192.5:8279/stream?icy=http"); mp3.start("http://188.165.192.5:8279/stream?icy=http");
break; break;
case 10: case 7:
mp3.start("http://69.167.190.234:8080/stream"); mp3.start("http://69.167.190.234:8080/stream");
break; break;
case 11: case 8:
mp3.start("http://192.240.102.133:11790/stream"); mp3.start("http://192.240.102.133:11790/stream");
break; break;
case 12: case 9:
mp3.start("http://192.99.41.102:5044/stream"); mp3.start("http://192.99.41.102:5044/stream");
break; break;
case 10:
menuChange = eMainMenu;
return current_pos;
break;
default: default:
Serial.println("unknown entry selected"); Serial.println("unknown entry selected");
break; break;
@ -138,14 +167,14 @@ void MainScreen::draw() {
if(millis() - lastVolumeChange <= 1000) { if(millis() - lastVolumeChange <= 1000) {
//u8g2.drawXBMP(0,0, IMG_1872_width, IMG_1872_height, IMG_1872_bits); //u8g2.drawXBMP(0,0, IMG_1872_width, IMG_1872_height, IMG_1872_bits);
u8g2.setFont(u8g2_font_inb19_mf); u8g2.setFont(u8g2_font_inb19_mf);
u8g2.drawStr(20, 20, "Volume"); u8g2.drawStr(15, 20, "Volume");
u8g2.drawRBox(10, 28, 108, 22, 5); u8g2.drawRBox(10, 28, 108, 22, 5);
u8g2.setDrawColor(0); u8g2.setDrawColor(0);
u8g2.drawBox(14+volume, 31, 100-volume, 14); u8g2.drawBox(14+volume, 31, 100-volume, 16);
char volumeStr[6]; char volumeStr[6];
sprintf(volumeStr, "%d %%", volume); sprintf(volumeStr, "%3d %%", volume);
u8g2.setFont(u8g2_font_crox3cb_mf); u8g2.setFont(u8g2_font_profont17_mf);
u8g2.setFontMode(1); u8g2.setFontMode(1);
u8g2.setDrawColor(2); u8g2.setDrawColor(2);
u8g2.drawStr(40, 45, volumeStr); u8g2.drawStr(40, 45, volumeStr);
@ -155,20 +184,27 @@ void MainScreen::draw() {
u8g2.setFont(u8g2_font_inb19_mf); u8g2.setFont(u8g2_font_inb19_mf);
u8g2.drawStr(0, 20, timeStr); u8g2.drawStr(0, 20, timeStr);
char weather[32];
u8g2.setFont(u8g2_font_profont12_mf); // choose a suitable font 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, weatherStr);
u8g2.drawUTF8(0, 30, weather);
u8g2.setFont(u8g2_font_prospero_bold_nbp_tf); // choose a suitable font 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 u8g2_uint_t width = u8g2.getUTF8Width(titleStr); // calculate the pixel width of the text
if (width > u8g2.getDisplayWidth()) {
u8g2_uint_t x = titleStr_offset;
do { // repeated drawing of the scrolling text...
u8g2.drawUTF8(x, 54, titleStr); // draw the scolling text
x += width; // add the pixel width of the scrolling text
} while( x < u8g2.getDisplayWidth() ); // draw again until the complete display is filled
// repeated drawing of the scrolling text... // repeated drawing of the scrolling text...
u8g2.drawUTF8(titleStr_offset, 54, titleStr); // draw the scolling text
titleStr_offset-=4; // scroll by one pixel titleStr_offset-=4; // scroll by one pixel
if ( (u8g2_uint_t)titleStr_offset < (u8g2_uint_t)-width ) if ( (u8g2_uint_t)titleStr_offset < (u8g2_uint_t)-width )
titleStr_offset = 0; // start over again // u8g2.getDisplayWidth() titleStr_offset = 0; // start over again
} else {
u8g2.drawUTF8((u8g2.getDisplayWidth()-width)/2, 54, titleStr);
}
} }
u8g2.sendBuffer(); u8g2.sendBuffer();
// bme280.printValues(); // bme280.printValues();

26
src/screen.h

@ -20,10 +20,11 @@
#include "BME280.h" #include "BME280.h"
#include "image.h" #include "image.h"
enum menuType { eNone=0, eMainScreen, eMainMenu }; enum menuType { eNone=0, eMainScreen, eMainMenu, eStationMenu };
extern U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2; extern U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2;
extern char timeStr[]; extern char timeStr[];
extern char weatherStr[];
extern BME280 bme280; extern BME280 bme280;
extern MP3 mp3; extern MP3 mp3;
extern menuType menuChange; extern menuType menuChange;
@ -67,13 +68,6 @@ class SelectionList : public Screen {
uint8_t visible = 4; uint8_t visible = 4;
}; };
class MainMenu : public SelectionList {
public:
MainMenu();
uint8_t select(void) override;
private:
};
class MainScreen : public Screen { class MainScreen : public Screen {
public: public:
void draw(void) override; void draw(void) override;
@ -87,4 +81,18 @@ class MainScreen : public Screen {
uint8_t volume = 20; uint8_t volume = 20;
}; };
class MainMenu : public SelectionList {
public:
MainMenu();
uint8_t select(void) override;
private:
};
class StationMenu : public SelectionList {
public:
StationMenu();
uint8_t select(void) override;
private:
};
#endif /* _SCREEN_H */ #endif /* _SCREEN_H */

Loading…
Cancel
Save