Add option in axeos to flip screen

This commit is contained in:
Ben 2023-10-01 21:40:36 -04:00
parent 10caab213c
commit 0fdb6e7a0d
9 changed files with 74 additions and 55 deletions

View File

@ -5,6 +5,14 @@
<h2>Settings</h2>
<ng-container *ngIf="form != null">
<form [formGroup]="form">
<div class="form-group">
<label>Flip Screen</label>
<input formControlName="flipscreen" type="checkbox">
</div>
<!-- <div class="form-group">
<label>Invert Screen</label>
<input formControlName="invertscreen" type="checkbox">
</div> -->
<div class="form-group">
<label>WiFi SSID: </label>
<input formControlName="ssid" type="text">

View File

@ -1,4 +1,4 @@
input {
input[type="text"] {
min-width: 250px;
max-width: 90%;
}
@ -15,7 +15,7 @@ select {
@media only screen and (min-width:900px) {
input {
input[type="text"] {
min-width: 500px
}

View File

@ -39,6 +39,8 @@ export class EditComponent {
.subscribe(info => {
this.ASICModel = info.ASICModel;
this.form = this.fb.group({
flipscreen: [info.flipscreen == 1],
invertscreen: [info.invertscreen == 1],
stratumURL: [info.stratumURL, [Validators.required]],
stratumPort: [info.stratumPort, [Validators.required]],
stratumUser: [info.stratumUser, [Validators.required]],
@ -67,6 +69,8 @@ export class EditComponent {
form.frequency = parseInt(form.frequency);
form.coreVoltage = parseInt(form.coreVoltage);
form.flipscreen = form.flipscreen == true ? 1 : 0;
form.invertscreen = form.invertscreen == true ? 1 : 0;
this.systemService.updateSystem(form)
.pipe(this.loadingService.lockUIUntilComplete())

View File

@ -42,6 +42,8 @@ export class SystemService {
stratumUser: "bc1q99n3pu025yyu0jlywpmwzalyhm36tg5u37w20d.bitaxe-U1",
frequency: 485,
version: "2.0",
flipscreen: 1,
invertscreen: 0
}
).pipe(delay(1000));
}

View File

@ -2,6 +2,8 @@ import { eASICModel } from './enum/eASICModel';
export interface ISystemInfo {
flipscreen: number;
invertscreen: number;
power: number,
voltage: number,
current: number,

View File

@ -94,7 +94,7 @@ button {
}
input,
input[type="text"],
select {
font-size: 1rem;

View File

@ -204,6 +204,9 @@ static esp_err_t PATCH_update_settings(httpd_req_t * req)
uint16_t coreVoltage = cJSON_GetObjectItem(root, "coreVoltage")->valueint;
uint16_t frequency = cJSON_GetObjectItem(root, "frequency")->valueint;
uint16_t flip_screen = cJSON_GetObjectItem(root, "flipscreen")->valueint;
uint16_t invert_screen = cJSON_GetObjectItem(root, "invertscreen")->valueint;
nvs_config_set_string(NVS_CONFIG_STRATUM_URL, stratumURL);
nvs_config_set_string(NVS_CONFIG_STRATUM_USER, stratumUser);
nvs_config_set_u16(NVS_CONFIG_STRATUM_PORT, stratumPort);
@ -211,6 +214,8 @@ static esp_err_t PATCH_update_settings(httpd_req_t * req)
nvs_config_set_string(NVS_CONFIG_WIFI_PASS, wifiPass);
nvs_config_set_u16(NVS_CONFIG_ASIC_VOLTAGE, coreVoltage);
nvs_config_set_u16(NVS_CONFIG_ASIC_FREQ, frequency);
nvs_config_set_u16(NVS_CONFIG_FLIP_SCREEN, flip_screen);
nvs_config_set_u16(NVS_CONFIG_INVERT_SCREEN, invert_screen);
cJSON_Delete(root);
httpd_resp_send_chunk(req, NULL, 0);
@ -266,6 +271,9 @@ static esp_err_t GET_system_info(httpd_req_t * req)
cJSON_AddStringToObject(root, "version", esp_app_get_description()->version);
cJSON_AddStringToObject(root, "runningPartition", esp_ota_get_running_partition()->label);
cJSON_AddNumberToObject(root, "flipscreen", nvs_config_get_u16(NVS_CONFIG_FLIP_SCREEN, 1));
cJSON_AddNumberToObject(root, "invertscreen", nvs_config_get_u16(NVS_CONFIG_INVERT_SCREEN, 0));
free(ssid);
free(wifiPass);
free(stratumURL);

View File

@ -14,6 +14,8 @@
#define NVS_CONFIG_ASIC_MODEL "asicmodel"
#define NVS_CONFIG_DEVICE_MODEL "devicemodel"
#define NVS_CONFIG_BOARD_VERSION "boardversion"
#define NVS_CONFIG_FLIP_SCREEN "flipscreen"
#define NVS_CONFIG_INVERT_SCREEN "invertscreen"
char * nvs_config_get_string(const char * key, const char * default_value);
void nvs_config_set_string(const char * key, const char * default_value);

View File

@ -15,20 +15,20 @@
// A copy of the display memory is maintained by this code so that single pixel
// writes can occur without having to read from the display controller.
#include <string.h>
#include "driver/i2c.h"
#include "esp_err.h"
#include "esp_log.h"
#include "nvs_config.h"
#include <stdbool.h>
#include <stdint.h>
#include "driver/i2c.h"
#include "esp_log.h"
#include "esp_err.h"
#include <string.h>
#include "oled.h"
#define I2C_TIMEOUT 1000
#define OLED_FLIP 1
#define OLED_INVERT 0
#define I2C_MASTER_NUM 0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
/*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
#define I2C_MASTER_NUM 0
extern unsigned char ucSmallFont[];
static int iScreenOffset; // current write offset of screen data
@ -43,35 +43,34 @@ static bool oled_active;
// Initialialize the OLED Screen
bool OLED_init(void)
{
uint8_t oled32_initbuf[] = {
0x00,
0xae, // cmd: display off
0xd5, // cmd: set display clock
0x80,
0xa8, // cmd: set multiplex ratio
0x1f, // HEIGHT - 1 -> 31
0xd3, // cmd: set display offset
0x00,
0x40, // cmd: Set Display Start Line
0x8d,
0x14, // cmd: Set Higher Column Start Address for Page Addressing Mode
0xa1,
0xc8, // cmd: Set COM Output Scan Direction C0/C8
0xda, // cmd: Set COM Pins Hardware Configuration
0x02, //
0x81, // cmd: Set Contrast control
0x7f,
0xd9, // cmd: Set Pre-Charge Period
0xf1,
0xdb, // comd: Vcom regulator output
0x40,
0xa4, // cmd: display on ram contents
0xa6, // cmd: set normal
0xaf}; // cmd: display on
uint8_t oled32_initbuf[] = {0x00,
0xae, // cmd: display off
0xd5, // cmd: set display clock
0x80,
0xa8, // cmd: set multiplex ratio
0x1f, // HEIGHT - 1 -> 31
0xd3, // cmd: set display offset
0x00,
0x40, // cmd: Set Display Start Line
0x8d,
0x14, // cmd: Set Higher Column Start Address for Page Addressing Mode
0xa1,
0xc8, // cmd: Set COM Output Scan Direction C0/C8
0xda, // cmd: Set COM Pins Hardware Configuration
0x02, //
0x81, // cmd: Set Contrast control
0x7f,
0xd9, // cmd: Set Pre-Charge Period
0xf1,
0xdb, // comd: Vcom regulator output
0x40,
0xa4, // cmd: display on ram contents
0xa6, // cmd: set normal
0xaf}; // cmd: display on
uint8_t uc[4];
uint8_t bFlip = OLED_FLIP;
uint8_t bInvert = OLED_INVERT;
uint8_t bFlip = nvs_config_get_u16(NVS_CONFIG_FLIP_SCREEN, 1);
uint8_t bInvert = nvs_config_get_u16(NVS_CONFIG_INVERT_SCREEN, 0);
oled_active = false;
// //enable the module
@ -98,15 +97,13 @@ bool OLED_init(void)
write(oled32_initbuf, sizeof(oled32_initbuf));
if (bInvert)
{
if (bInvert) {
uc[0] = 0; // command
uc[1] = 0xa7; // invert command
write(uc, 2);
}
if (bFlip)
{ // rotate display 180
if (bFlip) { // rotate display 180
uc[0] = 0; // command
uc[1] = 0xa0;
write(uc, 2);
@ -164,8 +161,7 @@ static void oledSetPosition(int x, int y)
x += 32; // display is centered in VRAM, so this is always true
if (oled_flip == 0) // non-flipped display starts from line 4
y += 4;
}
else if (oled_type == OLED_132x64) // SH1106 has 128 pixels centered in 132
} else if (oled_type == OLED_132x64) // SH1106 has 128 pixels centered in 132
{
x += 2;
}
@ -177,7 +173,7 @@ static void oledSetPosition(int x, int y)
// Write a block of pixel data to the OLED
// Length can be anything from 1 to 1024 (whole display)
static void oledWriteDataBlock(uint8_t *ucBuf, int iLen)
static void oledWriteDataBlock(uint8_t * ucBuf, int iLen)
{
uint8_t ucTemp[129];
@ -205,8 +201,7 @@ int OLED_setPixel(int x, int y, uint8_t ucColor)
return -1;
uc = ucOld = ucScreen[i];
uc &= ~(0x1 << (y & 7));
if (ucColor)
{
if (ucColor) {
uc |= (0x1 << (y & 7));
}
if (uc != ucOld) // pixel changed
@ -223,10 +218,10 @@ int OLED_setPixel(int x, int y, uint8_t ucColor)
// The X position is in character widths (8 or 16)
// The Y position is in memory pages (8 lines each)
//
int OLED_writeString(int x, int y, char *szMsg)
int OLED_writeString(int x, int y, char * szMsg)
{
int i, iLen;
uint8_t *s;
uint8_t * s;
// if (oled_i2c == NULL) return -1; // not initialized
@ -237,9 +232,8 @@ int OLED_writeString(int x, int y, char *szMsg)
iLen = 21 - x;
if (iLen < 0)
return -1;
for (i = 0; i < iLen; i++)
{
s = &ucSmallFont[(unsigned char)szMsg[i] * 6];
for (i = 0; i < iLen; i++) {
s = &ucSmallFont[(unsigned char) szMsg[i] * 6];
oledWriteDataBlock(s, 6);
}
@ -260,8 +254,7 @@ int OLED_fill(uint8_t ucData)
iCols = (oled_type == OLED_64x32) ? 4 : 8;
memset(temp, ucData, 128);
for (y = 0; y < iLines; y++)
{
for (y = 0; y < iLines; y++) {
oledSetPosition(0, y); // set to (0,Y)
oledWriteDataBlock(temp, iCols * 16); // fill with data byte
} // for y
@ -291,7 +284,7 @@ bool OLED_status(void)
/**
* @brief Write a byte to a I2C register
*/
static esp_err_t write(uint8_t *data, uint8_t len)
static esp_err_t write(uint8_t * data, uint8_t len)
{
int ret;