Nonce starting point + fix halving blocks
- Added different nonce start point for each thread - Fixed halving block calculation - Added firmware version on initial screen
This commit is contained in:
parent
2adfede605
commit
54ace9455d
@ -10,11 +10,14 @@
|
||||
#include "mbedtls/md.h"
|
||||
#include "media/images.h"
|
||||
#include "media/myFonts.h"
|
||||
#include "media/Free_Fonts.h"
|
||||
#include "OpenFontRender.h"
|
||||
#include "wManager.h"
|
||||
#include "mining.h"
|
||||
#include "monitor.h"
|
||||
|
||||
#define CURRENT_VERSION "V1.5.2"
|
||||
|
||||
//3 seconds WDT
|
||||
#define WDT_TIMEOUT 3
|
||||
OneButton button1(PIN_BUTTON_1);
|
||||
@ -98,7 +101,8 @@ void setup()
|
||||
/******** PRINT INIT SCREEN *****/
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.pushImage(0, 0, initWidth, initHeight, initScreen);
|
||||
|
||||
tft.setTextColor(TFT_BLACK);
|
||||
tft.drawString(CURRENT_VERSION, 24, 130, FONT2);
|
||||
delay(2000);
|
||||
|
||||
/******** INIT WIFI ************/
|
||||
@ -134,7 +138,7 @@ void setup()
|
||||
// Start mining tasks
|
||||
//BaseType_t res = xTaskCreate(runWorker, name, 35000, (void*)name, 1, NULL);
|
||||
xTaskCreate(runMiner, "Miner0", 15000, NULL, 1, NULL);
|
||||
//xTaskCreate(runMiner, "Miner1", 15000, NULL, 1, NULL);
|
||||
xTaskCreate(runMiner, "Miner1", 15000, NULL, 1, NULL);
|
||||
|
||||
/******** MONITOR SETUP *****/
|
||||
setup_monitor();
|
||||
|
@ -181,9 +181,9 @@ void runStratumWorker(void *name) {
|
||||
case MINING_NOTIFY: if(parse_mining_notify(line, mJob)){
|
||||
//Increse templates readed
|
||||
templates++;
|
||||
//Stop miner current job
|
||||
//Stop miner current jobs
|
||||
mMiner.inRun = false;
|
||||
//Prepare data for new job
|
||||
//Prepare data for new jobs
|
||||
mMiner=calculateMiningData(mWorker,mJob);
|
||||
mMiner.poolDifficulty = currentPoolDifficulty;
|
||||
mMiner.newJob = true;
|
||||
@ -215,6 +215,8 @@ void runStratumWorker(void *name) {
|
||||
#include "shaTests/customSHA256.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
void runMiner(void * name){
|
||||
unsigned long nonce;
|
||||
unsigned long max_nonce;
|
||||
|
||||
while(1){
|
||||
|
||||
@ -223,9 +225,18 @@ void runMiner(void * name){
|
||||
if(mMiner.newJob==true || mMiner.newJob2==true) break;
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS); //Small delay
|
||||
}
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS); //Small delay to join both mining threads
|
||||
|
||||
if(mMiner.newJob) mMiner.newJob = false; //Clear newJob flag
|
||||
else if(mMiner.newJob2) mMiner.newJob2 = false; //Clear newJob flag
|
||||
if(mMiner.newJob) {
|
||||
mMiner.newJob = false; //Clear newJob flag
|
||||
nonce = 0;
|
||||
max_nonce = MAX_NONCE;
|
||||
}
|
||||
else if(mMiner.newJob2){
|
||||
mMiner.newJob2 = false; //Clear newJob flag
|
||||
nonce = TARGET_NONCE - MAX_NONCE;
|
||||
max_nonce = TARGET_NONCE;
|
||||
}
|
||||
mMiner.inRun = true; //Set inRun flag
|
||||
|
||||
//Prepare Premining data
|
||||
@ -248,12 +259,11 @@ void runMiner(void * name){
|
||||
Serial.println("");
|
||||
*/
|
||||
// search a valid nonce
|
||||
unsigned long nonce = TARGET_NONCE - MAX_NONCE;
|
||||
uint32_t startT = micros();
|
||||
unsigned char *header64 = mMiner.bytearray_blockheader + 64;
|
||||
Serial.println(">>> STARTING TO HASH NONCES");
|
||||
while(true) {
|
||||
//memcpy(mMiner.bytearray_blockheader + 76, &nonce, 4);
|
||||
memcpy(mMiner.bytearray_blockheader + 76, &nonce, 4);
|
||||
|
||||
//Con midstate
|
||||
// Primer SHA-256
|
||||
@ -274,7 +284,7 @@ void runMiner(void * name){
|
||||
Serial.println(""); */
|
||||
|
||||
hashes++;
|
||||
if (nonce++> TARGET_NONCE) break; //exit
|
||||
if (nonce++> max_nonce) break; //exit
|
||||
if(!mMiner.inRun) { Serial.println ("MINER WORK ABORTED >> waiting new job"); break;}
|
||||
|
||||
// check if 16bit share
|
||||
|
@ -80,13 +80,12 @@ void updateGlobalData(void){
|
||||
}
|
||||
http.end();
|
||||
|
||||
//Make second API call to get remaining Blocks
|
||||
|
||||
//OLD code gets remaining blocks to next difficulty ajustment
|
||||
/*//Make second API call to get remaining Blocks
|
||||
http.begin(getDifficulty);
|
||||
httpCode = http.GET();
|
||||
|
||||
//TODO -> current data is giving new difficulty event
|
||||
// -> add halving table and calculate blocks to next event
|
||||
// -> calculate percentage to nearest event
|
||||
if (httpCode > 0) {
|
||||
String payload = http.getString();
|
||||
|
||||
@ -101,7 +100,7 @@ void updateGlobalData(void){
|
||||
mGlobalUpdate = millis();
|
||||
}
|
||||
|
||||
http.end();
|
||||
http.end();*/
|
||||
|
||||
//Make third API call to get fees
|
||||
http.begin(getFees);
|
||||
@ -252,20 +251,16 @@ void show_MinerScreen(unsigned long mElapsed){
|
||||
render.drawString(String(shares).c_str(), 186, 76, 0xDEDB);
|
||||
//Hores
|
||||
char timeMining[15];
|
||||
|
||||
unsigned long secElapsed = millis() / 1000;
|
||||
int days = secElapsed / 86400;
|
||||
int hours = (secElapsed - (days * 86400)) / 3600; //Number of seconds in an hour
|
||||
int mins = (secElapsed - (days * 86400) - (hours * 3600)) / 60; //Remove the number of hours and calculate the minutes.
|
||||
int secs = secElapsed - (days * 86400) - (hours * 3600) - (mins * 60);
|
||||
sprintf(timeMining, "%01d,%02d:%02d:%02d", days, hours, mins, secs);
|
||||
render.setFontSize(33);
|
||||
render.rdrawString(String(timeMining).c_str(), 315, 102, 0xDEDB);
|
||||
//Minutss
|
||||
//render.setFontSize(36);
|
||||
//render.rdrawString(String(mins).c_str(), 253, 99, 0xDEDB);
|
||||
//Segons
|
||||
//render.setFontSize(36);
|
||||
//render.rdrawString(String(sec).c_str(), 298, 99, 0xDEDB);
|
||||
sprintf(timeMining, "%01d %02d:%02d:%02d", days, hours, mins, secs);
|
||||
render.setFontSize(27);
|
||||
render.rdrawString(String(timeMining).c_str(), 315, 104, 0xDEDB);
|
||||
|
||||
//Valid Blocks
|
||||
render.setFontSize(48);
|
||||
render.drawString(String(valids).c_str(), 285, 56, 0xDEDB);
|
||||
@ -283,10 +278,10 @@ void show_MinerScreen(unsigned long mElapsed){
|
||||
render.rdrawString(getTime().c_str(), 286, 1, TFT_BLACK);
|
||||
|
||||
// pool url
|
||||
background.setTextSize(1);
|
||||
/*background.setTextSize(1);
|
||||
background.setTextDatum(MC_DATUM);
|
||||
background.setTextColor(0xDEDB);
|
||||
background.drawString(String(poolString), 59, 85, FONT2);
|
||||
background.drawString(String(poolString), 59, 85, FONT2);*/
|
||||
|
||||
//Push prepared background to screen
|
||||
background.pushSprite(0,0);
|
||||
@ -390,10 +385,14 @@ void show_GlobalHashScreen(unsigned long mElapsed){
|
||||
|
||||
//Print BlockHeight
|
||||
render.setFontSize(55);
|
||||
render.rdrawString(getBlockHeight().c_str(), 140, 104, 0xDEDB);
|
||||
gData.currentBlock = getBlockHeight();
|
||||
render.rdrawString(gData.currentBlock.c_str(), 140, 104, 0xDEDB);
|
||||
|
||||
//Draw percentage rectangle
|
||||
//width percent bar 140 - 2
|
||||
unsigned long cBlock = gData.currentBlock.toInt();
|
||||
gData.remainingBlocks = (((cBlock / HALVING_BLOCKS)+1) * HALVING_BLOCKS) - cBlock;
|
||||
gData.progressPercent = (HALVING_BLOCKS-gData.remainingBlocks)*100/HALVING_BLOCKS;
|
||||
int x2 = 2 + (138*gData.progressPercent/100);
|
||||
background.fillRect(2, 149, x2, 168, 0xDEDB);
|
||||
|
||||
|
@ -25,6 +25,8 @@
|
||||
#define getFees "https://mempool.space/api/v1/fees/recommended"
|
||||
#define UPDATE_Global_min 2
|
||||
|
||||
#define NEXT_HALVING_EVENT 840000
|
||||
#define HALVING_BLOCKS 210000
|
||||
|
||||
typedef struct{
|
||||
uint8_t screen;
|
||||
@ -33,7 +35,7 @@ typedef struct{
|
||||
|
||||
typedef struct{
|
||||
String globalHash; //hexahashes
|
||||
String lastBlock;
|
||||
String currentBlock;
|
||||
String difficulty;
|
||||
String blocksHalving;
|
||||
float progressPercent;
|
||||
|
Loading…
Reference in New Issue
Block a user