mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-11 00:22:56 -05:00
fix(sg2002): read VI debug state without shell pipelines
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -216,54 +216,58 @@ void write_res_to_file(uint16_t _width, uint16_t _height)
|
|||||||
*/
|
*/
|
||||||
uint8_t get_vi_state()
|
uint8_t get_vi_state()
|
||||||
{
|
{
|
||||||
char VI_State[10]={0};
|
FILE *fp = fopen("/proc/cvitek/vi_dbg", "r");
|
||||||
char cmd[100] = "cat /proc/cvitek/vi_dbg | grep -A 17 VIDevFPS | awk '{print $3}'";
|
if (fp == NULL) {
|
||||||
uint8_t FPS[2];
|
return 0;
|
||||||
uint8_t VIWHGTLSCnt[4];
|
}
|
||||||
FILE* fp = popen( cmd, "r" );
|
|
||||||
uint8_t ret = 0;
|
|
||||||
|
|
||||||
if (fgets(VI_State, sizeof(VI_State), fp) != NULL){
|
unsigned int dev_fps = 0;
|
||||||
FPS[0] = atoi(VI_State);
|
unsigned int fps = 0;
|
||||||
// debug("VIDevFPS = %d\n", FPS[0]);
|
unsigned int width_gt = 0;
|
||||||
} else {
|
unsigned int width_ls = 0;
|
||||||
pclose(fp);
|
unsigned int height_gt = 0;
|
||||||
return ret; // VI not init;
|
unsigned int height_ls = 0;
|
||||||
|
bool have_dev_fps = false;
|
||||||
|
bool have_fps = false;
|
||||||
|
char line[256];
|
||||||
|
char field[32];
|
||||||
|
unsigned int value;
|
||||||
|
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||||
|
if (sscanf(line, "%31s : %u", field, &value) != 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (strcmp(field, "VIDevFPS") == 0) {
|
||||||
|
dev_fps = value;
|
||||||
|
have_dev_fps = true;
|
||||||
|
} else if (strcmp(field, "VIFPS") == 0) {
|
||||||
|
fps = value;
|
||||||
|
have_fps = true;
|
||||||
|
} else if (strcmp(field, "VICsiCh0WidthGTCnt") == 0) {
|
||||||
|
width_gt = value;
|
||||||
|
} else if (strcmp(field, "VICsiCh0WidthLSCnt") == 0) {
|
||||||
|
width_ls = value;
|
||||||
|
} else if (strcmp(field, "VICsiCh0HeightGTCnt") == 0) {
|
||||||
|
height_gt = value;
|
||||||
|
} else if (strcmp(field, "VICsiCh0HeightLSCnt") == 0) {
|
||||||
|
height_ls = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (fgets(VI_State, sizeof(VI_State), fp) != NULL){
|
fclose(fp);
|
||||||
FPS[1] = atoi(VI_State);
|
|
||||||
// debug("VIFPS = %d\n", FPS[1]);
|
|
||||||
}
|
|
||||||
if (FPS[0] == 0){
|
|
||||||
ret = 2; // HDMI not OK;
|
|
||||||
} else if (FPS[1] == 0){
|
|
||||||
ret = 3; // HDMI OK ; CSI not;
|
|
||||||
} else {
|
|
||||||
ret = 1; // HDMI CSI OK;
|
|
||||||
}
|
|
||||||
if(ret == 3){
|
|
||||||
// Ignore other information
|
|
||||||
uint8_t count = 0;
|
|
||||||
for(count = 0; count < 13; count ++){
|
|
||||||
fgets(VI_State, sizeof(VI_State), fp);
|
|
||||||
}
|
|
||||||
// Check if the resolution might be set incorrectly
|
|
||||||
for(count = 0; count < 4; count ++){
|
|
||||||
if (fgets(VI_State, sizeof(VI_State), fp) != NULL){
|
|
||||||
// debug("VI_State = %s", VI_State);
|
|
||||||
VIWHGTLSCnt[count] = atoi(VI_State);
|
|
||||||
// printf("count = %d, val = %d\n", count, atoi(VI_State));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(VIWHGTLSCnt[0] != 0) ret = 3; // The vi width setting value is too small
|
if (!have_dev_fps || !have_fps) {
|
||||||
else if(VIWHGTLSCnt[1] != 0) ret = 4; // The vi width setting value is too large
|
return 0;
|
||||||
else if(VIWHGTLSCnt[2] != 0) ret = 5; // The vi height setting value is too small
|
}
|
||||||
else if(VIWHGTLSCnt[3] != 0) ret = 6; // The vi height setting value is too large
|
if (dev_fps == 0) {
|
||||||
else ret = 7; // printf("[kvmv] Unexpected situation\n");
|
return 2;
|
||||||
}
|
}
|
||||||
pclose(fp);
|
if (fps != 0) {
|
||||||
return ret;
|
return 1;
|
||||||
|
}
|
||||||
|
if (width_gt != 0) return 3;
|
||||||
|
if (width_ls != 0) return 4;
|
||||||
|
if (height_gt != 0) return 5;
|
||||||
|
if (height_ls != 0) return 6;
|
||||||
|
return 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
int set_hdmi_mode(uint8_t _hdmi_mode)
|
int set_hdmi_mode(uint8_t _hdmi_mode)
|
||||||
|
|||||||
@@ -237,24 +237,24 @@ void kvm_update_usb_state()
|
|||||||
void kvm_update_hdmi_state()
|
void kvm_update_hdmi_state()
|
||||||
{
|
{
|
||||||
static uint8_t check_times = 4;
|
static uint8_t check_times = 4;
|
||||||
FILE *fp;
|
|
||||||
int file_size;
|
|
||||||
uint8_t RW_Data[10];
|
|
||||||
if(++check_times > 5){
|
if(++check_times > 5){
|
||||||
check_times = 0;
|
check_times = 0;
|
||||||
fp = popen("cat /proc/cvitek/vi_dbg | grep VIFPS | awk '{print $3}'", "r");
|
FILE *fp = fopen("/proc/cvitek/vi_dbg", "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
pclose(fp);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fgets((char*)RW_Data, 2, fp);
|
|
||||||
pclose(fp);
|
char line[256];
|
||||||
// printf("[kvmd]HDMI exist? %c\n", RW_Data[0]);
|
char field[32];
|
||||||
if (RW_Data[0] != '0'){
|
unsigned int value;
|
||||||
kvm_sys_state.hdmi_state = 1;
|
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||||
} else {
|
if (sscanf(line, "%31s : %u", field, &value) == 2 &&
|
||||||
kvm_sys_state.hdmi_state = 0;
|
strcmp(field, "VIFPS") == 0) {
|
||||||
|
kvm_sys_state.hdmi_state = value == 0 ? 0 : 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
fclose(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,4 +519,4 @@ int check_watchdog()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else return 0;
|
} else return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user