This commit is contained in:
2024-02-12 16:26:17 -03:00
parent 61a9b3e262
commit 4139759b96
3 changed files with 93 additions and 74 deletions

View File

@@ -24,9 +24,9 @@ int32_t SSL_Display::init() {
RobotStatus status0;
for(uint32_t i = 0; i<12; i++){
status0.batteryLevel = ((float)i)/12;
status0.connected = true;
status0.connected = i%2;
status0.robotId = i;
status0.status = 0;
status0.status = i%2;
status0.team = i%2;
robots[i].setRobotStatus(status0);
}

View File

@@ -31,10 +31,10 @@ int32_t SSL_GFX::draw() {
uint8_t colorBoundingBox[3];
if(robotStatus.connected){
colorBoundingBox[0] = 0;
colorBoundingBox[1] = 0b11111100;
colorBoundingBox[1] = 0xFC;
colorBoundingBox[2] = 0;
}else{
colorBoundingBox[0] = 0b11111100;
colorBoundingBox[0] = 0xFC;
colorBoundingBox[1] = 0;
colorBoundingBox[2] = 0;
}
@@ -45,6 +45,7 @@ int32_t SSL_GFX::draw() {
errors += drawBatteryBar();
errors += drawRobotLid();
errors += drawRobotTeam();
errors += drawBall();
errors += hDisplay->setPosition(posX, posY, sizeX, sizeY);
errors += hDisplay->write((uint8_t*)hBuffer, 19200);
return errors;
@@ -57,53 +58,29 @@ int32_t SSL_GFX::setRobotStatus(RobotStatus status) {
// Private methods
int32_t SSL_GFX::drawText(uint8_t color[3], uint16_t posX, uint16_t posY, uint8_t* string, uint32_t size) {
if(posX+6*size > sizeX){
// Out of bounds
return -1;
}
if(posY+6 > sizeY){
// Out of bounds
return -1;
}
for(uint32_t i = 0; i<size; i++){
for(uint32_t j = 0; j<6; j++){
for(uint32_t k = 0; k<6; k++){
if((font[string[i]-32][k]>>(j))&1){
hBuffer[j+posY][k+posX][0] = color[0];
hBuffer[j+posY][k+posX][1] = color[1];
hBuffer[j+posY][k+posX][2] = color[2];
}else{
hBuffer[j+posY][k+posX][0] = 0;
hBuffer[j+posY][k+posX][1] = 0;
hBuffer[j+posY][k+posX][2] = 0;
}
}
}
posX += 6;
}
return 0;
}
int32_t SSL_GFX::drawBoundingBox(uint8_t color[3]) {
for(uint32_t i=0; i<sizeX; i++){
for(uint32_t j=0; j<3; j++){
hBuffer[0][i][j] = color[j];
hBuffer[1][i][j] = color[j];
}
}
for(uint32_t i=0; i<sizeX; i++){
for(uint32_t j=0; j<3; j++){
hBuffer[sizeY-1][i][j] = color[j];
hBuffer[sizeY-2][i][j] = color[j];
}
}
for(uint32_t i=0; i<sizeX; i++){
for(uint32_t i=0; i<sizeY; i++){
for(uint32_t j=0; j<3; j++){
hBuffer[i][0][j] = color[j];
hBuffer[i][1][j] = color[j];
}
}
for(uint32_t i=0; i<sizeX; i++){
for(uint32_t i=0; i<sizeY; i++){
for(uint32_t j=0; j<3; j++){
hBuffer[i][sizeX-1][j] = color[j];
hBuffer[i][sizeX-2][j] = color[j];
}
}
return 0;
@@ -257,6 +234,83 @@ int32_t SSL_GFX::drawRobotTeam(){
return drawCircle(colorTobotTeam, 40, 40, 5);
}
int32_t SSL_GFX::drawBall() {
int32_t errors = 0;
uint8_t hasBallColor[3] = {0xFC, 0xA0, 0x00};
uint8_t noBallColor[3] = {0x00, 0x00, 0x00};
if(robotStatus.status&1){
drawCircle(hasBallColor, 40, 21, 4);
}else{
drawCircle(noBallColor, 40, 21, 4);
}
return errors;
}
int32_t SSL_GFX::drawId(uint8_t color[3]) {
uint32_t errors = 0;
errors += drawText(color, 3, 71, (uint8_t*)"ID = ", 5);
if(robotStatus.robotId<10){
uint8_t robotIdChar = robotStatus.robotId+48;
errors += drawText(color, 33, 71, &robotIdChar, 1);
}else{
uint8_t robotIdChar[2] = {49, robotStatus.robotId+(uint8_t)38};
errors += drawText(color, 33, 71, robotIdChar, 2);
}
return errors;
}
int32_t SSL_GFX::drawBatteryBar() {
uint32_t errors = 0;
for(uint32_t j = 3; j<7; j++){
for(uint32_t k = 3; k<77; k++){
if(robotStatus.batteryLevel*74 > k){
if(robotStatus.batteryLevel>0.5){
hBuffer[j][k][0] = ((uint8_t)(512-robotStatus.batteryLevel*512))&0xFC;
hBuffer[j][k][1] = 255&0xFC;
hBuffer[j][k][2] = 0;
}else{
hBuffer[j][k][0] = 255&0xFC;
hBuffer[j][k][1] = ((uint8_t)(robotStatus.batteryLevel*511))&0xFC;
hBuffer[j][k][2] = 0;
}
}else{
hBuffer[j][k][0] = 0;
hBuffer[j][k][1] = 0;
hBuffer[j][k][2] = 0;
}
}
}
return errors;
}
int32_t SSL_GFX::drawText(uint8_t color[3], uint16_t posX, uint16_t posY, uint8_t* string, uint32_t size) {
if(posX+6*size > sizeX){
// Out of bounds
return -1;
}
if(posY+6 > sizeY){
// Out of bounds
return -1;
}
for(uint32_t i = 0; i<size; i++){
for(uint32_t j = 0; j<6; j++){
for(uint32_t k = 0; k<6; k++){
if((font[string[i]-32][k]>>(j))&1){
hBuffer[j+posY][k+posX][0] = color[0];
hBuffer[j+posY][k+posX][1] = color[1];
hBuffer[j+posY][k+posX][2] = color[2];
}else{
hBuffer[j+posY][k+posX][0] = 0;
hBuffer[j+posY][k+posX][1] = 0;
hBuffer[j+posY][k+posX][2] = 0;
}
}
}
posX += 6;
}
return 0;
}
int32_t SSL_GFX::drawCircle(uint8_t color[3], uint16_t posX, uint16_t posY, uint16_t radius) {
uint32_t errors = 0;
uint8_t corners = 3;
@@ -324,40 +378,3 @@ int32_t SSL_GFX::drawCircle(uint8_t color[3], uint16_t posX, uint16_t posY, uint
}
return errors;
}
int32_t SSL_GFX::drawId(uint8_t color[3]) {
uint32_t errors = 0;
errors += drawText(color, 2, 72, (uint8_t*)"ID = ", 5);
if(robotStatus.robotId<10){
uint8_t robotIdChar = robotStatus.robotId+48;
errors += drawText(color, 32, 72, &robotIdChar, 1);
}else{
uint8_t robotIdChar[2] = {49, robotStatus.robotId+(uint8_t)38};
errors += drawText(color, 32, 72, robotIdChar, 2);
}
return errors;
}
int32_t SSL_GFX::drawBatteryBar() {
uint32_t errors = 0;
for(uint32_t j = 2; j<6; j++){
for(uint32_t k = 2; k<78; k++){
if(robotStatus.batteryLevel*76 > k){
if(robotStatus.batteryLevel>0.5){
hBuffer[j][k][0] = ((uint8_t)(512-robotStatus.batteryLevel*512))&0xFC;
hBuffer[j][k][1] = 255&0xFC;
hBuffer[j][k][2] = 0;
}else{
hBuffer[j][k][0] = 255&0xFC;
hBuffer[j][k][1] = ((uint8_t)(robotStatus.batteryLevel*511))&0xFC;
hBuffer[j][k][2] = 0;
}
}else{
hBuffer[j][k][0] = 0;
hBuffer[j][k][1] = 0;
hBuffer[j][k][2] = 0;
}
}
}
return errors;
}

View File

@@ -37,14 +37,16 @@ private:
uint16_t posY;
uint8_t (*hBuffer)[sizeX][3];
uint32_t size;
int32_t drawText(uint8_t color[3], uint16_t posX, uint16_t posY, uint8_t* string, uint32_t size);
int32_t drawCircle(uint8_t color[3], uint16_t posX, uint16_t posY, uint16_t radius);
int32_t drawBoundingBox(uint8_t color[3]);
int32_t drawRobotSilhouette(uint8_t color[3]);
int32_t drawRobotLid();
int32_t drawRobotTeam();
int32_t drawBall();
int32_t drawId(uint8_t color[3]);
int32_t drawBatteryBar();
int32_t drawText(uint8_t color[3], uint16_t posX, uint16_t posY, uint8_t* string, uint32_t size);
int32_t drawCircle(uint8_t color[3], uint16_t posX, uint16_t posY, uint16_t radius);
};
#endif /* SRC_COMPONENTS_SSL_GFX_HPP_ */