From c8b776c0876aa39f7dbcce92c97cc3bf3bfc0bc8 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Sun, 14 Jan 2018 15:25:13 +0800 Subject: [PATCH] Add connection type to menu core. --- charrom.h | 4 ++-- debug.h | 2 +- menu.c | 41 +++++++++++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/charrom.h b/charrom.h index 2ce7b9d..53c7508 100644 --- a/charrom.h +++ b/charrom.h @@ -68,8 +68,8 @@ unsigned char charfont[128][8] = { 0x3e,0x3e,0x22,0x22,0x22,0x3e,0x3e,0x00 }, // 25 [0x19] unchecked checkbox { 0x3e,0x3e,0x3e,0x3e,0x3e,0x3e,0x3e,0x00 }, // 26 [0x1a] checked checkbox { 0x00,0x00,0x00,0x0c,0x0c,0x00,0x00,0x00 }, // 27 [0x1b] middle dot - { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, // 28 [0x1c] - { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, // 29 [0x1d] + { 0x68,0x78,0x6b,0x0f,0x6b,0x78,0x68,0x00 }, // 28 [0x1c] ethernet + { 0x02,0x09,0x25,0x95,0x95,0x25,0x09,0x02 }, // 29 [0x1d] wifi { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, // 30 [0x1e] { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, // 31 [0x1f] { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, // 32 [0x20] diff --git a/debug.h b/debug.h index 78b8d76..c65516a 100644 --- a/debug.h +++ b/debug.h @@ -44,7 +44,7 @@ #if 1 // ikbd debug output in red #define IKBD_DEBUG -#define ikbd_debugf(a, ...) printf("\033[1;31mIKBD: " a "\033[0m\n", ##__VA_ARGS__) +#define ikbd_debugf(a, ...) printf("\033[1;32mIKBD: " a "\033[0m\n", ##__VA_ARGS__) #else #define ikbd_debugf(...) #endif diff --git a/menu.c b/menu.c index 6be28b8..fc12d42 100644 --- a/menu.c +++ b/menu.c @@ -478,9 +478,10 @@ static uint32_t menu_key_get(void) return(c); } -char* getIP() +static char netType; +char* getNet() { - struct ifaddrs *ifaddr, *ifa; + struct ifaddrs *ifaddr, *ifa, *ifae = 0, *ifaw = 0; int family, s; static char host[NI_MAXHOST]; @@ -494,17 +495,32 @@ char* getIP() { if (ifa->ifa_addr == NULL) continue; - s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); + if ((strcmp(ifa->ifa_name, "eth0") == 0) && (ifa->ifa_addr->sa_family == AF_INET)) ifae = ifa; + if ((strncmp(ifa->ifa_name, "wlan", 4) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) ifaw = ifa; + } - if ((strcmp(ifa->ifa_name, "eth0") == 0) && (ifa->ifa_addr->sa_family == AF_INET)) - { - freeifaddrs(ifaddr); - return host; - } + ifa = 0; + netType = 0; + if (ifaw) + { + ifa = ifaw; + netType = 2; + } + + if (ifae) + { + ifa = ifae; + netType = 1; + } + + if (ifa) + { + strcpy(host, "IP: "); + getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host+strlen(host), NI_MAXHOST-strlen(host), NULL, 0, NI_NUMERICHOST); } freeifaddrs(ifaddr); - return NULL; + return ifa ? host : 0; } void HandleUI(void) @@ -3206,12 +3222,11 @@ void HandleUI(void) rtc_timer = GetTimer(1000); char str[64] = { 0 }; sprintf(str, " MiSTer "); + char *net = getNet(); if (menustate == MENU_STORAGE) { - char *ip = getIP(); - if (ip) sprintf(str + strlen(str), "IP: %s", ip); - else sprintf(str + strlen(str), " No network"); + strcat(str, net ? net : " no network"); } else { @@ -3223,6 +3238,8 @@ void HandleUI(void) } } + if (net) str[9] = 0x1b + netType; + OsdWrite(16, "", 1, 0); OsdWrite(17, str, 1, 0); OsdWrite(18, "", 1, 0);