mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-03-17 21:32:52 +01:00
moved the system monitor functions to a separate file and task
This commit is contained in:
parent
4a2fc973b6
commit
5a689f90cc
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -8,7 +8,7 @@
|
||||
"interface/ftdi/esp32_devkitj_v1.cfg",
|
||||
"target/esp32s3.cfg"
|
||||
],
|
||||
"idf.port": "/dev/cu.usbserial-1464401",
|
||||
"idf.port": "/dev/cu.usbserial-1464301",
|
||||
"idf.pythonBinPath": "/Users/skot/.espressif/python_env/idf4.4_py3.9_env/bin/python",
|
||||
"idf.toolsPath": "/Users/skot/.espressif",
|
||||
"files.associations": {
|
||||
@ -18,7 +18,8 @@
|
||||
"ds4432u.h": "c",
|
||||
"led_controller.h": "c",
|
||||
"*.tcc": "c",
|
||||
"*.ipp": "c"
|
||||
"*.ipp": "c",
|
||||
"complex": "cpp"
|
||||
},
|
||||
"idf.flashType": "UART"
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
idf_component_register(SRCS "adc.c" "INA260.c" "EMC2101.c" "i2c_simple_main.c" "led_controller.c" "DS4432U.c" "EMC2101.c" "INA260.c" "adc.c" "oled.c" "fonts.c"
|
||||
idf_component_register(SRCS "system.c" "adc.c" "INA260.c" "EMC2101.c" "i2c_simple_main.c" "led_controller.c" "DS4432U.c" "EMC2101.c" "INA260.c" "adc.c" "oled.c" "fonts.c" "system.c"
|
||||
INCLUDE_DIRS ".")
|
||||
|
@ -24,89 +24,15 @@
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#include "led_controller.h"
|
||||
#include "DS4432U.h"
|
||||
#include "EMC2101.h"
|
||||
#include "INA260.h"
|
||||
#include "adc.h"
|
||||
#include "oled.h"
|
||||
#include "system.h"
|
||||
|
||||
static const char *TAG = "i2c-test";
|
||||
static const char *TAG = "main";
|
||||
|
||||
TaskHandle_t sysTaskHandle = NULL;
|
||||
|
||||
void app_main(void) {
|
||||
char oled_buf[20];
|
||||
ESP_LOGI(TAG, "Welcome to The bitaxe!");
|
||||
|
||||
//test the LEDs
|
||||
// ESP_LOGI(TAG, "Init LEDs!");
|
||||
// ledc_init();
|
||||
// led_set();
|
||||
|
||||
//Playing with BI level
|
||||
gpio_set_direction(GPIO_NUM_10, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(GPIO_NUM_10, 0);
|
||||
|
||||
//Init I2C
|
||||
ESP_ERROR_CHECK(i2c_master_init());
|
||||
ESP_LOGI(TAG, "I2C initialized successfully");
|
||||
|
||||
ADC_init();
|
||||
|
||||
//DS4432U tests
|
||||
DS4432U_set_vcore(1.4);
|
||||
xTaskCreate(SysTask, "System_Task", 4096, NULL, 10, &sysTaskHandle);
|
||||
|
||||
//Fan Tests
|
||||
EMC2101_init();
|
||||
EMC2101_set_fan_speed(0.5);
|
||||
vTaskDelay(500 / portTICK_RATE_MS);
|
||||
|
||||
//oled
|
||||
if (OLED_init()) {
|
||||
OLED_fill(0); // fill with black
|
||||
snprintf(oled_buf, 20, "The Bitaxe");
|
||||
OLED_writeString(0, 0, oled_buf);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "OLED did not init!\n");
|
||||
}
|
||||
|
||||
while (1) {
|
||||
uint16_t fan_speed = EMC2101_get_fan_speed();
|
||||
float chip_temp = EMC2101_get_chip_temp();
|
||||
float current = INA260_read_current();
|
||||
float voltage = INA260_read_voltage();
|
||||
float power = INA260_read_power();
|
||||
uint16_t vcore = ADC_get_vcore();
|
||||
|
||||
ESP_LOGI(TAG, "Fan Speed: %d RPM", fan_speed);
|
||||
ESP_LOGI(TAG, "Chip Temp: %.2f C", chip_temp);
|
||||
|
||||
//Current Sensor tests
|
||||
ESP_LOGI(TAG, "Current: %.2f mA", current);
|
||||
ESP_LOGI(TAG, "Voltage: %.2f mV", voltage);
|
||||
ESP_LOGI(TAG, "Power: %.2f mW", power);
|
||||
|
||||
//ESP32 ADC tests
|
||||
ESP_LOGI(TAG, "Vcore: %d mV\n", vcore);
|
||||
|
||||
if (OLED_status()) {
|
||||
memset(oled_buf, 0, 20);
|
||||
snprintf(oled_buf, 20, "Fan: %d RPM", fan_speed);
|
||||
OLED_clearLine(1);
|
||||
OLED_writeString(0, 1, oled_buf);
|
||||
|
||||
memset(oled_buf, 0, 20);
|
||||
snprintf(oled_buf, 20, "Temp: %.2f C", chip_temp);
|
||||
OLED_clearLine(2);
|
||||
OLED_writeString(0, 2, oled_buf);
|
||||
|
||||
memset(oled_buf, 0, 20);
|
||||
snprintf(oled_buf, 20, "Pwr: %.2f mW", power);
|
||||
OLED_clearLine(3);
|
||||
OLED_writeString(0, 3, oled_buf);
|
||||
}
|
||||
|
||||
vTaskDelay(5000 / portTICK_RATE_MS);
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(i2c_master_delete());
|
||||
ESP_LOGI(TAG, "I2C unitialized successfully");
|
||||
}
|
||||
|
96
main/system.c
Normal file
96
main/system.c
Normal file
@ -0,0 +1,96 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "driver/i2c.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#include "led_controller.h"
|
||||
#include "DS4432U.h"
|
||||
#include "EMC2101.h"
|
||||
#include "INA260.h"
|
||||
#include "adc.h"
|
||||
#include "oled.h"
|
||||
|
||||
static const char *TAG = "system";
|
||||
|
||||
void init_system(void) {
|
||||
|
||||
//test the LEDs
|
||||
// ESP_LOGI(TAG, "Init LEDs!");
|
||||
// ledc_init();
|
||||
// led_set();
|
||||
|
||||
//Playing with BI level
|
||||
gpio_set_direction(GPIO_NUM_10, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(GPIO_NUM_10, 0);
|
||||
|
||||
//Init I2C
|
||||
ESP_ERROR_CHECK(i2c_master_init());
|
||||
ESP_LOGI(TAG, "I2C initialized successfully");
|
||||
|
||||
ADC_init();
|
||||
|
||||
//DS4432U tests
|
||||
DS4432U_set_vcore(1.4);
|
||||
|
||||
//Fan Tests
|
||||
EMC2101_init();
|
||||
EMC2101_set_fan_speed(0.75);
|
||||
vTaskDelay(500 / portTICK_RATE_MS);
|
||||
|
||||
//oled
|
||||
if (!OLED_init()) {
|
||||
ESP_LOGI(TAG, "OLED init failed!");
|
||||
}
|
||||
}
|
||||
|
||||
void get_stats(void) {
|
||||
char oled_buf[20];
|
||||
|
||||
uint16_t fan_speed = EMC2101_get_fan_speed();
|
||||
float chip_temp = EMC2101_get_chip_temp();
|
||||
float current = INA260_read_current();
|
||||
float voltage = INA260_read_voltage();
|
||||
float power = INA260_read_power();
|
||||
uint16_t vcore = ADC_get_vcore();
|
||||
|
||||
ESP_LOGI(TAG, "Fan Speed: %d RPM", fan_speed);
|
||||
ESP_LOGI(TAG, "Chip Temp: %.2f C", chip_temp);
|
||||
|
||||
//Current Sensor tests
|
||||
ESP_LOGI(TAG, "Current: %.2f mA", current);
|
||||
ESP_LOGI(TAG, "Voltage: %.2f mV", voltage);
|
||||
ESP_LOGI(TAG, "Power: %.2f mW", power);
|
||||
|
||||
//ESP32 ADC tests
|
||||
ESP_LOGI(TAG, "Vcore: %d mV\n", vcore);
|
||||
|
||||
if (OLED_status()) {
|
||||
memset(oled_buf, 0, 20);
|
||||
snprintf(oled_buf, 20, "Fan: %d RPM", fan_speed);
|
||||
OLED_clearLine(1);
|
||||
OLED_writeString(0, 1, oled_buf);
|
||||
|
||||
memset(oled_buf, 0, 20);
|
||||
snprintf(oled_buf, 20, "Temp: %.2f C", chip_temp);
|
||||
OLED_clearLine(2);
|
||||
OLED_writeString(0, 2, oled_buf);
|
||||
|
||||
memset(oled_buf, 0, 20);
|
||||
snprintf(oled_buf, 20, "Pwr: %.2f mW", power);
|
||||
OLED_clearLine(3);
|
||||
OLED_writeString(0, 3, oled_buf);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SysTask(void *arg) {
|
||||
|
||||
init_system();
|
||||
|
||||
while(1){
|
||||
get_stats();
|
||||
vTaskDelay(5000 / portTICK_RATE_MS);
|
||||
}
|
||||
}
|
8
main/system.h
Normal file
8
main/system.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef SYSTEM_H_
|
||||
#define SYSTEM_H_
|
||||
|
||||
void SysTask(void *arg);
|
||||
void init_system(void);
|
||||
void get_stats(void);
|
||||
|
||||
#endif /* SYSTEM_H_ */
|
Loading…
x
Reference in New Issue
Block a user