mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-05-19 11:01:46 +02:00
146 lines
3.9 KiB
C++
146 lines
3.9 KiB
C++
#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);
|
|
|
|
sendDisplayCMD(setChargePump);
|
|
sendDisplayCMD(0x14);
|
|
sendDisplayCMD(activateDisplay);
|
|
this->clear();
|
|
return;
|
|
};
|
|
void Display::clear(void){
|
|
sendDisplayCMD(addressingMode);
|
|
sendDisplayCMD(0x00); //horizontal
|
|
sendDisplayCMD(colRange);
|
|
sendDisplayCMD(0x00);
|
|
sendDisplayCMD(0x7f);
|
|
sendDisplayCMD(pageRange);
|
|
sendDisplayCMD(0x00);
|
|
sendDisplayCMD(0x07);
|
|
for (int j=0;j<64;j++){
|
|
Wire.beginTransmission(DisplayAdress);
|
|
Wire.write(data_byte);
|
|
for(int i = 0;i<16;i++){
|
|
Wire.write(0x00);
|
|
}
|
|
Wire.endTransmission();
|
|
}
|
|
this -> charsOnCurrLine = 0;
|
|
this -> currLine = 0;
|
|
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)
|
|
{
|
|
this->currLine = (this->currLine+((charAmount+this->charsOnCurrLine)/16))%8;
|
|
this->charsOnCurrLine = (charAmount+this->charsOnCurrLine)%17; //there can be 0-16 chars on one line, so the 17th char is on next line
|
|
}
|
|
else
|
|
{
|
|
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
|
|
if(*value=='\n')
|
|
{
|
|
//value++;
|
|
//if(*nextchar=='n')
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
updateLine(1);
|
|
Wire.beginTransmission(DisplayAdress);
|
|
for(int i = 0;i<9;i++){
|
|
Wire.write(font8x8_colwise[*value][i]);
|
|
}
|
|
Wire.endTransmission();
|
|
}
|
|
value++;
|
|
}
|
|
return;
|
|
|
|
};
|
|
void Display::println(char *value){
|
|
|
|
};
|
|
void Display::print(int value){
|
|
|
|
}; |