Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added variable for more readable height of volume bar #286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
338 changes: 169 additions & 169 deletions Esp32_radio/bluetft.h
Original file line number Diff line number Diff line change
@@ -1,170 +1,170 @@
// bluetft.h
//
// Separated from the main sketch to allow several display types.
// Includes for various ST7735 displays. Size is 160 x 128. Select INITR_BLACKTAB
// for this and set dsp_getwidth() to 160.
// Works also for the 128 x 128 version. Select INITR_144GREENTAB for this and
// set dsp_getwidth() to 128.

#include <Adafruit_ST7735.h>

// Color definitions for the TFT screen (if used)
// TFT has bits 6 bits (0..5) for RED, 6 bits (6..11) for GREEN and 4 bits (12..15) for BLUE.
#define BLACK ST7735_BLACK
#define BLUE ST7735_BLUE
#define RED ST7735_RED
#define GREEN ST7735_GREEN
#define CYAN GREEN | BLUE
#define MAGENTA RED | BLUE
#define YELLOW RED | GREEN
#define WHITE RED | BLUE | GREEN

// Data to display. There are TFTSECS sections
#define TFTSECS 4
scrseg_struct tftdata[TFTSECS] = // Screen divided in 3 segments + 1 overlay
{ // One text line is 8 pixels
{ false, WHITE, 0, 8, "" }, // 1 top line
{ false, CYAN, 20, 64, "" }, // 8 lines in the middle
{ false, YELLOW, 90, 32, "" }, // 4 lines at the bottom
{ false, GREEN, 90, 32, "" } // 4 lines at the bottom for rotary encoder
} ;


Adafruit_ST7735* tft = NULL ; // For instance of display driver

// Various macro's to mimic the ST7735 version of display functions
#define dsp_setRotation() tft->setRotation ( 1 ) // Use landscape format (3 for upside down)
#define dsp_print(a) tft->print ( a ) // Print a string
#define dsp_println(b) tft->println ( b ) // Print a string followed by newline
#define dsp_fillRect(a,b,c,d,e) tft->fillRect ( a, b, c, d, e ) ; // Fill a rectange
#define dsp_setTextSize(a) tft->setTextSize(a) // Set the text size
#define dsp_setTextColor(a) tft->setTextColor(a) // Set the text color
#define dsp_setCursor(a,b) tft->setCursor ( a, b ) // Position the cursor
#define dsp_erase() tft->fillScreen ( BLACK ) ; // Clear the screen
#define dsp_getwidth() 160 // Adjust to your display
#define dsp_getheight() 128 // Get height of screen
#define dsp_update() // Updates to the physical screen
#define dsp_usesSPI() true // Does use SPI


bool dsp_begin()
{
tft = new Adafruit_ST7735 ( ini_block.tft_cs_pin,
ini_block.tft_dc_pin, -1 ) ; // Create an instant for TFT
// Uncomment one of the following initR lines for ST7735R displays
//tft->initR ( INITR_GREENTAB ) ; // Init TFT interface
//tft->initR ( INITR_REDTAB ) ; // Init TFT interface
tft->initR ( INITR_BLACKTAB ) ; // Init TFT interface
//tft->initR ( INITR_144GREENTAB ) ; // Init TFT interface
//tft->initR ( INITR_MINI160x80 ) ; // Init TFT interface
//tft->initR ( INITR_BLACKTAB ) ; // Init TFT interface (160x128)
// Uncomment the next line for ST7735B displays
//tft_initB() ;
return ( tft != NULL ) ;
}


//**************************************************************************************************
// D I S P L A Y B A T T E R Y *
//**************************************************************************************************
// Show the current battery charge level on the screen. *
// It will overwrite the top divider. *
// No action if bat0/bat100 not defined in the preferences. *
//**************************************************************************************************
void displaybattery()
{
if ( tft )
{
if ( ini_block.bat0 < ini_block.bat100 ) // Levels set in preferences?
{
static uint16_t oldpos = 0 ; // Previous charge level
uint16_t ypos ; // Position on screen
uint16_t v ; // Constrainted ADC value
uint16_t newpos ; // Current setting

v = constrain ( adcval, ini_block.bat0, // Prevent out of scale
ini_block.bat100 ) ;
newpos = map ( v, ini_block.bat0, // Compute length of green bar
ini_block.bat100,
0, dsp_getwidth() ) ;
if ( newpos != oldpos ) // Value changed?
{
oldpos = newpos ; // Remember for next compare
ypos = tftdata[1].y - 5 ; // Just before 1st divider
dsp_fillRect ( 0, ypos, newpos, 2, GREEN ) ; // Paint green part
dsp_fillRect ( newpos, ypos,
dsp_getwidth() - newpos,
2, RED ) ; // Paint red part
}
}
}
}


