Hi,
I’m trying to make a Class in my own library but I can’t fix some errors even when I’ve seen the same issue on the web.
I don’t know if my class inherit from the adafruit class or not etc…
The first issue was with the functions with arguments but I think the issue is bigger since I’ve trying to understand inheritance. I use the esp8266 (nodemcu).
I’ve tried a lot of differents things but I’ve got a lot of (differents) issues.
Screen.h
#ifndef AFFICH_h
#define AFFICH_h
#include <Arduino.h>
#include <SPI.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <Button.h>
#define BCKGND_COLOR ST7735_BLACK
#define TEXT_COLOR ST7735_WHITE
#define SCREEN_POSITION_A 0
#define SCREEN_POSITION_B 2
#define SCREEN_POSITION_C 4
#define SCREEN_POSITION_D 3
#define TFT_CS 15
#define TFT_RST 4
#define TFT_DC 2
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
class Screen : public Adafruit_ST7735() {
public:
void Screen(void);
void Watch(void);
void Update(void);
void ChooseInfo(uint8_t screen_info);
void Time(uint8_t h, uint8_t min, uint8_t sec);
void Chrono(uint8_t h, uint8_t min, uint8_t sec);
void Speed(float v);
void Distance(float d);
void Spm(uint8_t s);
void Nothing(void);
void Date(void);
void Fix(bool fix);
void Battery(void);
byte MenuRacine(void);
void MenuTraining(void);
void MenuTrainingWifi(void);
void MenuSettings(void);
void Url(void);
};
#endif
Screen.cpp
#include <Arduino.h>
#include <SPI.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <Screen.h>
#include <Button.h>
void Screen::Screen(void)
{
// Use this initializer if you're using a 1.8" TFT
//tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
// Use this initializer (uncomment) if you're using a 1.44" TFT
//tft.initR(INITR_144GREENTAB); // initialize a ST7735S chip, black tab
tft.initR(INITR_REDTAB);
tft.fillScreen(ST7735_BLACK);
}
void Screen::Watch(void)
{
Date();
tft.setCursor(30,30);
tft.setTextSize(5);
Time();
Battery();
}
void Screen::Update(void)
{
tft.fillScreen(BCKGND_COLOR); //Clear the display
byte screen_info = 0;
//display the A area
tft.setTextSize(2);
tft.setCursor(0, 0);
screen_info = SCREEN_POSITION_A;
ChooseInfo(screen_info);
//display the B area
tft.setTextSize(3);
tft.setCursor(10, 20);
screen_info = SCREEN_POSITION_B;
ChooseInfo(screen_info);
//display the C area
tft.setTextSize(3);
tft.setCursor(80, 20);
screen_info = SCREEN_POSITION_C;
ChooseInfo(screen_info);
//display the D area
tft.setTextSize(2);
tft.setCursor(0, 100);
screen_info = SCREEN_POSITION_A;
ChooseInfo(screen_info);
Fix();
Battery();
}
void Screen::ChooseInfo(uint8_t screen_info)
{
switch (screen_info)
{
case 0:
Time();
break;
case 1:
Chrono();
break;
case 2:
Speed();
break;
case 3:
Distance();
break;
case 4:
Spm();
break;
default:
Nothing();
break;
}
}
void Screen::Time(uint8_t h, uint8_t min, uint8_t sec) //Func n°0 //decallage horraire GMT+x
{
tft.print(h);
tft.print(":");
tft.print(min);
tft.print(":");
tft.print(sec);
}
void Screen::Chrono(uint8_t h, uint8_t min, uint8_t sec) //Func n°1
{
tft.print(h);
tft.print(":");
tft.print(min);
tft.print(":");
tft.print(sec);
}
void Screen::Speed(float v) //Func n°2
{
tft.print(v);
}
void Screen::Distance(float d) //Func n°3, print distanceFromStart
{
tft.print(d);
}
void Screen::Spm(uint8_t s) //Func n°4
{
tft.print(s);
}
void ScreenNothing()
{
tft.setTextSize(1);
tft.print("nothing");
}
void Screen::Date()
{
tft.setCursor(30,100);
tft.setTextSize(5);
String date ="";
//date += day;
//date += month;
//date += year;
tft.print(date);
}
void Screen::Fix(bool fix)
{
int color = ST7735_WHITE;
if(fix==1 && BCKGND_COLOR != ST7735_GREEN)
color = ST7735_GREEN;
if(fix==1 && BCKGND_COLOR == ST7735_GREEN)
color = ST7735_BLUE;
if(fix==0 && BCKGND_COLOR != ST7735_RED)
color = ST7735_RED;
if(fix==0 && BCKGND_COLOR == ST7735_RED)
color = ST7735_BLACK;
//make the gps fix logo, a circle in a circle
tft.drawCircle(100,10,3,color); //x, y , radius, color
tft.fillCircle(100,10,1,color);
}
void Screen::Battery()
{/*
byte bat_lvl = Battery_Level();
int color;
if(bat_lvl > 1 && BCKGND_COLOR != ST7735_GREEN)
color = ST7735_GREEN;
if(bat_lvl > 1 && BCKGND_COLOR == ST7735_GREEN)
color = ST7735_BLUE;
if(bat_lvl < 2 && BCKGND_COLOR != ST7735_RED)
color = ST7735_RED;
if(bat_lvl < 2 && BCKGND_COLOR == ST7735_RED)
color = ST7735_BLACK;
if(bat_lvl >= 0)
{
tft.drawRect(110,3,15,6,color); //draw battery logo, empty (x,y,width,height,color)
tft.fillRect(108,4,2,4,color);
if(bat_lvl >= 1)
tft.fillRect(120,4,5,4,color);
if(bat_lvl >= 2)
tft.fillRect(115,4,5,4,color);
if(bat_lvl == 3)
tft.fillRect(110,4,5,4,color);
}*/
}
byte Screen::MenuRacine()
{
byte menu_index = 0;
tft.setTextSize(4);
MenuTraining();
byte button =0;
//while(button == 0)
//button = Button_Listen();
bool menu_choisi = 0;
while(menu_choisi == 0)
{
switch(button)
{
case BUTTON_OK:
//start the trainning B-)
menu_choisi = 1;
break;
case BUTTON_MENU:
return 0;
break;
case BUTTON_UP:
menu_index--;
break;
case BUTTON_DOWN:
menu_index++;
break;
}
if(menu_index == 4) menu_index = 1;
if(menu_index == 0) menu_index = 3;
switch(menu_index)
{
case 1:
MenuTraining();
break;
case 2:
MenuTrainingWifi();
break;
case 3:
MenuSettings();
break;
}
}
return menu_index;
}
void Screen::MenuTraining()
{
tft.fillScreen(BCKGND_COLOR);
tft.setCursor(30,40);
tft.print("Start");
tft.setCursor(20,60);
tft.print("training");
}
void Screen::MenuTrainingWifi()
{
tft.fillScreen(BCKGND_COLOR);
tft.setCursor(30,40);
tft.print("Start");
tft.setCursor(40,60);
tft.print("wi-fi");
tft.setCursor(20,80);
tft.print("training");
}
void Screen::MenuSettings()
{
tft.fillScreen(BCKGND_COLOR);
tft.setCursor(30,60);
tft.print("Settings");
}
void Url()
{
tft.fillScreen(BCKGND_COLOR);
tft.setTextSize(2);
tft.setCursor(0, 45);
tft.print("url");
}
code
#include <Screen.h>
//Screen Display = Screen();
Screen(Display);
void setup() {}
void loop() {}
and current errors
In file included from /media/guillaume/DATA/Documents/Arduino/NodeMCU/Entier_sansGPS/Entier_sansGPS.ino:2:0:
/home/guillaume/Arduino/libraries/Ecran/Screen.h:36:38: error: expected '{' before '(' token
class Screen : public Adafruit_ST7735() {
^
/home/guillaume/Arduino/libraries/Ecran/Screen.h:36:39: error: expected unqualified-id before ')' token
class Screen : public Adafruit_ST7735() {
^
Entier_sansGPS:7: error: aggregate 'Screen Display' has incomplete type and cannot be defined
Screen(Display);
exit status 1
aggregate 'Screen Display' has incomplete type and cannot be defined
Thanks
Guillaume