Skip to content

Commit 9cfd296

Browse files
committed
Add input handling
1 parent 2162019 commit 9cfd296

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

bin/mercury2_prog

56 Bytes
Binary file not shown.

mercury2_prog.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <math.h>
3333
#include <stdint.h>
3434
#include <time.h>
35+
#include <inttypes.h>
36+
#include <errno.h>
3537

3638
// OS-specific libraries
3739
#ifdef _WIN32
@@ -849,10 +851,15 @@ int main(int argc, char** argv)
849851
// *@@@@@@@@@@@@@@@@@@@@@@@ OUTPUT @@@@@@@@@@@@@@@@@@@@@@@@@@@
850852
else if((!strcmp(argv[1], "-o") || !strcmp(argv[1], "--output")) && argc > 2)
851853
{
852-
// TODO: parse int from argv[2]
853-
uint8_t var = 0x1F;
854+
// parse int from argv[2]
855+
intmax_t var = strtoimax(argv[2], NULL, 0);
856+
if (errno == ERANGE || (var == 0 && strcmp(argv[2], "0")))
857+
{
858+
printf("\nFailed to interpret output value '%s' as decimal or hex value\n", argv[2]);
859+
exit(1);
860+
}
854861
FTDI_ConnectMercury2(FTDI_FindMercury2(), 0); // connect to Mercury 2 without initializing flash interface
855-
printf("\n***** OUTPUTTING 0x%x for 100 ms *****\n", var);
862+
printf("\n***** OUTPUTTING 0x%X for 100 ms *****\n", (uint8_t)(var & 0b00011111));
856863
// output value on pins, We assume user has configured the 5 pins as inputs with either a pull up or pull down
857864
const uint8_t MPSSE_StateWriteData[] = {3, ACBUS_GPIO_WRITE_COMMAND, (var << 3) & 0b11111000, ACBUS_DIRECTION_OUTPUT};
858865
FTDI_WriteBuffer_AppendArray(MPSSE_StateWriteData); // Configure write upper bits of ACB

0 commit comments

Comments
 (0)