@ -12,10 +12,12 @@ class DisplayMono128X64 : public DisplayMono {
mExtra = 0 ;
}
void config ( bool enPowerSave , uint8_t screenSaver , uint8_t lum ) {
void config ( bool enPowerSave , uint8_t screenSaver , uint8_t lum , uint8_t graph_ratio , uint8_t graph_size ) {
mEnPowerSave = enPowerSave ;
mScreenSaver = screenSaver ;
mLuminance = lum ;
mGraphRatio = graph_ratio ;
mGraphSize = graph_size ;
}
void init ( uint8_t type , uint8_t rotation , uint8_t cs , uint8_t dc , uint8_t reset , uint8_t clock , uint8_t data , DisplayData * displayData ) {
@ -34,6 +36,34 @@ class DisplayMono128X64 : public DisplayMono {
}
calcLinePositions ( ) ;
switch ( mGraphSize ) { // var opts2 = [[0, "Line 1 - 2"], [1, "Line 2 - 3"], [2, "Line 1 - 3"], [3, "Line 2 - 4"], [4, "Line 1 - 4"]];
case 0 :
graph_first_line = 1 ;
graph_last_line = 2 ;
break ;
case 1 :
graph_first_line = 2 ;
graph_last_line = 3 ;
break ;
case 2 :
graph_first_line = 1 ;
graph_last_line = 3 ;
break ;
case 3 :
graph_first_line = 2 ;
graph_last_line = 4 ;
break ;
case 4 :
default :
graph_first_line = 1 ;
graph_last_line = 4 ;
break ;
}
widthShrink = ( mScreenSaver = = 1 ) ? pixelShiftRange : 0 ; // shrink graphwidth for pixelshift screensaver
initPowerGraph ( mDispWidth - 22 - widthShrink , mLineYOffsets [ graph_last_line ] - mLineYOffsets [ graph_first_line - 1 ] - 2 ) ;
printText ( " Ahoy! " , l_Ahoy , 0xff ) ;
printText ( " ahoydtu.de " , l_Website , 0xff ) ;
printText ( mDisplayData - > version , l_Version , 0xff ) ;
@ -61,23 +91,17 @@ class DisplayMono128X64 : public DisplayMono {
// calculate current pixelshift for pixelshift screensaver
calcPixelShift ( pixelShiftRange ) ;
// print total power
// add new power data to power graph
if ( mDisplayData - > nrProducing > 0 ) {
if ( mDisplayData - > totalPower > 9999.0 )
snprintf ( mFmtText , DISP_FMT_TEXT_LEN , " %.2f kW " , ( mDisplayData - > totalPower / 1000.0 ) ) ;
else
snprintf ( mFmtText , DISP_FMT_TEXT_LEN , " %.0f W " , mDisplayData - > totalPower ) ;
printText ( mFmtText , l_TotalPower , 0xff ) ;
} else {
printText ( " offline " , l_TotalPower , 0xff ) ;
addPowerGraphEntry ( mDisplayData - > totalPower ) ;
}
// print Date and time
if ( 0 ! = mDisplayData - > utcTs )
printText ( ah : : getDateTimeStrShort ( gTimezone . toLocal ( mDisplayData - > utcTs ) ) . c_str ( ) , l_Time , 0xff ) ;
// dynamic status bar, alternatively:
if ( showLine ( l_Status ) ) {
// alternatively:
// print ip address
if ( ! ( mExtra % 5 ) & & ( mDisplayData - > ipAddress ) ) {
snprintf ( mFmtText , DISP_FMT_TEXT_LEN , " %s " , ( mDisplayData - > ipAddress ) . toString ( ) . c_str ( ) ) ;
@ -114,8 +138,24 @@ class DisplayMono128X64 : public DisplayMono {
if ( moon_pos ! = - 1 )
mDisplay - > drawStr ( pos + moon_pos + mPixelshift , mLineYOffsets [ l_Status ] , " H " ) ; // moon symbol
}
}
if ( showLine ( l_TotalPower ) ) {
// print total power
if ( mDisplayData - > nrProducing > 0 ) {
if ( mDisplayData - > totalPower > 9999.0 )
snprintf ( mFmtText , DISP_FMT_TEXT_LEN , " %.2f kW " , ( mDisplayData - > totalPower / 1000.0 ) ) ;
else
snprintf ( mFmtText , DISP_FMT_TEXT_LEN , " %.0f W " , mDisplayData - > totalPower ) ;
printText ( mFmtText , l_TotalPower , 0xff ) ;
} else {
printText ( " offline " , l_TotalPower , 0xff ) ;
}
}
// print yields
if ( showLine ( l_YieldDay ) ) {
// print day yield
mDisplay - > setFont ( u8g2_font_ncenB10_symbols10_ahoy ) ;
mDisplay - > drawStr ( 16 + mPixelshift , mLineYOffsets [ l_YieldDay ] , " I " ) ; // day symbol
mDisplay - > drawStr ( 16 + mPixelshift , mLineYOffsets [ l_YieldTotal ] , " D " ) ; // total symbol
@ -125,42 +165,44 @@ class DisplayMono128X64 : public DisplayMono {
else
snprintf ( mFmtText , DISP_FMT_TEXT_LEN , " %.0f Wh " , mDisplayData - > totalYieldDay ) ;
printText ( mFmtText , l_YieldDay , 0xff ) ;
}
if ( showLine ( l_YieldTotal ) ) {
// print total yield
if ( mDisplayData - > totalYieldTotal > 9999.0 )
snprintf ( mFmtText , DISP_FMT_TEXT_LEN , " %.2f MWh " , mDisplayData - > totalYieldTotal / 1000.0 ) ;
else
snprintf ( mFmtText , DISP_FMT_TEXT_LEN , " %.0f kWh " , mDisplayData - > totalYieldTotal ) ;
printText ( mFmtText , l_YieldTotal , 0xff ) ;
}
if ( mDispSwitchState = = d_POWER_GRAPH ) {
// plot power graph
plotPowerGraph ( ( mDispWidth - mPgWidth ) / 2 + mPixelshift , mLineYOffsets [ graph_last_line ] - 1 ) ;
}
// draw dynamic RSSI bars
int xoffs ;
if ( mScreenSaver = = 1 ) // shrink screenwidth for pixelshift screensaver
xoffs = pixelShiftRange / 2 ;
else
xoffs = 0 ;
int rssi_bar_height = 9 ;
for ( int i = 0 ; i < 4 ; i + + ) {
int radio_rssi_threshold = - 60 - i * 10 ;
int wifi_rssi_threshold = - 60 - i * 10 ;
uint8_t barwidth = std : : min ( 4 - i , 3 ) ;
if ( mDisplayData - > RadioRSSI > radio_rssi_threshold )
mDisplay - > drawBox ( xoffs + mPixelshift , 8 + ( rssi_bar_height + 1 ) * i , 4 - i , rssi_bar_height ) ;
mDisplay - > drawBox ( widthShrink / 2 + mPixelshift , 8 + ( rssi_bar_height + 1 ) * i , barwidth , rssi_bar_height ) ;
if ( mDisplayData - > WifiRSSI > wifi_rssi_threshold )
mDisplay - > drawBox ( mDispWidth - 4 - xoffs + mPixelshift + i , 8 + ( rssi_bar_height + 1 ) * i , 4 - i , rssi_bar_height ) ;
mDisplay - > drawBox ( mDispWidth - barwidth - widthShrink / 2 + mPixelshift , 8 + ( rssi_bar_height + 1 ) * i , barwidth , rssi_bar_height ) ;
}
// draw dynamic antenna and WiFi symbols
mDisplay - > setFont ( u8g2_font_ncenB10_symbols10_ahoy ) ;
char sym [ ] = " " ;
sym [ 0 ] = mDisplayData - > RadioSymbol ? ' A ' : ' E ' ; // NRF
mDisplay - > drawStr ( xoffs + mPixelshift , mLineYOffsets [ l_RSSI ] , sym ) ;
mDisplay - > drawStr ( widthShrink / 2 + mPixelshift , mLineYOffsets [ l_RSSI ] , sym ) ;
if ( mDisplayData - > MQTTSymbol )
sym [ 0 ] = ' J ' ; // MQTT
else
sym [ 0 ] = mDisplayData - > WifiSymbol ? ' B ' : ' F ' ; // Wifi
mDisplay - > drawStr ( mDispWidth - mDisplay - > getStrWidth ( sym ) - xoffs + mPixelshift , mLineYOffsets [ l_RSSI ] , sym ) ;
mDisplay - > sendBuffer ( ) ;
mDisplay - > drawStr ( mDispWidth - mDisplay - > getStrWidth ( sym ) - widthShrink / 2 + mPixelshift , mLineYOffsets [ l_RSSI ] , sym ) ;
mDisplay - > sendBuffer ( ) ;
mExtra + + ;
@ -184,7 +226,11 @@ class DisplayMono128X64 : public DisplayMono {
l_MAX_LINES = 5 ,
} ;
uint8_t graph_first_line ;
uint8_t graph_last_line ;
const uint8_t pixelShiftRange = 11 ; // number of pixels to shift from left to right (centered -> must be odd!)
uint8_t widthShrink ;
void calcLinePositions ( ) {
uint8_t yOff = 0 ;
@ -199,7 +245,7 @@ class DisplayMono128X64 : public DisplayMono {
dsc = mDisplay - > getDescent ( ) ;
yOff - = dsc ;
if ( l_Time = = i ) // prevent time and status line to touch
yOff + = 1 ; // -> one pixels space
yOff + + ; // -> one pixels space
i + + ;
} while ( l_MAX_LINES > i ) ;
}
@ -226,4 +272,8 @@ class DisplayMono128X64 : public DisplayMono {
dispX + = mPixelshift ;
mDisplay - > drawStr ( dispX , mLineYOffsets [ line ] , text ) ;
}
bool showLine ( uint8_t line ) {
return ( ( mDispSwitchState = = d_POWER_TEXT ) | | ( ( line < graph_first_line ) | | ( line > graph_last_line ) ) ) ;
}
} ;