Skip to content

Commit

Permalink
Add undocumented option to rotate display by 180 deg.
Browse files Browse the repository at this point in the history
To set user need to edit dp_setting.txt manually:
 * rot 0 = no rotation
 * rot 1 = display rotated by 180 degrees.
  • Loading branch information
jose1711 committed Mar 12, 2023
1 parent 8a249e3 commit cfb3e90
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
Binary file modified firmware/beta_1.1.2_duckyscript3img.dfu
Binary file not shown.
1 change: 1 addition & 0 deletions firmware/code_duckyscript3/Inc/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extern profile_cache p_cache;
typedef struct
{
uint32_t sleep_after_ms;
uint8_t rotate;
} dp_global_settings;

void der_init(ds3_exe_result* der);
Expand Down
2 changes: 2 additions & 0 deletions firmware/code_duckyscript3/Inc/ssd1306.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ char ssd1306_WriteString(char* str, FontDef Font, SSD1306_COLOR color);
void ssd1306_SetCursor(uint8_t x, uint8_t y);
void ssd1306_dim(uint8_t is_dim);

extern SSD1306_t SSD1306;

static void ssd1306_WriteCommand(uint8_t command);

#endif
4 changes: 3 additions & 1 deletion firmware/code_duckyscript3/Src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ void save_settings(void)
if(f_open(&sd_file, "dp_settings.txt", FA_CREATE_ALWAYS | FA_WRITE) != 0)
goto ss_end;
memset(temp_buf, 0, PATH_SIZE);
sprintf(temp_buf, "sleep_after_min %d\nbi %d\nkbl %s\n", dp_settings.sleep_after_ms/60000, brightness_index, curr_kb_layout);
sprintf(temp_buf, "sleep_after_min %d\nrot %d\nbi %d\nkbl %s\n", dp_settings.sleep_after_ms/60000, dp_settings.rotate, brightness_index, curr_kb_layout);
f_write(&sd_file, temp_buf, strlen(temp_buf), &bytes_read);
ss_end:
f_close(&sd_file);
Expand All @@ -551,6 +551,8 @@ void load_settings(void)
{
if(strncmp(temp_buf, "sleep_after_min", 15) == 0)
dp_settings.sleep_after_ms = atoi(temp_buf+15) * 60000;
if(strncmp(temp_buf, "rot", 3) == 0)
dp_settings.rotate = atoi(temp_buf+3);
if(strncmp(temp_buf, "bi ", 3) == 0)
brightness_index = atoi(temp_buf+3);
if(brightness_index >= BRIGHTNESS_LEVELS)
Expand Down
8 changes: 7 additions & 1 deletion firmware/code_duckyscript3/Src/ssd1306.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ssd1306.h"
#include "shared.h"
#include "parser.h"

#define SSD1306_LCDWIDTH 128
#define SSD1306_LCDHEIGHT 64
Expand Down Expand Up @@ -38,6 +39,8 @@ SSD1306_t SSD1306;
uint8_t i2c_status;
uint8_t last_dim;

extern dp_global_settings dp_settings;

//
// Een byte sturen naar het commando register
// Kan niet gebruikt worden buiten deze file
Expand Down Expand Up @@ -168,7 +171,10 @@ void ssd1306_DrawPixel(uint8_t x, uint8_t y, SSD1306_COLOR color)
// We gaan niet buiten het scherm schrijven
return;
}

if (dp_settings.rotate) {
x = SSD1306_WIDTH - x - 1;
y = SSD1306_HEIGHT - y - 1;
}
// Kijken of de pixel geinverteerd moet worden
if (SSD1306.Inverted)
{
Expand Down

0 comments on commit cfb3e90

Please sign in to comment.