fakeBeacon / display.h /
b1dd2ec 5 years ago
1 contributor
94 lines | 3.98kb
#ifndef _DISPLAY_H
#define _DISPLAY_H

#include "beacon.h"

// Display Constants
#define LINE1 0
#define LINE2 12
#define LINE3 24
#define LINE4 36
#define LINE5 48
#ifndef _M5STICKC_H_
  #define LINEBOTTOM 54
#else
  #define LINE6 60 //M5Only
  #define LINEBOTTOM 72
  //Battery see : http://community.m5stack.com/topic/1361/ischarging-and-getbatterylevel/5
  //#define VMAX 3500.0f //
  #define VMAX 3900.0f // Observed Maximum: 3943.5 after 7h charge
  #define VMIN 2973.0f // Observed Minimum: 2973.0
  #define COLUMN_BAT 80
#endif //_M5STICKC_H_  

//-----------------------------------------------------------------------------------
#ifdef _M5STICKC_H_
//uint8_t backlight_level = 15; //15 High Luminosity, 7 lowest luminosity
#define MIN_BACKLIGHT 7
#define MID_BACKLIGHT 11
#define MAX_BACKLIGHT 15
#define DEFAULT_BACKLIGHT MID_BACKLIGHT
uint8_t backlight_level = DEFAULT_BACKLIGHT; //15 High Luminosity, 7 lowest luminosity
#endif //_M5STICKC_H_
//-----------------------------------------------------------------------------------


// Display String Variables for updating all screen at once
//---------------------------------------------------------------------
char instanceStr[12] = "";
char macStr[18] = "";
int ad_running = 0;
uint32_t beacon_count = 0;

#ifdef _M5STICKC_H_
float getBatteryLevel(void)
{
  uint16_t vbatData = M5.Axp.GetVbatData();
  float vbat = vbatData * 1.1;
  //return 100.0 * ((vbat - 3000) / (4070 - 3000));
  return 100.0 * ((vbat - VMIN) / (VMAX - VMIN));
}
#endif //_M5STICKC_H_
//---------------------------------------------------------------------
void DisplayButtonStatus() {
  #ifdef _HELTEC_H_
  Heltec.display->clear();
  Heltec.display->drawString(0, LINE1, "BT: "+String(macStr));
  Heltec.display->drawString(0, LINE2, "I : "+String(instanceStr));
  Heltec.display->drawString(0, LINE4, beaconTypeStr);
  Heltec.display->drawString(0, LINEBOTTOM, "Cnt: "+String(beacon_count));
  if( 1 == ad_running ) {
    String running="X";
    Heltec.display->drawString(120, LINEBOTTOM, running);
  }
  Heltec.display->display();
  #endif //_HELTEC_H_
  #ifdef _M5STICKC_H_
  //M5.Lcd.fillScreen(BLACK);
  M5.Lcd.setTextColor(0x7bef, BLACK);
  M5.Lcd.setCursor(0, LINE1, 1);M5.Lcd.println("BT: "+String(macStr));
  M5.Lcd.setCursor(0, LINE2, 1);M5.Lcd.println("I : "+String(instanceStr));
  M5.Lcd.setCursor(0, LINE4, 1);M5.Lcd.setTextColor(GREEN, BLACK);  M5.Lcd.println(beaconTypeStr);
  M5.Lcd.setCursor(0, LINE6, 1);M5.Lcd.setTextColor(0x7bef, BLACK);  M5.Lcd.println( "Cnt: "+String(beacon_count));
  if( 1 == ad_running ) {
    M5.Lcd.setCursor(150, LINEBOTTOM, 1);M5.Lcd.setTextColor(WHITE, GREEN); M5.Lcd.println(String("X"));
  } else {
    M5.Lcd.fillRect(150, LINEBOTTOM, 160, 10, BLACK);
  }
  float BatteryValue    = M5.Axp.GetVbatData() * 1.1;// mV
  float BatteryPercent  = 100*(BatteryValue-VMIN)/ (VMAX-VMIN);
  float BatteryLevel = getBatteryLevel();
  if( BatteryPercent > 100 ) BatteryPercent = 100;
  M5.Lcd.setTextColor(0x7bef, BLACK);
  M5.Lcd.setCursor(0, LINEBOTTOM, 1);
  M5.Lcd.fillRect(0, LINEBOTTOM, 50, 10, BLACK);
  M5.Lcd.fillRect(COLUMN_BAT, LINEBOTTOM, 60, 10, BLACK);
  M5.Lcd.printf("%.1fmV",BatteryValue);
  if( BatteryPercent <= 80 ) { M5.Lcd.setCursor(COLUMN_BAT, LINEBOTTOM, 1);M5.Lcd.setTextColor(0x7bef, BLACK);M5.Lcd.printf("%.0f%%",BatteryPercent); }
  else if( BatteryPercent > 80 ) { M5.Lcd.setCursor(COLUMN_BAT, LINEBOTTOM, 1);M5.Lcd.setTextColor(0x7bef, BLACK);M5.Lcd.printf("%.1f%%",BatteryPercent); }
  else if( BatteryPercent > 90 ) { M5.Lcd.setCursor(COLUMN_BAT, LINEBOTTOM, 1);M5.Lcd.setTextColor(0x7bef, BLACK);M5.Lcd.printf("%.2f%%",BatteryPercent); }
  else if( BatteryPercent > 95 ) { M5.Lcd.setCursor(COLUMN_BAT, LINEBOTTOM, 1);M5.Lcd.setTextColor(0x7bef, BLACK);M5.Lcd.printf("%.3f%%",BatteryPercent); }
  Serial.println(BatteryValue);
  #endif //_M5STICKC_H_
}
#endif //_DISPLAY_H