mirror of
https://github.com/raphnet/gc_n64_usb-v3
synced 2025-01-30 14:50:10 -05:00
Add signature and controller type fetching
This commit is contained in:
parent
ef7a06c304
commit
92aa261e4e
@ -66,7 +66,59 @@ int gcn64lib_getVersion(gcn64_hdl_t hdl, char *dst, int dstmax)
|
||||
|
||||
cmd[0] = RQ_GCN64_GET_VERSION;
|
||||
|
||||
n = gcn64_exchange(hdl, cmd, 1, cmd, sizeof(cmd));
|
||||
if (n<0)
|
||||
return n;
|
||||
|
||||
dst[0] = 0;
|
||||
if (n > 1) {
|
||||
strncpy(dst, (char*)cmd+1, n);
|
||||
}
|
||||
dst[dstmax-1] = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gcn64lib_getControllerType(gcn64_hdl_t hdl, int chn)
|
||||
{
|
||||
unsigned char cmd[32];
|
||||
int n;
|
||||
|
||||
cmd[0] = RQ_GCN64_GET_CONTROLLER_TYPE;
|
||||
cmd[1] = chn;
|
||||
|
||||
n = gcn64_exchange(hdl, cmd, 2, cmd, sizeof(cmd));
|
||||
if (n<0)
|
||||
return n;
|
||||
if (n<3)
|
||||
return -1;
|
||||
|
||||
return cmd[2];
|
||||
}
|
||||
|
||||
const char *gcn64lib_controllerName(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case CTL_TYPE_NONE: return "No controller";
|
||||
case CTL_TYPE_N64: return "N64 Controller";
|
||||
case CTL_TYPE_GC: return "GC Controller";
|
||||
case CTL_TYPE_GCKB: return "GC Keyboard";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
int gcn64lib_getSignature(gcn64_hdl_t hdl, char *dst, int dstmax)
|
||||
{
|
||||
unsigned char cmd[32];
|
||||
int n;
|
||||
|
||||
if (dstmax <= 0)
|
||||
return -1;
|
||||
|
||||
cmd[0] = RQ_GCN64_GET_SIGNATURE;
|
||||
|
||||
n = gcn64_exchange(hdl, cmd, 1, cmd, sizeof(cmd));
|
||||
if (n<0)
|
||||
return n;
|
||||
|
||||
|
@ -3,11 +3,19 @@
|
||||
|
||||
#include "gcn64.h"
|
||||
|
||||
#define CTL_TYPE_NONE 0
|
||||
#define CTL_TYPE_N64 1
|
||||
#define CTL_TYPE_GC 2
|
||||
#define CTL_TYPE_GCKB 3
|
||||
|
||||
int gcn64lib_suspendPolling(gcn64_hdl_t hdl, unsigned char suspend);
|
||||
int gcn64lib_setConfig(gcn64_hdl_t hdl, unsigned char param, unsigned char *data, unsigned char len);
|
||||
int gcn64lib_getConfig(gcn64_hdl_t hdl, unsigned char param, unsigned char *rx, unsigned char rx_max);
|
||||
int gcn64lib_rawSiCommand(gcn64_hdl_t hdl, unsigned char channel, unsigned char *tx, unsigned char tx_len, unsigned char *rx, unsigned char max_rx);
|
||||
int gcn64lib_getVersion(gcn64_hdl_t hdl, char *dst, int dstmax);
|
||||
int gcn64lib_getSignature(gcn64_hdl_t hdl, char *dst, int dstmax);
|
||||
int gcn64lib_getControllerType(gcn64_hdl_t hdl, int chn);
|
||||
const char *gcn64lib_controllerName(int type);
|
||||
int gcn64lib_bootloader(gcn64_hdl_t hdl);
|
||||
|
||||
int gcn64lib_8bit_scan(gcn64_hdl_t hdl, unsigned char min, unsigned char max);
|
||||
|
26
tool/main.c
26
tool/main.c
@ -53,11 +53,13 @@ static void printUsage(void)
|
||||
printf(" --get_serial Read serial from eeprom\n");
|
||||
printf(" --set_poll_rate ms Set time between controller polls in milliseconds\n");
|
||||
printf(" --get_poll_rate Read configured poll rate\n");
|
||||
printf(" --get_controller_type Display the type of controller currently connected\n");
|
||||
printf("\n");
|
||||
printf("Advanced commands:\n");
|
||||
printf(" --bootloader Re-enumerate in bootloader mode\n");
|
||||
printf(" --suspend_polling Stop polling the controller\n");
|
||||
printf(" --resume_polling Re-start polling the controller\n");
|
||||
printf(" --get_signature Get the firmware signature\n");
|
||||
printf("\n");
|
||||
printf("Raw controller commands:\n");
|
||||
printf(" --n64_getstatus Read N64 controller status now\n");
|
||||
@ -113,7 +115,9 @@ static void printUsage(void)
|
||||
#define OPT_GC_TO_N64_READ_MAPPING 320
|
||||
#define OPT_GC_TO_N64_LOAD_MAPPING 321
|
||||
#define OPT_GC_TO_N64_STORE_CURRENT_MAPPING 322
|
||||
#define OPT_GET_VERSION 323
|
||||
#define OPT_GET_VERSION 323
|
||||
#define OPT_GET_SIGNATURE 324
|
||||
#define OPT_GET_CTLTYPE 325
|
||||
|
||||
struct option longopts[] = {
|
||||
{ "help", 0, NULL, 'h' },
|
||||
@ -147,6 +151,8 @@ struct option longopts[] = {
|
||||
{ "gc_to_n64_store_current_mapping", 1, NULL, OPT_GC_TO_N64_STORE_CURRENT_MAPPING },
|
||||
{ "nonstop", 0, NULL, OPT_NONSTOP },
|
||||
{ "get_version", 0, NULL, OPT_GET_VERSION },
|
||||
{ "get_signature", 0, NULL, OPT_GET_SIGNATURE },
|
||||
{ "get_controller_type", 0, NULL, OPT_GET_CTLTYPE },
|
||||
{ },
|
||||
};
|
||||
|
||||
@ -499,6 +505,24 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case OPT_GET_SIGNATURE:
|
||||
{
|
||||
char sig[64];
|
||||
|
||||
if (0 == gcn64lib_getSignature(hdl, sig, sizeof(sig))) {
|
||||
printf("Signature: %s\n", sig);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case OPT_GET_CTLTYPE:
|
||||
{
|
||||
int type;
|
||||
type = gcn64lib_getControllerType(hdl, 0);
|
||||
printf("Controller type 0x%02x: %s\n", type, gcn64lib_controllerName(type));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (do_exchange) {
|
||||
|
Loading…
Reference in New Issue
Block a user