Changeset 2676

Show
Ignore:
Timestamp:
08/29/04 23:22:00 (9 years ago)
Author:
khali
Message:

Wait for user input to continue (as opposed to 5 sec delay).

Can be skipped using -y.

Location:
lm-sensors/trunk/prog/dump
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/prog/dump/i2cset.8

    r2647 r2676  
    1 .TH I2CSET 8 "July 2004" 
     1.TH I2CSET 8 "August 2004" 
    22.SH "NAME" 
    33i2cset \- set I2C registers 
     
    55.SH SYNOPSIS 
    66.B i2cset 
     7.RB [ -y ] 
    78.I i2cbus 
    89.I chip-address 
     
    1011.I value 
    1112.RI [ mode ] 
     13.br 
     14.B i2cset 
     15.B -V 
    1216 
    1317.SH DESCRIPTION 
     
    1620 
    1721.SH OPTIONS 
     22.TP 
     23.B -v, -V 
     24Display the version and exit. 
     25.TP 
     26.B -y 
     27Disable interactive mode. By default, isaset will wait for a confirmation 
     28from the user before messing with the ISA bus. When this flag is used, it 
     29will perform the operation directly. This is mainly meant to be used in 
     30scripts. 
     31.PP 
    1832There are four required options to i2cset. \fIi2cbus\fR indicates the number 
    1933of the I2C bus to be scanned.  This number should correspond to one of 
  • lm-sensors/trunk/prog/dump/i2cset.c

    r2675 r2676  
    3333void help(void) 
    3434{ 
    35         fprintf(stderr, "Syntax: i2cset I2CBUS CHIP-ADDRESS DATA-ADDRESS " 
    36                 "VALUE [MODE]\n"); 
     35        fprintf(stderr, "Syntax: i2cset [-y] I2CBUS CHIP-ADDRESS DATA-ADDRESS " 
     36                "VALUE [MODE]\n" 
     37                "        i2cset -V\n"); 
    3738        fprintf(stderr, "  MODE is 'b[yte]' or 'w[ord]' (default b)\n"); 
    3839        fprintf(stderr, "  I2CBUS is an integer\n"); 
     
    4950        char filename[20]; 
    5051        long funcs; 
    51  
    52         if (argc >= 2 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "-V"))) { 
     52        int flags = 0; 
     53        int yes = 0, version = 0; 
     54 
     55        /* handle (optional) flags first */ 
     56        while (1+flags < argc && argv[1+flags][0] == '-') { 
     57                switch (argv[1+flags][1]) { 
     58                case 'V': version = 1; break; 
     59                case 'y': yes = 1; break; 
     60                default: 
     61                        fprintf(stderr, "Warning: Unsupported flag " 
     62                                "\"-%c\"!\n", argv[1+flags][1]); 
     63                        help(); 
     64                        exit(1); 
     65                } 
     66                flags++; 
     67        } 
     68 
     69        if (version) { 
    5370                fprintf(stderr, "i2cset version %s\n", LM_VERSION); 
    5471                exit(1); 
    5572        } 
    5673 
    57         if (argc < 5) 
    58                 help(); 
    59  
    60         i2cbus = strtol(argv[1], &end, 0); 
     74        if (argc + flags < 5) 
     75                help(); 
     76 
     77        i2cbus = strtol(argv[flags+1], &end, 0); 
    6178        if (*end || i2cbus < 0 || i2cbus > 0x3f) { 
    6279                fprintf(stderr, "Error: I2CBUS argument invalid!\n"); 
     
    6481        } 
    6582 
    66         address = strtol(argv[2], &end, 0); 
     83        address = strtol(argv[flags+2], &end, 0); 
    6784        if (*end || address < 0 || address > 0x7f) { 
    6885                fprintf(stderr, "Error: Chip address invalid!\n"); 
     
    7087        } 
    7188 
    72         daddress = strtol(argv[3], &end, 0); 
     89        daddress = strtol(argv[flags+3], &end, 0); 
    7390        if (*end || daddress < 0 || daddress > 0xff) { 
    7491                fprintf(stderr, "Error: Data address invalid!\n"); 
     
    7693        } 
    7794 
    78         value = strtol(argv[4], &end, 0); 
     95        value = strtol(argv[flags+4], &end, 0); 
    7996        if (*end) { 
    8097                fprintf(stderr, "Error: Data value invalid!\n"); 
     
    8299        } 
    83100 
    84         if (argc < 6) { 
     101        if (argc < flags + 6) { 
    85102                fprintf(stderr, "No size specified (using byte-data access)\n"); 
    86103                size = I2C_SMBUS_BYTE_DATA; 
    87         } else if (!strcmp(argv[5], "b")) 
     104        } else if (!strcmp(argv[flags+5], "b")) 
    88105                size = I2C_SMBUS_BYTE_DATA; 
    89         else if (!strcmp(argv[5], "w")) 
     106        else if (!strcmp(argv[flags+5], "w")) 
    90107                size = I2C_SMBUS_WORD_DATA; 
    91108        else { 
     
    139156        } 
    140157 
    141         fprintf(stderr, "WARNING! This program can confuse your I2C bus, " 
    142                 "cause data loss and worse!\n"); 
    143         if (address >= 0x50 && address <= 0x57) { 
    144                 fprintf(stderr, "DANGEROUS!! Writing to a serial EEPROM on " 
    145                         "a memory DIMM\nmay render your memory USELESS and " 
    146                         "make your system UNBOOTABLE!!!\nAre you SURE that " 
    147                         "you want to write to the chip at address 0x%02x? " 
    148                         "(y/N) ", address); 
    149                 res = getchar(); 
    150                 if (res != 'y' && res != 'Y') 
    151                         exit(1); 
    152         } 
    153  
    154         fprintf(stderr, "I will write to device file %s, chip address 0x%02x, " 
    155                 "data address\n0x%02x, data 0x%02x, mode %s.\n", filename, 
    156                 address, daddress, value, size == I2C_SMBUS_BYTE_DATA ? 
    157                 "byte" : "word"); 
    158         fprintf(stderr, "You have five seconds to reconsider and press " 
    159                 "CTRL-C!\n\n"); 
    160         sleep(5); 
     158        if (!yes) { 
     159                char s[2]; 
     160                int dont = 0; 
     161 
     162                fprintf(stderr, "WARNING! This program can confuse your I2C " 
     163                        "bus, cause data loss and worse!\n"); 
     164 
     165                if (address >= 0x50 && address <= 0x57) { 
     166                        fprintf(stderr, "DANGEROUS! Writing to a serial " 
     167                                "EEPROM on a memory DIMM\nmay render your " 
     168                                "memory USELESS and make your system " 
     169                                "UNBOOTABLE!\n"); 
     170                        dont = 1; 
     171                } 
     172 
     173                fprintf(stderr, "I will write to device file %s, chip address " 
     174                        "0x%02x, data address\n0x%02x, data 0x%02x, mode " 
     175                        "%s.\n", filename, address, daddress, value, 
     176                        size == I2C_SMBUS_BYTE_DATA ? "byte" : "word"); 
     177 
     178                fprintf(stderr, "Continue? [%s] ", dont ? "y/N" : "Y/n"); 
     179                fflush(stderr); 
     180                fgets(s, 2, stdin); 
     181                if ((s[0] != '\n' || dont) && s[0] != 'y' && s[0] != 'Y') { 
     182                        fprintf(stderr, "Aborting on user request.\n"); 
     183                        exit(0); 
     184                } 
     185        } 
    161186 
    162187        e1 = 0;