Loading...
Loading...
Compare original and translation side by side
#include "esp_log.h"
#include <string.h>
static const char* TAG = "SerialCmd";
void serial_command_task(void* arg) {
char buf[64];
int idx = 0;
while (1) {
int c = getchar();
if (c == EOF) {
vTaskDelay(pdMS_TO_TICKS(10));
continue;
}
if (c == '\n' || c == '\r') {
buf[idx] = '\0';
if (idx > 0) {
ESP_LOGI(TAG, "Command: %s", buf);
if (strcmp(buf, "PRESS") == 0) {
button_callback();
} else if (strncmp(buf, "SCREEN:", 7) == 0) {
int screen = atoi(buf + 7);
go_to_screen(screen);
}
}
idx = 0;
} else if (idx < sizeof(buf) - 1) {
buf[idx++] = c;
}
}
}
// In app_main():
// xTaskCreate(serial_command_task, "serial_cmd", 2048, NULL, 5, NULL);#include "esp_log.h"
#include <string.h>
static const char* TAG = "SerialCmd";
void serial_command_task(void* arg) {
char buf[64];
int idx = 0;
while (1) {
int c = getchar();
if (c == EOF) {
vTaskDelay(pdMS_TO_TICKS(10));
continue;
}
if (c == '\n' || c == '\r') {
buf[idx] = '\0';
if (idx > 0) {
ESP_LOGI(TAG, "Command: %s", buf);
if (strcmp(buf, "PRESS") == 0) {
button_callback();
} else if (strncmp(buf, "SCREEN:", 7) == 0) {
int screen = atoi(buf + 7);
go_to_screen(screen);
}
}
idx = 0;
} else if (idx < sizeof(buf) - 1) {
buf[idx++] = c;
}
}
}
// In app_main():
// xTaskCreate(serial_command_task, "serial_cmd", 2048, NULL, 5, NULL);void setup() {
Serial.begin(115200);
}
void loop() {
if (Serial.available()) {
String cmd = Serial.readStringUntil('\n');
cmd.trim();
Serial.printf("Command: %s\n", cmd.c_str());
if (cmd == "PRESS") {
button_callback();
} else if (cmd.startsWith("SCREEN:")) {
int screen = cmd.substring(7).toInt();
go_to_screen(screen);
} else if (cmd == "STATUS") {
Serial.println("OK");
}
}
}void setup() {
Serial.begin(115200);
}
void loop() {
if (Serial.available()) {
String cmd = Serial.readStringUntil('\n');
cmd.trim();
Serial.printf("Command: %s\n", cmd.c_str());
if (cmd == "PRESS") {
button_callback();
} else if (cmd.startsWith("SCREEN:")) {
int screen = cmd.substring(7).toInt();
go_to_screen(screen);
} else if (cmd == "STATUS") {
Serial.println("OK");
}
}
}undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedPORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* 2>/dev/null | head -1)
for i in {1..100}; do
echo "PRESS" > "$PORT"
echo "Sent press $i"
sleep 2
donePORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* 2>/dev/null | head -1)
for i in {1..100}; do
echo "PRESS" > "$PORT"
echo "已发送第$i次按压命令"
sleep 2
donePORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* 2>/dev/null | head -1)
END=$(($(date +%s) + 3600)) # 1 hour
count=0
while [ $(date +%s) -lt $END ]; do
count=$((count + 1))
echo "PRESS" > "$PORT"
echo "[$(date +%H:%M:%S)] Press $count"
sleep 30
done
echo "Total: $count presses"PORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* 2>/dev/null | head -1)
END=$(($(date +%s) + 3600)) # 1小时
count=0
while [ $(date +%s) -lt $END ]; do
count=$((count + 1))
echo "PRESS" > "$PORT"
echo "[$(date +%H:%M:%S)] 第$count次按压"
sleep 30
done
echo "总计: $count次按压"tail -f /tmp/device.logPORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* 2>/dev/null | head -1)
echo "PRESS" > "$PORT"tail -f /tmp/device.logPORT=$(ls /dev/cu.usbmodem* /dev/ttyUSB* 2>/dev/null | head -1)
echo "PRESS" > "$PORT"