fixed indentation after linebreak, made some refactoring

This commit is contained in:
hhaupt 2024-06-05 13:13:26 +02:00
parent 4ffed430e2
commit e30395e8a6
4 changed files with 88 additions and 71 deletions

View File

@ -10,15 +10,20 @@
*/
#define SDA_PIN 1
#define SCL_PIN 2
#include "Dezibot.h"
#include <Wire.h>
Dezibot::Dezibot():multiColorLight(){};
void Dezibot::begin(void) {
//infraredLight.begin();
//lightDetection.begin();
//motion.begin();
//multiColorLight.begin();
Wire.begin(SDA_PIN,SCL_PIN);
infraredLight.begin();
lightDetection.begin();
motion.begin();
multiColorLight.begin();
display.begin();
};

View File

@ -1,3 +1,22 @@
/**
* @file CharTable.h
* @author Hans Haupt (hans.haupt@dezibot.de)
* @brief LookUpTable for 8x8 Pixel Characters for an SSD1306 Display
* @version 0.1
* @date 2024-05-24
*
* @copyright Copyright (c) 2024
*
*/
/**
* @brief First index specifies the index, where index equals the ascii encoding
* unprintable characters are encode as all zero
* the first byte in an entry is the cmd_byte for SSD1306 and therefore not printed
* Encoding is colum wise, so first byte is the first column of the char and so on
*
*/
const char font8x8_colwise[128][9] = {{ 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // U+0()
{ 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // U+1()
{ 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // U+2()
@ -125,4 +144,4 @@ const char font8x8_colwise[128][9] = {{ 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
{ 0x40,0x00,0x00,0x00,0x77,0x77,0x00,0x00,0x00}, // U+7c(|)
{ 0x40,0x41,0x41,0x77,0x3e,0x08,0x08,0x00,0x00}, // U+7d(})
{ 0x40,0x02,0x03,0x01,0x03,0x02,0x03,0x01,0x00}, // U+7e(~)
{ 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; // U+7f(°)
{ 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; // U+7f(°)

View File

@ -1,48 +1,29 @@
/**
* @file Display.cpp
* @author Hans Haupt (hans.haupt@dezibot.de)
* @brief Adds the ability to print to the display of the robot.
* @version 0.1
* @date 2024-06-05
*
* @copyright Copyright (c) 2024
*/
#include "Display.h"
#include "CharTable.h"
#include "Wire.h"
void Display::sendDisplayCMD(uint8_t cmd){
Wire.beginTransmission(DisplayAdress);
Wire.write(cmd_byte);
Wire.write(cmd);
Wire.endTransmission();
};
void Display::begin(void){
//TODO: change pin to #defines, first check if Wire.begin was already called
Wire.begin(1,2);
//set Mux Ratio
sendDisplayCMD(muxRatio);
sendDisplayCMD(0x3f);
sendDisplayCMD(setOffset);
sendDisplayCMD(0x00);
sendDisplayCMD(setStartLine);
/*x-flip*/
//sendDisplayCMD(setSegmentMap);
//sendDisplayCMD(setSegmentReMap);
/*mapping of the rows*/
//sendDisplayCMD(setComHardwareConfig);
//sendDisplayCMD(0x10);
/*y-flip*/
//sendDisplayCMD( setComDirectionNormal);
//sendDisplayCMD(setComDirectionFlipped);
//sendDisplayCMD(setContrast);
//sendDisplayCMD(0x7f);
sendDisplayCMD(stopCompleteOn);
/*which pixels are bright: normal = 1s are bright, inverese= 0s are bright*/
sendDisplayCMD( setNormalMode);
//sendDisplayCMD( setInverseMode);
sendDisplayCMD( setOscFreq);
sendDisplayCMD(0x80);
@ -52,6 +33,14 @@ void Display::begin(void){
this->clear();
return;
};
void Display::sendDisplayCMD(uint8_t cmd){
Wire.beginTransmission(DisplayAdress);
Wire.write(cmd_byte);
Wire.write(cmd);
Wire.endTransmission();
};
void Display::clear(void){
sendDisplayCMD(addressingMode);
sendDisplayCMD(0x00); //horizontal
@ -74,11 +63,6 @@ void Display::clear(void){
return;
};
/**
* @brief updates amount of chars on current rows and also the current row
*
* @param charAmount how many chars were added
*/
void Display::updateLine(uint charAmount)
{
if(charAmount+this->charsOnCurrLine>16)
@ -90,44 +74,35 @@ void Display::updateLine(uint charAmount)
{
this->charsOnCurrLine = charAmount+this->charsOnCurrLine;
}
}
};
void Display::print(char *value){
char *nextchar;
/* write data to the buffer */
while(value && *value != '\0') //check if pointer is still valid and string is not terminated
{
//check if input is a predefined cmd
//check if next character is a linebreak
if(*value=='\n')
{
//value++;
//if(*nextchar=='n')
//fill the current line with blanks
while(this->charsOnCurrLine<16)
{
if(this->charsOnCurrLine==16)
{
this->currLine=currLine+1;
this->charsOnCurrLine=0;
}
while(this->charsOnCurrLine<17)
{
Wire.beginTransmission(DisplayAdress);
for(int i = 0;i<9;i++){
Wire.write(font8x8_colwise[0][i]);
}
Wire.endTransmission();
updateLine(1);
if(charsOnCurrLine==16)
{
break;
}
updateLine(1);
Wire.beginTransmission(DisplayAdress);
for(int i = 0;i<9;i++){
Wire.write(font8x8_colwise[0][i]);
}
Wire.endTransmission();
}
//make the linebreak
this->currLine=currLine+1;
this->charsOnCurrLine=0;
}
else
{
updateLine(1);
Wire.beginTransmission(DisplayAdress);
//print the character
for(int i = 0;i<9;i++){
Wire.write(font8x8_colwise[*value][i]);
}
@ -135,8 +110,11 @@ void Display::print(char *value){
}
value++;
}
return;
};
void Display::println(char *value){
this ->print(value);
this->print("\n");
};
void Display::flipOrientation(void){
@ -148,11 +126,13 @@ void Display::flipOrientation(void){
sendDisplayCMD(setSegmentReMap);
}
this->orientationFlipped = !this->orientationFlipped;
}
void Display::println(char *value){
this ->print(value);
this->print("\n");
};
void Display::print(int value){
};
void Display::invertColor(void){
if(this->colorInverted){
sendDisplayCMD(setNormalMode);
} else {
sendDisplayCMD(setInverseMode);
}
this->colorInverted = !this->colorInverted;
};

View File

@ -19,10 +19,16 @@ class Display{
protected:
//how many chars are on current line
uint8_t charsOnCurrLine = 0;
//on which line are we currently printing
uint8_t currLine = 0;
//flag that marks if the y-orientation is currently flipped
bool orientationFlipped = false;
//flag thats marks if the color is currently inverted
bool colorInverted = false;
/**
* @brief sends the passed cmd to the display, cmd_byte is added as prefix by the function
*
@ -65,11 +71,18 @@ class Display{
* @param value the string that should be printed
*/
void println(char *value);
void print(int value);
/**
* @brief flips the horizontal orientation of all content on the display
*/
void flipOrientation(void);
/**
* @brief inverts the pixelcolors, so pixels on will be set to off and currently off pixels will be turned off.
* affects already printed content as well as future prints.
*
*/
void invertColor(void);
};