-
Notifications
You must be signed in to change notification settings - Fork 259
/
NerdMinerV2.ino.cpp
163 lines (127 loc) · 4.28 KB
/
NerdMinerV2.ino.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <Wire.h>
#include <Arduino.h>
#include <WiFi.h>
#include <WebServer.h>
#include <esp_task_wdt.h>
#include <OneButton.h>
#include "mbedtls/md.h"
#include "wManager.h"
#include "mining.h"
#include "monitor.h"
#include "drivers/displays/display.h"
#include "drivers/storage/SDCard.h"
#include "timeconst.h"
//3 seconds WDT
#define WDT_TIMEOUT 3
//15 minutes WDT for miner task
#define WDT_MINER_TIMEOUT 900
#ifdef PIN_BUTTON_1
OneButton button1(PIN_BUTTON_1);
#endif
#ifdef PIN_BUTTON_2
OneButton button2(PIN_BUTTON_2);
#endif
extern monitor_data mMonitor;
SDCard SDCrd = SDCard();
/**********************⚡ GLOBAL Vars *******************************/
unsigned long start = millis();
const char* ntpServer = "pool.ntp.org";
//void runMonitor(void *name);
/********* INIT *****/
void setup()
{
//Init pin 15 to eneble 5V external power (LilyGo bug)
#ifdef PIN_ENABLE5V
pinMode(PIN_ENABLE5V, OUTPUT);
digitalWrite(PIN_ENABLE5V, HIGH);
#endif
#ifdef MONITOR_SPEED
Serial.begin(MONITOR_SPEED);
#else
Serial.begin(115200);
#endif //MONITOR_SPEED
Serial.setTimeout(0);
delay(SECOND_MS/10);
esp_task_wdt_init(WDT_MINER_TIMEOUT, true);
// Idle task that would reset WDT never runs, because core 0 gets fully utilized
disableCore0WDT();
//disableCore1WDT();
// Setup the buttons
#if defined(PIN_BUTTON_1) && !defined(PIN_BUTTON_2) //One button device
button1.setPressMs(5*SECOND_MS);
button1.attachClick(switchToNextScreen);
button1.attachDoubleClick(alternateScreenRotation);
button1.attachLongPressStart(reset_configuration);
button1.attachMultiClick(alternateScreenState);
#endif
#if defined(PIN_BUTTON_1) && defined(PIN_BUTTON_2) //Button 1 of two button device
button1.setPressMs(5*SECOND_MS);
button1.attachClick(alternateScreenState);
button1.attachDoubleClick(alternateScreenRotation);
#endif
#if defined(PIN_BUTTON_2) //Button 2 of two button device
button2.setPressMs(5*SECOND_MS);
button2.attachClick(switchToNextScreen);
button2.attachLongPressStart(reset_configuration);
#endif
/******** INIT NERDMINER ************/
Serial.println("NerdMiner v2 starting......");
/******** INIT DISPLAY ************/
initDisplay();
/******** PRINT INIT SCREEN *****/
drawLoadingScreen();
delay(2*SECOND_MS);
/******** SHOW LED INIT STATUS (devices without screen) *****/
mMonitor.NerdStatus = NM_waitingConfig;
doLedStuff(0);
/******** INIT WIFI ************/
init_WifiManager();
/******** CREATE TASK TO PRINT SCREEN *****/
//tft.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen);
// Higher prio monitor task
Serial.println("");
Serial.println("Initiating tasks...");
char *name = (char*) malloc(32);
sprintf(name, "(%s)", "Monitor");
BaseType_t res1 = xTaskCreatePinnedToCore(runMonitor, "Monitor", 10000, (void*)name, 4, NULL,1);
/******** CREATE STRATUM TASK *****/
sprintf(name, "(%s)", "Stratum");
#ifdef ESP32_2432S028R
// Free a little bit of the heap to the screen
BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 13500, (void*)name, 3, NULL,1);
#else
BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 15000, (void*)name, 3, NULL,1);
#endif
/******** CREATE MINER TASKS *****/
//for (size_t i = 0; i < THREADS; i++) {
// char *name = (char*) malloc(32);
// sprintf(name, "(%d)", i);
// Start mining tasks
//BaseType_t res = xTaskCreate(runWorker, name, 35000, (void*)name, 1, NULL);
TaskHandle_t minerTask1, minerTask2 = NULL;
xTaskCreate(runMiner, "Miner0", 6000, (void*)0, 1, &minerTask1);
xTaskCreate(runMiner, "Miner1", 6000, (void*)1, 1, &minerTask2);
esp_task_wdt_add(minerTask1);
esp_task_wdt_add(minerTask2);
/******** MONITOR SETUP *****/
setup_monitor();
}
void app_error_fault_handler(void *arg) {
// Get stack errors
char *stack = (char *)arg;
// Print the stack errors in the console
esp_log_write(ESP_LOG_ERROR, "APP_ERROR", "Pila de errores:\n%s", stack);
// restart ESP32
esp_restart();
}
void loop() {
// keep watching the push buttons:
#ifdef PIN_BUTTON_1
button1.tick();
#endif
#ifdef PIN_BUTTON_2
button2.tick();
#endif
wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code
vTaskDelay(50 / portTICK_PERIOD_MS);
}