调整打印速度为50mm/s

This commit is contained in:
Yu Xifeng 2024-08-26 11:22:11 +08:00
parent 8a03a3b16c
commit 73122e5ff1
4 changed files with 140 additions and 20 deletions

View File

@ -14,6 +14,6 @@ set(module_srcs
idf_component_register(SRCS ${srcs} ${module_srcs}
PRIV_REQUIRES spi_flash driver esp_event
PRIV_REQUIRES spi_flash driver esp_event esp_timer
INCLUDE_DIRS "."
INCLUDE_DIRS "module")

View File

@ -20,6 +20,7 @@ static const char *TAG = "main";
#define BLINK_GPIO 4
extern void light_sleep_task(void *args);
extern void Usb_Virtual_serial_port_init(void);
QueueHandle_t User_data_queue;
user_data_t Receive_All_data;
@ -63,18 +64,19 @@ void app_main(void)
button_init();
Printer_Bsp_Init();
Printer_run_init();
// xTaskCreate(light_sleep_task, "light_sleep_task", 4096, NULL, 6, NULL);
while (1) {
if(xQueueReceive(User_data_queue, &Receive_All_data, portMAX_DELAY))
{
uint16_t Spaces = uxQueueSpacesAvailable(User_data_queue);
ESP_LOGI(TAG,"Spaces:%d Type:%d Size:%d",Spaces,Receive_All_data.type,Receive_All_data.size);
if(Receive_All_data.type == USB)
{
input_Print_data(CMD_CUSTON,&Receive_All_data.data[0],Receive_All_data.size);
}
}
// if(xQueueReceive(User_data_queue, &Receive_All_data, portMAX_DELAY))
// {
// uint16_t Spaces = uxQueueSpacesAvailable(User_data_queue);
// ESP_LOGI(TAG,"Spaces:%d Type:%d Size:%d",Spaces,Receive_All_data.type,Receive_All_data.size);
// if(Receive_All_data.type == USB)
// {
// input_Print_data(CMD_CUSTON,&Receive_All_data.data[0],Receive_All_data.size);
// }
// }
// ESP_LOGI(TAG, "LED State:%d",!s_led_state);
vTaskDelay(1000/ portTICK_PERIOD_MS);
}
fflush(stdout);
esp_restart();

View File

@ -99,7 +99,6 @@ void Sys_heap_Init(void)
void Fill_block2Page_Buff(uint16_t SetPosY,uint16_t hight,uint8_t* block_buff)
{
uint32_t Total_height = SetPosY + hight;
memset(&Heat58MM.Heat_Page_buff[0],0xff,TH_ACTUAL_WIDTH*3);
for(int i=SetPosY;i<(SetPosY+hight);i++)
{
memcpy(&Heat58MM.Heat_Page_buff[i*TH_ACTUAL_WIDTH],&block_buff[(i - SetPosY)*TH_ACTUAL_WIDTH],TH_ACTUAL_WIDTH);
@ -210,7 +209,9 @@ void Sys_Key_motion_cb(void *arg, void *data)
switch ((button_event_t)data)
{
case BUTTON_SINGLE_CLICK:
/* code */
memset(&Heat58MM.Heat_Page_buff[0],0x00,TH_ACTUAL_WIDTH*500*8);
Heat58MM.Heat_Write = 200*8;
xEventGroupSetBits(Printer_group,EVENT_Motor_Test);
break;
default:
@ -348,8 +349,11 @@ void Printer_Heat_task(void *pvParameter)
break;
case EVENT_Heat_Begin:
//开始加热
Set_gpio_state(&STB,1);
Set_heat_timer_value(400*1);
if(Heat_Step < 3)
{
Set_gpio_state(&STB,1);
}
Set_heat_timer_value(312);//50mm/s
xEventGroupClearBits(Printer_group,EVENT_Heat_Begin);
break;
@ -374,10 +378,6 @@ void Printer_Heat_task(void *pvParameter)
{
Heat_Step = 0;
}
// STB.state = 0;
// gpio_set_level(STB.pin_num,STB.state);
// ESP_LOGI(TAG,"Heat_END_EVENT");
// Motor_GO(0xff);
xEventGroupSetBits(Printer_group,EVENT_Motor_Test);
xEventGroupClearBits(Printer_group,EVENT_Heat_Done);
break;
@ -413,6 +413,6 @@ void Printer_run_init()
Heat58MM.Heat_block_buff = malloc(TH_ACTUAL_WIDTH*100*8);
memset(&Heat58MM.Heat_Page_buff[0],0x00,TH_ACTUAL_WIDTH*500*8);
memset(&Heat58MM.Heat_block_buff[0],0x00,TH_ACTUAL_WIDTH*100*8);
xTaskCreatePinnedToCore(Printer_Heat_task, "Printer_Heat_task", 1024 * 10, NULL, 20, NULL, 1);//核心1
xTaskCreatePinnedToCore(Printer_Heat_task, "Printer_Heat_task", 1024 * 10, NULL, 28, NULL, 1);//核心1
xTaskCreatePinnedToCore(Printer_Run_task, "Printer_Run_task", 1024 * 100, NULL, 12, NULL, 0);//核心1
}

118
main/module/esp_sleep.c Normal file
View File

@ -0,0 +1,118 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "esp_sleep.h"
#include "esp_log.h"
#include "esp_timer.h"
#include "esp_check.h"
#include "driver/gpio.h"
#define TAG "esp_sleep"
#define BOOT_BUTTON_NUM 0
/* Use boot button as gpio input */
#define GPIO_WAKEUP_NUM BOOT_BUTTON_NUM
/* "Boot" button is active low */
#define GPIO_WAKEUP_LEVEL 0
void example_wait_gpio_inactive(void)
{
printf("Waiting for GPIO%d to go high...\n", GPIO_WAKEUP_NUM);
while (gpio_get_level(GPIO_WAKEUP_NUM) == GPIO_WAKEUP_LEVEL) {
vTaskDelay(pdMS_TO_TICKS(10));
}
}
esp_err_t example_register_gpio_wakeup(void)
{
/* Initialize GPIO */
gpio_config_t config = {
.pin_bit_mask = BIT64(GPIO_WAKEUP_NUM),
.mode = GPIO_MODE_INPUT,
.pull_down_en = false,
.pull_up_en = false,
.intr_type = GPIO_INTR_DISABLE
};
ESP_RETURN_ON_ERROR(gpio_config(&config), TAG, "Initialize GPIO%d failed", GPIO_WAKEUP_NUM);
/* Enable wake up from GPIO */
ESP_RETURN_ON_ERROR(gpio_wakeup_enable(GPIO_WAKEUP_NUM, GPIO_WAKEUP_LEVEL == 0 ? GPIO_INTR_LOW_LEVEL : GPIO_INTR_HIGH_LEVEL),
TAG, "Enable gpio wakeup failed");
ESP_RETURN_ON_ERROR(esp_sleep_enable_gpio_wakeup(), TAG, "Configure gpio as wakeup source failed");
/* Make sure the GPIO is inactive and it won't trigger wakeup immediately */
example_wait_gpio_inactive();
ESP_LOGI(TAG, "gpio wakeup source is ready");
return ESP_OK;
}
void light_sleep_task(void *args)
{
/* Enable wakeup from light sleep by gpio */
example_register_gpio_wakeup();
vTaskDelay(1000/ portTICK_PERIOD_MS);
while (true) {
printf("Entering light sleep\n");
/* To make sure the complete line is printed before entering sleep mode,
* need to wait until UART TX FIFO is empty:
*/
uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
/* Get timestamp before entering sleep */
int64_t t_before_us = esp_timer_get_time();
/* Enter sleep mode */
esp_light_sleep_start();
/* Get timestamp after waking up from sleep */
int64_t t_after_us = esp_timer_get_time();
/* Determine wake up reason */
const char* wakeup_reason;
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_TIMER:
wakeup_reason = "timer";
break;
case ESP_SLEEP_WAKEUP_GPIO:
wakeup_reason = "pin";
break;
case ESP_SLEEP_WAKEUP_UART:
wakeup_reason = "uart";
/* Hang-up for a while to switch and execute the uart task
* Otherwise the chip may fall sleep again before running uart task */
vTaskDelay(1);
break;
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
case ESP_SLEEP_WAKEUP_TOUCHPAD:
wakeup_reason = "touch";
break;
#endif
default:
wakeup_reason = "other";
break;
}
#if CONFIG_NEWLIB_NANO_FORMAT
/* printf in newlib-nano does not support %ll format, causing example test fail */
printf("Returned from light sleep, reason: %s, t=%d ms, slept for %d ms\n",
wakeup_reason, (int) (t_after_us / 1000), (int) ((t_after_us - t_before_us) / 1000));
#else
printf("Returned from light sleep, reason: %s, t=%lld ms, slept for %lld ms\n",
wakeup_reason, t_after_us / 1000, (t_after_us - t_before_us) / 1000);
#endif
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO) {
/* Waiting for the gpio inactive, or the chip will continuously trigger wakeup*/
example_wait_gpio_inactive();
}
}
vTaskDelete(NULL);
}