software update

main
lincaigui 6 months ago
commit 9384473312

@ -0,0 +1,131 @@
//
module key_filter #(parameter KEY_W = 4,DELAY = 1000_000)(//20ms
input sys_clk ,
input sys_rst_n ,
input [KEY_W-1:0] key_in ,
output reg [KEY_W-1:0] key_out
);
//
localparam IDLE = 4'b0001,//
DOWN = 4'b0010,//沿
HOLD = 4'b0100,//
UP = 4'b1000;//沿
//
reg [19:0] cnt ;//20ms
wire add_cnt ;
wire end_cnt ;
reg [3:0] state_c ;//
reg [3:0] state_n ;//
reg [KEY_W-1:0] key_r0 ;//
reg [KEY_W-1:0] key_r1 ;
reg [KEY_W-1:0] key_r2 ;
wire [KEY_W-1:0] nedge ;//沿
wire [KEY_W-1:0] pedge ;//沿
wire idle2down;//
wire down2idle;
wire down2hold;
wire hold2up ;
wire up2idle ;
//
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
state_c <= IDLE;
end
else begin
state_c <= state_n;
end
end
always @(*)begin
case (state_c)
IDLE :begin
if(idle2down)
state_n = DOWN;
else
state_n = state_c;
end
DOWN :begin
if(down2idle)
state_n = IDLE;
else if(down2hold)
state_n = HOLD;
else
state_n = state_c;
end
HOLD :begin
if(hold2up)
state_n = UP;
else
state_n = state_c;
end
UP :begin
if(up2idle)
state_n = IDLE;
else
state_n = state_c;
end
default:state_n = IDLE;
endcase
end
assign idle2down = state_c == IDLE && (nedge );//(nedge != 0)
assign down2idle = state_c == DOWN && (pedge );//(pedge != 0)
assign down2hold = state_c == DOWN && (end_cnt);// && pedge == 0;
assign hold2up = state_c == HOLD && (pedge );//(pedge != 0)
assign up2idle = state_c == UP && (end_cnt);
//
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt <= 0;
end
else if(add_cnt)begin
if(end_cnt)begin
cnt <= 0;
end
else begin
cnt <= cnt + 1;
end
end
end
assign add_cnt = (state_c == DOWN) || (state_c == UP);
assign end_cnt = add_cnt && (cnt == DELAY-1 || down2idle);
//
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
key_r0 <= {KEY_W{1'b1}};
key_r1 <= {KEY_W{1'b1}};
key_r2 <= {KEY_W{1'b1}};
end
else begin
key_r0 <= key_in; //
key_r1 <= key_r0; //
key_r2 <= key_r1;
end
end
//r1r2
assign nedge = ~key_r1 & key_r2;/*(~key_r1[0] & key_r2[0]) || (~key_r1[1] & key_r2[1]);*///
assign pedge = key_r1 & ~key_r2;/*(key_r1[0] & ~key_r2[0]) || (key_r1[1] & ~key_r2[1]);*/
//key_down
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
key_out <= 0;
end
else if(down2hold)begin
key_out <= ~key_r1; //~key_r2
//key_down <= down2hold?~key_r1:0;
end
else begin
key_out <= 0;
end
end
endmodule

@ -0,0 +1,16 @@
`define SYS_FRQ 50_000_000
`define BAUD_115200
//9600192003840057600115200
`ifdef BAUD_9600
`define MAX 9600
`elsif BAUD_19200
`define MAX 19200
`elsif BAUD_38400
`define MAX 38400
`elsif BAUD_57600
`define MAX 57600
`elsif BAUD_115200
`define MAX 115200
`else
`define MAX 115200
`endif

@ -0,0 +1,108 @@
`include "param.v"
module uart_rx(
input wire sys_clk ,
input wire sys_rst_n ,
input wire rx_din ,//
input wire rcv_start ,
output wire [7: 0] rx_dout ,//
output wire rx_vld //
);
parameter BAUD = `SYS_FRQ / `MAX;//1bit
reg din_reg0;//
reg din_reg1;//沿
wire nedge;//沿
reg rx_flag;//
//bit
reg [3: 0] cnt_bit ;
wire add_cnt_bit;
wire end_cnt_bit;
//
reg [12: 0] cnt_bps ;
wire add_cnt_bps ;
wire end_cnt_bps ;
//
reg [7: 0] data_reg;
always @(posedge sys_clk or negedge sys_rst_n) begin
if(!sys_rst_n)begin
din_reg0 <= 1'b1;
din_reg1 <= 1'b1;
end
else begin
din_reg0 <= rx_din;
din_reg1 <= din_reg0;
end
end
assign nedge = ~din_reg0 && din_reg1;//沿
//rx_flag
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
rx_flag <= 1'b0;
end
else if(nedge && rcv_start)begin//沿
rx_flag <= 1'b1;
end
else if(end_cnt_bit)begin//
rx_flag <= 1'b0;
end
else begin
rx_flag <= rx_flag;//
end
end
//cnt_bps
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_bps <= 13'd0;
end
else if(add_cnt_bps)begin
if(end_cnt_bps)begin
cnt_bps <= 13'd0;
end
else begin
cnt_bps <= cnt_bps + 1'd1;
end
end
else begin
cnt_bps <= cnt_bps;
end
end
assign add_cnt_bps = rx_flag;
assign end_cnt_bps = add_cnt_bps && cnt_bps == BAUD - 1'd1;
//cnt_bit
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_bit <= 4'd0;
end
else if(add_cnt_bit)begin
if(end_cnt_bit)begin
cnt_bit <= 4'd0;
end
else begin
cnt_bit <= cnt_bit + 1'd1;
end
end
else begin
cnt_bit <= cnt_bit;
end
end
assign add_cnt_bit = end_cnt_bps;//
assign end_cnt_bit = add_cnt_bit && cnt_bit == 4'd8;//0-8
//data_reg
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
data_reg <= 8'hx;
end
else if((cnt_bit >= 4'd1 && cnt_bit <= 4'd8) && (cnt_bps == BAUD >> 1))begin
data_reg[cnt_bit - 1'd1] = din_reg0;//
end
else begin
data_reg <= data_reg;
end
end
assign rx_dout = data_reg;//
assign rx_vld = end_cnt_bit;//
endmodule

@ -0,0 +1,45 @@
module uart_top(
input wire sys_clk ,
input wire sys_rst_n ,
input wire rx ,
input wire [3: 0] key_in ,
output wire tx
);
wire [7: 0] data_byte ;
wire [7: 0] data_out ;
wire [3: 0] key_out ;
wire tx_vld ;
wire rx_vld ;
reg rcv_start ;
// uart_rx uart_rx_inst(
// .sys_clk (sys_clk) ,
// .sys_rst_n (sys_rst_n) ,
// .rx_din (rx) ,//
// .rcv_start (rcv_start) ,
// .rx_dout (data_byte) ,//
// .rx_vld (rx_vld) //
// );
key_filter key_filter_inst(//20ms
.sys_clk (sys_clk),
.sys_rst_n (sys_rst_n),
.key_in (key_in),
.key_out (key_out)
);
assign rx_vld = |key_out;//0001 0010 0100 1000
assign data_out = {4'b0000, key_out};//,0x01=0000_0010
uart_tx uart_tx_inst(
.sys_clk (sys_clk) ,
.sys_rst_n (sys_rst_n) ,
.tx_din (data_out) ,//
.rx_vld (rx_vld) ,//
.tx_vld (tx_vld) ,
.tx_dout (tx)//
);
endmodule

@ -0,0 +1,46 @@
module uart_top(
input wire sys_clk ,
input wire sys_rst_n ,
input wire rx ,
input wire [3: 0] key_in ,
output wire tx ,
output wire led_ready
);
wire [7: 0] data_byte ;
wire [7: 0] data_out ;
wire [3: 0] key_out ;
wire tx_vld ;
wire rx_vld ;
reg rcv_start ;
// uart_rx uart_rx_inst(
// .sys_clk (sys_clk) ,
// .sys_rst_n (sys_rst_n) ,
// .rx_din (rx) ,//
// .rcv_start (rcv_start) ,
// .rx_dout (data_byte) ,//
// .rx_vld (rx_vld) //
// );
key_filter key_filter_inst(//20ms
.sys_clk (sys_clk),
.sys_rst_n (sys_rst_n),
.key_in (key_in),
.key_out (key_out)
);
assign rx_vld = |key_out;
assign data_out = {4'b0000, key_out};
uart_tx uart_tx_inst(
.sys_clk (sys_clk) ,
.sys_rst_n (sys_rst_n) ,
.tx_din (data_out) ,//
.rx_vld (rx_vld) ,//
.tx_vld (tx_vld) ,
.tx_dout (tx)//
);
endmodule

@ -0,0 +1,104 @@
`include "param.v"
module uart_tx(
input wire sys_clk ,
input wire sys_rst_n ,
input wire [7: 0] tx_din ,//
input wire rx_vld ,//
output wire tx_vld ,
output reg tx_dout //
);
parameter BAUD = `SYS_FRQ / `MAX;//
reg [8: 0] data_reg;//
reg tx_flag ;//
//
reg [12: 0] cnt_bps;
wire add_cnt_bps;
wire end_cnt_bps;
//
reg [3: 0] cnt_bit;
wire add_cnt_bit;
wire end_cnt_bit;
//
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
data_reg <= 9'hx;
end
else if(rx_vld)begin
data_reg <= {tx_din, 1'b0};//
end
else begin
data_reg <= data_reg;
end
end
//tx_flag
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
tx_flag <= 1'b0;
end
else if(rx_vld)begin
tx_flag <= 1'b1;
end
else if(end_cnt_bit)begin
tx_flag <= 1'b0;
end
else begin
tx_flag <= tx_flag;
end
end
//cnt_bps
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_bps <= 13'd0;
end
else if(add_cnt_bps)begin
if(end_cnt_bps)begin
cnt_bps <= 13'd0;
end
else begin
cnt_bps <= cnt_bps + 1'd1;
end
end
else begin
cnt_bps <= cnt_bps;
end
end
assign add_cnt_bps = tx_flag;
assign end_cnt_bps = add_cnt_bps && cnt_bps == BAUD - 1'd1;
//cnt_bit
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_bit <= 4'd0;
end
else if(add_cnt_bit)begin
if(end_cnt_bit)begin
cnt_bit <= 4'd0;
end
else begin
cnt_bit <= cnt_bit + 1'd1;
end
end
else begin
cnt_bit <= cnt_bit;
end
end
assign add_cnt_bit = end_cnt_bps;//
assign end_cnt_bit = add_cnt_bit && cnt_bit == 4'd8;
//tx_dout
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
tx_dout <= 1'b1;
end
else if(tx_flag)begin
tx_dout <= data_reg[cnt_bit];//
end
else begin
tx_dout <= 1'b1;
end
end
assign tx_vld = end_cnt_bit;
endmodule

@ -0,0 +1,27 @@
# Copyright (C) 2018 Intel Corporation. All rights reserved.
# Your use of Intel Corporation's design tools, logic functions
# and other software and tools, and its AMPP partner logic
# functions, and any output files from any of the foregoing
# (including device programming or simulation files), and any
# associated documentation or information are expressly subject
# to the terms and conditions of the Intel Program License
# Subscription Agreement, the Intel Quartus Prime License Agreement,
# the Intel FPGA IP License Agreement, or other applicable license
# agreement, including, without limitation, that your use is for
# the sole purpose of programming logic devices manufactured by
# Intel and sold by Intel or its authorized distributors. Please
# refer to the applicable agreement for further details.
# Quartus Prime Version 18.1.0 Build 625 09/12/2018 SJ Standard Edition
# File: C:\Users\Stark-lin\Desktop\uart_tiktok\hardware\tcl\uart_tiktok.tcl
# Generated on: Fri May 17 17:40:01 2024
package require ::quartus::project
set_location_assignment PIN_E1 -to sys_clk
set_location_assignment PIN_E15 -to sys_rst_n
set_location_assignment PIN_E16 -to key_in[0]
set_location_assignment PIN_M15 -to key_in[1]
set_location_assignment PIN_M16 -to key_in[2]
set_location_assignment PIN_F8 -to key_in[3]
set_location_assignment PIN_G1 -to tx

@ -0,0 +1,3 @@
# 串口抖音
## 1.按键数据通过串口发送给上位机控制抖音
## 2.软件升级,可以检测任意端口号

@ -0,0 +1,33 @@
module software
go 1.22.3
require (
github.com/StackExchange/wmi v1.2.1
github.com/go-vgo/robotgo v0.110.1
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
)
require (
github.com/gen2brain/shm v0.0.0-20230802011745-f2460f5984f7 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/jezek/xgb v1.1.0 // indirect
github.com/kbinani/screenshot v0.0.0-20230812210009-b87d31814237 // indirect
github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a // indirect
github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect
github.com/otiai10/gosseract v2.2.1+incompatible // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/robotn/xgb v0.0.0-20190912153532-2cb92d044934 // indirect
github.com/robotn/xgbutil v0.0.0-20190912154524-c861d6f87770 // indirect
github.com/shirou/gopsutil/v3 v3.23.8 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/vcaesar/gops v0.30.2 // indirect
github.com/vcaesar/imgo v0.40.0 // indirect
github.com/vcaesar/keycode v0.10.1 // indirect
github.com/vcaesar/tt v0.20.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
golang.org/x/image v0.12.0 // indirect
golang.org/x/sys v0.12.0 // indirect
)

@ -0,0 +1,116 @@
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966/go.mod h1:Mid70uvE93zn9wgF92A/r5ixgnvX8Lh68fxp9KQBaI0=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gen2brain/shm v0.0.0-20230802011745-f2460f5984f7 h1:VLEKvjGJYAMCXw0/32r9io61tEXnMWDRxMk+peyRVFc=
github.com/gen2brain/shm v0.0.0-20230802011745-f2460f5984f7/go.mod h1:uF6rMu/1nvu+5DpiRLwusA6xB8zlkNoGzKn8lmYONUo=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
github.com/go-vgo/robotgo v0.110.1 h1:2etpOzsBBt9KJOxDBFBVYzE4/U7gRrsnB9dxuujRMTw=
github.com/go-vgo/robotgo v0.110.1/go.mod h1:DdJUdi6mEU8ttHMbow6hKD1TjgsfgJC/H+4dusok8Uw=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk=
github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/kbinani/screenshot v0.0.0-20230812210009-b87d31814237 h1:YOp8St+CM/AQ9Vp4XYm4272E77MptJDHkwypQHIRl9Q=
github.com/kbinani/screenshot v0.0.0-20230812210009-b87d31814237/go.mod h1:e7qQlOY68wOz4b82D7n+DdaptZAi+SHW0+yKiWZzEYE=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a h1:N9zuLhTvBSRt0gWSiJswwQ2HqDmtX/ZCDJURnKUt1Ik=
github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE=
github.com/lxn/win v0.0.0-20210218163916-a377121e959e h1:H+t6A/QJMbhCSEH5rAuRxh+CtW96g0Or0Fxa9IKr4uc=
github.com/lxn/win v0.0.0-20210218163916-a377121e959e/go.mod h1:KxxjdtRkfNoYDCUP5ryK7XJJNTnpC8atvtmTheChOtk=
github.com/otiai10/gosseract v2.2.1+incompatible h1:Ry5ltVdpdp4LAa2bMjsSJH34XHVOV7XMi41HtzL8X2I=
github.com/otiai10/gosseract v2.2.1+incompatible/go.mod h1:XrzWItCzCpFRZ35n3YtVTgq5bLAhFIkascoRo8G32QE=
github.com/otiai10/mint v1.3.0 h1:Ady6MKVezQwHBkGzLFbrsywyp09Ah7rkmfjV3Bcr5uc=
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b h1:0LFwY6Q3gMACTjAbMZBjXAqTOzOwFaj2Ld6cjeQ7Rig=
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/robotn/xgb v0.0.0-20190912153532-2cb92d044934 h1:2lhSR8N3T6I30q096DT7/5AKEIcf1vvnnWAmS0wfnNY=
github.com/robotn/xgb v0.0.0-20190912153532-2cb92d044934/go.mod h1:SxQhJskUJ4rleVU44YvnrdvxQr0tKy5SRSigBrCgyyQ=
github.com/robotn/xgbutil v0.0.0-20190912154524-c861d6f87770 h1:2uX8QRLkkxn2EpAQ6I3KhA79BkdRZfvugJUzJadiJwk=
github.com/robotn/xgbutil v0.0.0-20190912154524-c861d6f87770/go.mod h1:svkDXUDQjUiWzLrA0OZgHc4lbOts3C+uRfP6/yjwYnU=
github.com/shirou/gopsutil/v3 v3.23.8 h1:xnATPiybo6GgdRoC4YoGnxXZFRc3dqQTGi73oLvvBrE=
github.com/shirou/gopsutil/v3 v3.23.8/go.mod h1:7hmCaBn+2ZwaZOr6jmPBZDfawwMGuo1id3C6aM8EDqQ=
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
github.com/vcaesar/gops v0.30.2 h1:fANyUGCjLkfcYmJRVnXv+QZhT8cL2e0GWpRFZe58p/4=
github.com/vcaesar/gops v0.30.2/go.mod h1:2NSA2Q9M1irGnGD9tWdo0Z+MwKjUj4Q4EgUDukN/Vsk=
github.com/vcaesar/imgo v0.40.0 h1:okI1eonRAfGLzjqgTIBkUwhm4j/rH19qGno4eFOBQsc=
github.com/vcaesar/imgo v0.40.0/go.mod h1:E5uI53XkEfbI20VvcIZ/19G2hHidPfH9h4NtQooEY+8=
github.com/vcaesar/keycode v0.10.1 h1:0DesGmMAPWpYTCYddOFiCMKCDKgNnwiQa2QXindVUHw=
github.com/vcaesar/keycode v0.10.1/go.mod h1:JNlY7xbKsh+LAGfY2j4M3znVrGEm5W1R8s/Uv6BJcfQ=
github.com/vcaesar/tt v0.20.0 h1:9t2Ycb9RNHcP0WgQgIaRKJBB+FrRdejuaL6uWIHuoBA=
github.com/vcaesar/tt v0.20.0/go.mod h1:GHPxQYhn+7OgKakRusH7KJ0M5MhywoeLb8Fcffs/Gtg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/image v0.12.0 h1:w13vZbU4o5rKOFFR8y7M+c4A5jXDC0uXTdHYRP8X2DQ=
golang.org/x/image v0.12.0/go.mod h1:Lu90jvHG7GfemOIcldsh9A2hS01ocl6oNO7ype5mEnk=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

@ -0,0 +1,79 @@
package main
import (
"fmt"
"log"
"regexp"
"time"
"github.com/StackExchange/wmi"
"github.com/go-vgo/robotgo"
"github.com/tarm/serial"
)
type Win32_PnPEntity struct {
Name string
}
func check() string {
var devices []Win32_PnPEntity
query := `SELECT Name FROM Win32_PnPEntity WHERE Name LIKE '%(COM%'`
err := wmi.Query(query, &devices)
if err != nil {
panic(fmt.Sprintf("Failed to query WMI: %v", err))
}
re := regexp.MustCompile(`COM\d+`)
dev := re.FindString(devices[0].Name)
return dev //获取串口名字
}
func main() {
// 串口配置
com := check() //获取串口名字com3
config := &serial.Config{
Name: com, // 替换为实际的串口设备路径例如在Windows上可能是"COM1"
Baud: 115200, // 波特率,根据实际需求设置
}
// 打开串口
port, err := serial.OpenPort(config)
if err != nil {
log.Fatal(err)
}
defer port.Close()
buffer := make([]byte, 128) // 缓冲区大小根据你的数据包大小调整
for {
//如果有数据就读,没有就阻塞
n, err := port.Read(buffer) //n多少Byte
if err != nil {
log.Printf("读取错误: %v\n", err)
continue
}
if n > 0 {
// 这里可以添加处理数据的逻辑
if buffer[0] == 0x01 {
robotgo.KeyPress("up")
} else if buffer[0] == 0x02 {
robotgo.KeyPress("down")
} else if buffer[0] == 0x04 {
robotgo.KeyPress("f")
} else if buffer[0] == 0x08 {
robotgo.KeyPress("z")
} else {
log.Printf("读取到 %d 字节数据: %d\n", n, buffer[:n])
}
} else {
// 当没有读取到数据时,可以根据需要处理或简单跳过
log.Println("没有新数据")
}
// 可以根据需要添加适当的延迟避免无数据时CPU占用过高
time.Sleep(10 * time.Millisecond)
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -0,0 +1,60 @@
{
"RT_GROUP_ICON": {
"APP": {
"0000": [
"home-logo.png"
]
}
},
"RT_MANIFEST": {
"#1": {
"0409": {
"identity": {
"name": "",
"version": ""
},
"description": "",
"minimum-os": "win7",
"execution-level": "as invoker",
"ui-access": false,
"auto-elevate": false,
"dpi-awareness": "system",
"disable-theming": false,
"disable-window-filtering": false,
"high-resolution-scrolling-aware": false,
"ultra-high-resolution-scrolling-aware": false,
"long-path-aware": false,
"printer-driver-isolation": false,
"gdi-scaling": false,
"segment-heap": false,
"use-common-controls-v6": false
}
}
},
"RT_VERSION": {
"#1": {
"0000": {
"fixed": {
"file_version": "0.0.0.0",
"product_version": "0.0.0.0"
},
"info": {
"0409": {
"Comments": "",
"CompanyName": "",
"FileDescription": "",
"FileVersion": "",
"InternalName": "",
"LegalCopyright": "",
"LegalTrademarks": "",
"OriginalFilename": "",
"PrivateBuild": "",
"ProductName": "",
"ProductVersion": "",
"SpecialBuild": ""
}
}
}
}
}
}
Loading…
Cancel
Save