//**************************************************************************************************
// D I S P L A Y V O L U M E *
//**************************************************************************************************
// Show the current volume as an indicator on the screen. *
// The indicator is 2 pixels heigh. *
//**************************************************************************************************
void displayvolume()
{
if ( tft )
{
static uint8_t oldvol = 0 ; // Previous volume
uint8_t newvol ; // Current setting
uint16_t pos ; // Positon of volume indicator

newvol = vs1053player->getVolume() ; // Get current volume setting
if ( newvol != oldvol ) // Volume changed?
{
oldvol = newvol ; // Remember for next compare
pos = map ( newvol, 0, 100, 0, dsp_getwidth() ) ; // Compute position on TFT
dsp_fillRect ( 0, dsp_getheight() - 2,
pos, 2, RED ) ; // Paint red part
dsp_fillRect ( pos, dsp_getheight() - 2,
dsp_getwidth() - pos, 2, GREEN ) ; // Paint green part
}
}
}


//**************************************************************************************************
// D I S P L A Y T I M E *
//**************************************************************************************************
// Show the time on the LCD at a fixed position in a specified color *
// To prevent flickering, only the changed part of the timestring is displayed. *
// An empty string will force a refresh on next call. *
// A character on the screen is 8 pixels high and 6 pixels wide. *
//**************************************************************************************************
void displaytime ( const char* str, uint16_t color )
{
static char oldstr[9] = "........" ; // For compare
uint8_t i ; // Index in strings
uint16_t pos = dsp_getwidth() + TIMEPOS ; // X-position of character, TIMEPOS is negative

if ( str[0] == '\0' ) // Empty string?
{
for ( i = 0 ; i < 8 ; i++ ) // Set oldstr to dots
{
oldstr[i] = '.' ;
}
return ; // No actual display yet
}
if ( tft ) // TFT active?
{
dsp_setTextColor ( color ) ; // Set the requested color
for ( i = 0 ; i < 8 ; i++ ) // Compare old and new
{
if ( str[i] != oldstr[i] ) // Difference?
{
dsp_fillRect ( pos, 0, 6, 8, BLACK ) ; // Clear the space for new character
dsp_setCursor ( pos, 0 ) ; // Prepare to show the info
dsp_print ( str[i] ) ; // Show the character
oldstr[i] = str[i] ; // Remember for next compare
}
pos += 6 ; // Next position
}
}
}
// bluetft.h
//
// Separated from the main sketch to allow several display types.
// Includes for various ST7735 displays. Size is 160 x 128. Select INITR_BLACKTAB
// for this and set dsp_getwidth() to 160.
// Works also for the 128 x 128 version. Select INITR_144GREENTAB for this and
// set dsp_getwidth() to 128.

#include <Adafruit_ST7735.h>

// Color definitions for the TFT screen (if used)
// TFT has bits 6 bits (0..5) for RED, 6 bits (6..11) for GREEN and 4 bits (12..15) for BLUE.
#define BLACK ST7735_BLACK
#define BLUE ST7735_BLUE
#define RED ST7735_RED
#define GREEN ST7735_GREEN
#define CYAN GREEN | BLUE
#define MAGENTA RED | BLUE
#define YELLOW RED | GREEN
#define WHITE RED | BLUE | GREEN

// Data to display. There are TFTSECS sections
#define TFTSECS 4
scrseg_struct tftdata[TFTSECS] = // Screen divided in 3 segments + 1 overlay
{ // One text line is 8 pixels
{ false, WHITE, 0, 8, "" }, // 1 top line
{ false, CYAN, 20, 64, "" }, // 8 lines in the middle
{ false, YELLOW, 90, 32, "" }, // 4 lines at the bottom
{ false, GREEN, 90, 32, "" } // 4 lines at the bottom for rotary encoder
} ;


Adafruit_ST7735* tft = NULL ; // For instance of display driver

// Various macro's to mimic the ST7735 version of display functions
#define dsp_setRotation() tft->setRotation ( 1 ) // Use landscape format (3 for upside down)
#define dsp_print(a) tft->print ( a ) // Print a string
#define dsp_println(b) tft->println ( b ) // Print a string followed by newline
#define dsp_fillRect(a,b,c,d,e) tft->fillRect ( a, b, c, d, e ) ; // Fill a rectange
#define dsp_setTextSize(a) tft->setTextSize(a) // Set the text size
#define dsp_setTextColor(a) tft->setTextColor(a) // Set the text color
#define dsp_setCursor(a,b) tft->setCursor ( a, b ) // Position the cursor
#define dsp_erase() tft->fillScreen ( BLACK ) ; // Clear the screen
#define dsp_getwidth() 160 // Adjust to your display
#define dsp_getheight() 128 // Get height of screen
#define dsp_update() // Updates to the physical screen
#define dsp_usesSPI() true // Does use SPI


