generated from LailaTheElf/rp2040_c
better sheduling
This commit is contained in:
113
src/main.cpp
113
src/main.cpp
@@ -5,6 +5,7 @@
|
|||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
#include <Adafruit_SPIDevice.h>
|
#include <Adafruit_SPIDevice.h>
|
||||||
#include <Adafruit_ILI9341.h>
|
#include <Adafruit_ILI9341.h>
|
||||||
|
#include <dhcp.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "max31856.h"
|
#include "max31856.h"
|
||||||
@@ -88,59 +89,85 @@ int main() {
|
|||||||
};
|
};
|
||||||
wizchip_setnetinfo(&netinfo);
|
wizchip_setnetinfo(&netinfo);
|
||||||
rgb_rainbow();
|
rgb_rainbow();
|
||||||
if (!w5500_rp_dhcp()) {
|
w5500_rp_dhcp();
|
||||||
display.fillScreen(SSD1306_BLACK);
|
|
||||||
display.setCursor(64-24, 32-8);
|
|
||||||
display.print("fail");
|
|
||||||
display.display();
|
|
||||||
sleep_ms(1000);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
rgb_rainbow();
|
rgb_rainbow();
|
||||||
|
|
||||||
|
absolute_time_t time_read_temp = make_timeout_time_ms(0);
|
||||||
|
absolute_time_t time_read_ip = make_timeout_time_ms(10);
|
||||||
|
absolute_time_t time_update_display = make_timeout_time_ms(20);
|
||||||
|
absolute_time_t time_second = make_timeout_time_ms(0);
|
||||||
|
|
||||||
|
char cj_str[8] = {0, };
|
||||||
|
char tc_str[8] = {0, };
|
||||||
|
char ip[16] = {0, };
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
char cj_str[8];
|
int64_t time = INT64_MIN;
|
||||||
char tc_str[8];
|
int64_t time_max = INT64_MIN;
|
||||||
char ip[16];
|
|
||||||
|
|
||||||
spi_set_format(SPI_MAX31856, SPI_MAX31856_BLOCK_SIZE, SPI_MAX31856_SPO, SPI_MAX31856_SPH, SPI_MAX31856_BIT_ORDER);
|
time = absolute_time_diff_us(time_read_temp, get_absolute_time());
|
||||||
sleep_ms(5);
|
time_max = MAX(time, time_max);
|
||||||
max31856_temp_t cj = max31856_get_cj_temp_c(&temp[0]);
|
if (time >= 0) {
|
||||||
snprintf(&cj_str[0], 8, "%i.%02uC", cj.i, cj.f);
|
time_read_temp = delayed_by_ms(time_read_temp, 300);
|
||||||
max31856_temp_t tc = max31856_get_tc_temp_c(&temp[0]);
|
spi_set_format(SPI_MAX31856, SPI_MAX31856_BLOCK_SIZE, SPI_MAX31856_SPO, SPI_MAX31856_SPH, SPI_MAX31856_BIT_ORDER);
|
||||||
snprintf(&tc_str[0], 8, "%i.%02uC", tc.i, tc.f);
|
max31856_temp_t cj = max31856_get_cj_temp_c(&temp[0]);
|
||||||
|
snprintf(&cj_str[0], 8, "%i.%02uC", cj.i, cj.f);
|
||||||
|
max31856_temp_t tc = max31856_get_tc_temp_c(&temp[0]);
|
||||||
|
snprintf(&tc_str[0], 8, "%i.%02uC", tc.i, tc.f);
|
||||||
|
|
||||||
netinfo = {
|
// printf("CJ temp: %s\n", &cj_str[0]);
|
||||||
.mac={255, 255, 255, 255, 255, 255},
|
// printf("TC temp: %s\n", &tc_str[0]);
|
||||||
.ip={255, 255, 255, 255},
|
}
|
||||||
.sn={255, 255, 255, 255}, // subnet mask
|
|
||||||
.gw={255, 255, 255, 255},
|
|
||||||
.dns={255, 255, 255, 255},
|
|
||||||
.dhcp=NETINFO_STATIC
|
|
||||||
};
|
|
||||||
wizchip_getnetinfo(&netinfo);
|
|
||||||
w5500_rp_print_netinfo(netinfo);
|
|
||||||
snprintf(&ip[0], 16, "%u.%u.%u.%u", netinfo.ip[0], netinfo.ip[1], netinfo.ip[2], netinfo.ip[3]);
|
|
||||||
|
|
||||||
// printf("CJ temp: %s\n", &cj_str[0]);
|
time = absolute_time_diff_us(time_read_temp, get_absolute_time());
|
||||||
// printf("TC temp: %s\n", &tc_str[0]);
|
time_max = MAX(time, time_max);
|
||||||
|
if (time >= 0) {
|
||||||
|
time_read_temp = delayed_by_ms(time_read_temp, 300);
|
||||||
|
netinfo = {
|
||||||
|
.mac={255, 255, 255, 255, 255, 255},
|
||||||
|
.ip={255, 255, 255, 255},
|
||||||
|
.sn={255, 255, 255, 255}, // subnet mask
|
||||||
|
.gw={255, 255, 255, 255},
|
||||||
|
.dns={255, 255, 255, 255},
|
||||||
|
.dhcp=NETINFO_STATIC
|
||||||
|
};
|
||||||
|
wizchip_getnetinfo(&netinfo);
|
||||||
|
// w5500_rp_print_netinfo(netinfo);
|
||||||
|
snprintf(&ip[0], 16, "%u.%u.%u.%u", netinfo.ip[0], netinfo.ip[1], netinfo.ip[2], netinfo.ip[3]);
|
||||||
|
}
|
||||||
|
|
||||||
spi_set_format(spi0, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
|
time = absolute_time_diff_us(time_update_display, get_absolute_time());
|
||||||
sleep_ms(5);
|
time_max = MAX(time, time_max);
|
||||||
display.fillScreen(SSD1306_BLACK);
|
if (time >= 0) {
|
||||||
display.setCursor(0, 0);
|
time_update_display = delayed_by_ms(time_update_display, 300);
|
||||||
display.setTextSize(1);
|
spi_set_format(spi0, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
|
||||||
display.println(&ip[0]);
|
display.fillScreen(SSD1306_BLACK);
|
||||||
display.setTextSize(2);
|
display.setCursor(0, 0);
|
||||||
display.print("CJ ");
|
display.setTextSize(1);
|
||||||
display.println(&cj_str[0]);
|
display.println(&ip[0]);
|
||||||
display.print("TC ");
|
display.setTextSize(2);
|
||||||
display.println(&tc_str[0]);
|
display.print("CJ ");
|
||||||
display.display();
|
display.println(&cj_str[0]);
|
||||||
|
display.print("TC ");
|
||||||
|
display.println(&tc_str[0]);
|
||||||
|
display.display();
|
||||||
|
}
|
||||||
|
|
||||||
sleep_ms(200);
|
DHCP_run();
|
||||||
|
time = absolute_time_diff_us(time_second, get_absolute_time());
|
||||||
|
time_max = MAX(time, time_max);
|
||||||
|
if (time >= 0) {
|
||||||
|
time_second = delayed_by_ms(time_second, 1000);
|
||||||
|
DHCP_time_handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (time_max < -1000) {
|
||||||
|
sleep_us(-time_max);
|
||||||
|
} else if (time_max > 100) {
|
||||||
|
printf("%llius\n", time_max);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ void w5500_rp_spi_read_burst(uint8_t *buffer, uint16_t size) {
|
|||||||
void w5500_rp_spi_cs_select() {
|
void w5500_rp_spi_cs_select() {
|
||||||
spi_set_format(W5500_SPI_DRIVER, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
|
spi_set_format(W5500_SPI_DRIVER, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
|
||||||
gpio_put(PIN_W5500_CS, 0);
|
gpio_put(PIN_W5500_CS, 0);
|
||||||
printf("pling\n");
|
|
||||||
}
|
}
|
||||||
void w5500_rp_spi_cs_deselect() {
|
void w5500_rp_spi_cs_deselect() {
|
||||||
gpio_put(PIN_W5500_CS, 1);
|
gpio_put(PIN_W5500_CS, 1);
|
||||||
@@ -62,24 +61,7 @@ void w5500_rp_dhcp_assigned() {
|
|||||||
dhcp_assigned = true;
|
dhcp_assigned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool w5500_rp_dhcp() {
|
void w5500_rp_dhcp() {
|
||||||
DHCP_init(1, &dhcp_buffer[0]);
|
DHCP_init(1, &dhcp_buffer[0]);
|
||||||
reg_dhcp_cbfunc(NULL, NULL, NULL);
|
reg_dhcp_cbfunc(NULL, NULL, NULL);
|
||||||
|
|
||||||
uint64_t second_time = time_us_64() + 1E6;
|
|
||||||
uint8_t seconds = 0;
|
|
||||||
while (DHCP_run() != DHCP_IP_LEASED) {
|
|
||||||
if (second_time > time_us_64()) {
|
|
||||||
second_time += 1E6;
|
|
||||||
DHCP_time_handler();
|
|
||||||
seconds++;
|
|
||||||
if (seconds > 60) {
|
|
||||||
DHCP_stop();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sleep_ms(100);
|
|
||||||
}
|
|
||||||
DHCP_stop();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,6 @@
|
|||||||
|
|
||||||
void w5500_rp_init();
|
void w5500_rp_init();
|
||||||
void w5500_rp_print_netinfo(wiz_NetInfo netinfo);
|
void w5500_rp_print_netinfo(wiz_NetInfo netinfo);
|
||||||
bool w5500_rp_dhcp();
|
void w5500_rp_dhcp();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user