Skip to content

Commit

Permalink
Merge pull request #32 from shufps/job-interval-ui-setting
Browse files Browse the repository at this point in the history
make job interval configurable in the web ui
  • Loading branch information
shufps authored Oct 20, 2024
2 parents 0174a81 + bc20c26 commit 2fc79d6
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 18 deletions.
4 changes: 4 additions & 0 deletions main/boards/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ void Board::loadSettings()
m_fanInvertPolarity = nvs_config_get_u16(NVS_CONFIG_INVERT_FAN_POLARITY, 1);
m_fanPerc = nvs_config_get_u16(NVS_CONFIG_FAN_SPEED, 100);

// was initialized with board specific default value in the constructor
m_asicJobIntervalMs = nvs_config_get_u16(NVS_CONFIG_ASIC_JOB_INTERVAL, m_asicJobIntervalMs);

ESP_LOGI(TAG, "NVS_CONFIG_ASIC_FREQ %.3f", (float) m_asicFrequency);
ESP_LOGI(TAG, "NVS_CONFIG_ASIC_VOLTAGE %.3f", (float) m_asicVoltage);
ESP_LOGI(TAG, "NVS_CONFIG_ASIC_JOB_INTERVAL %d", (int) m_asicJobIntervalMs);
ESP_LOGI(TAG, "NVS_CONFIG_INVERT_FAN_POLARITY %s", m_fanInvertPolarity ? "true" : "false");
ESP_LOGI(TAG, "NVS_CONFIG_FAN_SPEED %d%%", (int) m_fanPerc);
}
Expand Down
12 changes: 8 additions & 4 deletions main/boards/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,23 @@ class Board {
return m_isInitialized ? m_asics : nullptr;
}