bool dsp_begin()
{
tft = new Adafruit_ST7735 ( ini_block.tft_cs_pin,
ini_block.tft_dc_pin, -1 ) ; // Create an instant for TFT
// Uncomment one of the following initR lines for ST7735R displays
//tft->initR ( INITR_GREENTAB ) ; // Init TFT interface
//tft->initR ( INITR_REDTAB ) ; // Init TFT interface
tft->initR ( INITR_BLACKTAB ) ; // Init TFT interface
//tft->initR ( INITR_144GREENTAB ) ; // Init TFT interface
//tft->initR ( INITR_MINI160x80 ) ; // Init TFT interface
//tft->initR ( INITR_BLACKTAB ) ; // Init TFT interface (160x128)
// Uncomment the next line for ST7735B displays
//tft_initB() ;
return ( tft != NULL ) ;
}

int VolumeBarHeight = 5;

//**************************************************************************************************
// D I S P L A Y B A T T E R Y *
//**************************************************************************************************
// Show the current battery charge level on the screen. *
// It will overwrite the top divider. *
// No action if bat0/bat100 not defined in the preferences. *
//**************************************************************************************************
void displaybattery()
{
if ( tft )
{
if ( ini_block.bat0 < ini_block.bat100 ) // Levels set in preferences?
{
static uint16_t oldpos = 0 ; // Previous charge level
uint16_t ypos ; // Position on screen
uint16_t v ; // Constrainted ADC value
uint16_t newpos ; // Current setting

v = constrain ( adcval, ini_block.bat0, // Prevent out of scale
ini_block.bat100 ) ;
newpos = map ( v, ini_block.bat0, // Compute length of green bar
ini_block.bat100,
0, dsp_getwidth() ) ;
if ( newpos != oldpos ) // Value changed?
{
oldpos = newpos ; // Remember for next compare
ypos = tftdata[1].y - 5 ; // Just before 1st divider
dsp_fillRect ( 0, ypos, newpos, 2, GREEN ) ; // Paint green part
dsp_fillRect ( newpos, ypos,
dsp_getwidth() - newpos,
2, RED ) ; // Paint red part
}
}
}
}


//**************************************************************************************************
// D I S P L A Y V O L U M E *
//**************************************************************************************************
// Show the current volume as an indicator on the screen. *
// The indicator is 2 pixels heigh. *
//**************************************************************************************************
void displayvolume()
{
if ( tft )
{
static uint8_t oldvol = 0 ; // Previous volume
uint8_t newvol ; // Current setting
uint16_t pos ; // Positon of volume indicator

newvol = vs1053player->getVolume() ; // Get current volume setting
if ( newvol != oldvol ) // Volume changed?
{
oldvol = newvol ; // Remember for next compare
pos = map ( newvol, 0, 100, 0, dsp_getwidth() ) ; // Compute position on TFT
dsp_fillRect ( 0, dsp_getheight() - VolumeBarHeight,
pos, VolumeBarHeight, RED ) ; // Paint red part
dsp_fillRect ( pos, dsp_getheight() - VolumeBarHeight,
dsp_getwidth() - pos, VolumeBarHeight, GREEN ) ; // Paint green part
}
}
}


//**************************************************************************************************
// D I S P L A Y T I M E *
//**************************************************************************************************
// Show the time on the LCD at a fixed position in a specified color *
// To prevent flickering, only the changed part of the timestring is displayed. *
// An empty string will force a refresh on next call. *
// A character on the screen is 8 pixels high and 6 pixels wide. *
//**************************************************************************************************
void displaytime ( const char* str, uint16_t color )
{
static char oldstr[9] = "........" ; // For compare
uint8_t i ; // Index in strings
uint16_t pos = dsp_getwidth() + TIMEPOS ; // X-position of character, TIMEPOS is negative

if ( str[0] == '\0' ) // Empty string?
{
for ( i = 0 ; i < 8 ; i++ ) // Set oldstr to dots
{
oldstr[i] = '.' ;
}
return ; // No actual display yet
}
if ( tft ) // TFT active?
{
dsp_setTextColor ( color ) ; // Set the requested color
for ( i = 0 ; i < 8 ; i++ ) // Compare old and new
{
if ( str[i] != oldstr[i] ) // Difference?
{
dsp_fillRect ( pos, 0, 6, 8, BLACK ) ; // Clear the space for new character
dsp_setCursor ( pos, 0 ) ; // Prepare to show the info
dsp_print ( str[i] ) ; // Show the character
oldstr[i] = str[i] ; // Remember for next compare
}
pos += 6 ; // Next position
}
}
}