float getMinPin() {
float getMinPin()
{
return m_minPin;
}

float getMaxPin() {
float getMaxPin()
{
return m_maxPin;
}

float getMinVin() {
float getMinVin()
{
return m_minVin;
}

float getMaxVin() {
float getMaxVin()
{
return m_maxVin;
}
};
2 changes: 1 addition & 1 deletion main/boards/nerdqaxeplus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ NerdQaxePlus::NerdQaxePlus() : Board() {
m_version = 501;
m_asicModel = "BM1368";
m_asicCount = 4;
m_asicJobIntervalMs = 1500;
m_asicJobIntervalMs = 1200;
m_asicFrequency = 490.0;
m_asicVoltage = 1.20;
m_initVoltage = 1.25;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
<div class="field grid p-fluid">
<label htmlFor="wifiPass" class="col-12 mb-2 md:col-2 md:mb-0">WiFi Password:</label>
<div class="col-12 md:col-10 p-input-icon-right">
<i *ngIf="form.get('wifiPass')?.dirty" class="pi"
[ngClass]="{'pi-eye': !showWifiPassword, 'pi-eye-slash': showWifiPassword}"
<i *ngIf="form.get('wifiPass')?.dirty" class="pi"
[ngClass]="{'pi-eye': !showWifiPassword, 'pi-eye-slash': showWifiPassword}"
(click)="toggleWifiPasswordVisibility()" style="cursor: pointer;"></i>
<input pInputText id="wifiPass" formControlName="wifiPass"
<input pInputText id="wifiPass" formControlName="wifiPass"
[type]="showWifiPassword ? 'text' : 'password'"
placeholder="Enter WiFi password" />
</div>
Expand Down Expand Up @@ -51,10 +51,10 @@
<div class="field grid p-fluid">
<label htmlFor="stratumPassword" class="col-12 mb-2 md:col-2 md:mb-0">Stratum Password:</label>
<div class="col-12 md:col-10 p-input-icon-right">
<i *ngIf="form.get('stratumPassword')?.dirty" class="pi"
[ngClass]="{'pi-eye': !showStratumPassword, 'pi-eye-slash': showStratumPassword}"
<i *ngIf="form.get('stratumPassword')?.dirty" class="pi"
[ngClass]="{'pi-eye': !showStratumPassword, 'pi-eye-slash': showStratumPassword}"
(click)="toggleStratumPasswordVisibility()" style="cursor: pointer;"></i>
<input pInputText id="stratumPassword" formControlName="stratumPassword"
<input pInputText id="stratumPassword" formControlName="stratumPassword"
[type]="showStratumPassword ? 'text' : 'password'"
placeholder="Enter stratum password" />
</div>
Expand Down Expand Up @@ -129,6 +129,12 @@
</div>
</div>

<div class="field grid p-fluid">
<label htmlFor="jobInterval" class="col-12 mb-2 md:col-2 md:mb-0">Job Interval</label>
<div class="col-12 md:col-10">
<input pInputText id="jobInterval" formControlName="jobInterval" type="number" />
</div>
</div>
</ng-container>

<div class="field grid p-fluid">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class EditComponent implements OnInit {
wifiPass: ['*****'],
coreVoltage: [info.coreVoltage, [Validators.required]],
frequency: [info.frequency, [Validators.required]],
jobInterval: [info.jobInterval, [Validators.required]],
autofanspeed: [info.autofanspeed == 1, [Validators.required]],
invertfanpolarity: [info.invertfanpolarity == 1, [Validators.required]],
fanspeed: [info.fanspeed, [Validators.required]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class SettingsComponent {
wifiPass: ['*****'],
coreVoltage: [info.coreVoltage, [Validators.required]],
frequency: [info.frequency, [Validators.required]],
jobInterval: [info.jobInterval, [Validators.required]],
autofanspeed: [info.autofanspeed == 1, [Validators.required]],
invertfanpolarity: [info.invertfanpolarity == 1, [Validators.required]],
fanspeed: [info.fanspeed, [Validators.required]],
Expand Down Expand Up @@ -111,6 +112,7 @@ export class SettingsComponent {

form.frequency = parseInt(form.frequency);
form.coreVoltage = parseInt(form.coreVoltage);
form.jobInterval = parseInt(form.jobInterval);

// bools to ints
form.flipscreen = form.flipscreen == true ? 1 : 0;
Expand Down
1 change: 1 addition & 0 deletions main/http_server/axe-os/src/app/services/system.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const defaultInfo: ISystemInfo = {
fanrpm: 0,
autoscreenoff: 0,
lastResetReason: "Unknown",
jobInterval: 1200,

boardtemp1: 30,
boardtemp2: 40,
Expand Down
1 change: 1 addition & 0 deletions main/http_server/axe-os/src/models/ISystemInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface ISystemInfo {
fanrpm: number,
coreVoltageActual: number,
lastResetReason: string,
jobInterval: number,

boardtemp1?: number,
boardtemp2?: number,
Expand Down
9 changes: 9 additions & 0 deletions main/http_server/http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ static esp_err_t PATCH_update_settings(httpd_req_t *req)
if ((item = cJSON_GetObjectItem(root, "frequency")) != NULL && item->valueint > 0) {
nvs_config_set_u16(NVS_CONFIG_ASIC_FREQ, item->valueint);
}
if ((item = cJSON_GetObjectItem(root, "jobInterval")) != NULL && item->valueint > 0) {
nvs_config_set_u16(NVS_CONFIG_ASIC_JOB_INTERVAL, item->valueint);
}
if ((item = cJSON_GetObjectItem(root, "flipscreen")) != NULL) {
nvs_config_set_u16(NVS_CONFIG_FLIP_SCREEN, item->valueint);
}
Expand All @@ -350,6 +353,11 @@ static esp_err_t PATCH_update_settings(httpd_req_t *req)

cJSON_Delete(root);
httpd_resp_send_chunk(req, NULL, 0);

// reload settings
Board* board = SYSTEM_MODULE.getBoard();
board->loadSettings();

return ESP_OK;
}

Expand Down Expand Up @@ -492,6 +500,7 @@ static esp_err_t GET_system_info(httpd_req_t *req)
cJSON_AddNumberToObject(root, "hashRate_10m", history->getCurrentHashrate10m());
cJSON_AddNumberToObject(root, "hashRate_1h", history->getCurrentHashrate1h());
cJSON_AddNumberToObject(root, "hashRate_1d", history->getCurrentHashrate1d());
cJSON_AddNumberToObject(root, "jobInterval", board->getAsicJobIntervalMs());
cJSON_AddStringToObject(root, "bestDiff", SYSTEM_MODULE.getBestDiffString());
cJSON_AddStringToObject(root, "bestSessionDiff", SYSTEM_MODULE.getBestSessionDiffString());

Expand Down
1 change: 1 addition & 0 deletions main/nvs_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define NVS_CONFIG_STRATUM_PASS "stratumpass"
#define NVS_CONFIG_ASIC_FREQ "asicfrequency"
#define NVS_CONFIG_ASIC_VOLTAGE "asicvoltage"
#define NVS_CONFIG_ASIC_JOB_INTERVAL "asicjobinterval"
#define NVS_CONFIG_FLIP_SCREEN "flipscreen"
#define NVS_CONFIG_INVERT_SCREEN "invertscreen"
#define NVS_CONFIG_INVERT_FAN_POLARITY "invertfanpol"
Expand Down
23 changes: 16 additions & 7 deletions main/tasks/create_jobs_task.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <limits.h>
#include <pthread.h>
#include <sys/time.h>
#include <string.h>
#include <sys/time.h>

#include "esp_log.h"
#include "esp_system.h"
Expand All @@ -10,8 +10,8 @@

#include "global_state.h"

#include "system.h"
#include "boards/board.h"
#include "system.h"

static const char *TAG = "create_jobs_task";

Expand All @@ -29,8 +29,8 @@ static uint32_t stratum_difficulty = 8192;
static uint32_t active_stratum_difficulty = 8192;
static uint32_t version_mask = 0;

#define min(a,b) ((a<b)?(a):(b))
#define max(a,b) ((a>b)?(a):(b))
#define min(a, b) ((a < b) ? (a) : (b))
#define max(a, b) ((a > b) ? (a) : (b))

static void create_job_timer(TimerHandle_t xTimer)
{
Expand Down Expand Up @@ -107,11 +107,10 @@ void create_job_mining_notify(mining_notify *notifiy)
trigger_job_creation();
}


void *create_jobs_task(void *pvParameters)
{
Board *board = SYSTEM_MODULE.getBoard();
Asic* asics = board->getAsics();
Asic *asics = board->getAsics();

ESP_LOGI(TAG, "ASIC Job Interval: %.2f ms", board->getAsicJobIntervalMs());
SYSTEM_MODULE.notifyMiningStarted();
Expand Down Expand Up @@ -139,11 +138,20 @@ void *create_jobs_task(void *pvParameters)
uint64_t last_submit_time = 0;
uint32_t extranonce_2 = 0;

int lastJobInterval = board->getAsicJobIntervalMs();

while (1) {
pthread_mutex_lock(&job_mutex);
pthread_cond_wait(&job_cond, &job_mutex); // Wait for the timer or external trigger
pthread_mutex_unlock(&job_mutex);

// job interval changed via UI
if (board->getAsicJobIntervalMs() != lastJobInterval) {
xTimerChangePeriod(job_timer, pdMS_TO_TICKS(board->getAsicJobIntervalMs()), 0);
lastJobInterval = board->getAsicJobIntervalMs();
continue;
}

pthread_mutex_lock(&current_stratum_job_mutex);

if (!current_job.ntime || !asics) {
Expand All @@ -161,7 +169,8 @@ void *create_jobs_task(void *pvParameters)
snprintf(extranonce_2_str, sizeof(extranonce_2_str), "%0*lx", (int) extranonce_2_len * 2, extranonce_2);

// generate coinbase tx
int coinbase_tx_len = strlen(current_job.coinbase_1) + strlen(extranonce_str) + strlen(extranonce_2_str) + strlen(current_job.coinbase_2);
int coinbase_tx_len =
strlen(current_job.coinbase_1) + strlen(extranonce_str) + strlen(extranonce_2_str) + strlen(current_job.coinbase_2);
char coinbase_tx[coinbase_tx_len + 1]; // +1 zero termination
snprintf(coinbase_tx, sizeof(coinbase_tx), "%s%s%s%s", current_job.coinbase_1, extranonce_str, extranonce_2_str,
current_job.coinbase_2);
Expand Down

0 comments on commit 2fc79d6

Please sign in to comment.