示例#1
0
int main(int argc, char **argv)
{
    struct arguments arguments;

    // Default values
    arguments.cmd = NULL;
    arguments.reg = NULL;
    arguments.value = -1;
    arguments.bit_num = -1;
    arguments.hw_addr = -1;

    argp_parse(&argp, argc, argv, 0, 0, &arguments);

    // printf("cmd = %s\nreg = %s\nbit_num = %d\nhw_addr = %d\n",
    //        arguments.cmd, arguments.reg, arguments.bit_num, arguments.hw_addr);

    // hw_addr defaults to 0
    const uint8_t hw_addr = arguments.hw_addr > 0 ? arguments.hw_addr : 0;
    const uint8_t reg = str2reg(arguments.reg);
    if (arguments.bit_num > 7) {
        fprintf(stderr, "pifacedigital: bit num must in range 0-7.\n");
        exit(1);
    }

    if (strcmp(arguments.cmd, "read") == 0) {
        pfd_read(arguments.bit_num, reg, hw_addr);
    } else if (strcmp(arguments.cmd, "write") == 0) {
        pfd_write((uint8_t) (arguments.value & 0xff),
                  arguments.bit_num,
                  reg,
                  hw_addr);
    }

    exit(0);
}
示例#2
0
int main(int argc, char **argv)
{
    struct arguments arguments;

    // Default values
    arguments.cmd = NULL;
    arguments.cmdargs[0] = NULL;
    arguments.cmdargs[1] = NULL;
    arguments.cmdargs[2] = NULL;
    arguments.bit_num = -1;

    argp_parse(&argp, argc, argv, 0, 0, &arguments);

    // printf("cmd = %s\ncmdargs[0] = %s\ncmdargs[1] = %s\n"
    //        "cmdargs[2] = %s\nbit_num = %d\n",
    //        arguments.cmd,
    //        arguments.cmdargs[0],
    //        arguments.cmdargs[1],
    //        arguments.cmdargs[2],
    //        arguments.bit_num);

    if (arguments.bit_num > 7) {
        fprintf(stderr, "pifacecad: bit num must in range 0-7.\n");
        exit(1);
    }

    pifacecad_open_noinit();

    if (strcmp(arguments.cmd, "open") == 0) {
        pifacecad_open();
        int i;
        for (i = 0; i <= 2; i++) {
            if (arguments.cmdargs[i] == NULL) {
                continue;
            }
            if (strcmp(arguments.cmdargs[i], "displayoff") == 0) {
                pifacecad_lcd_display_off();
            }
            if (strcmp(arguments.cmdargs[i], "blinkoff") == 0) {
                pifacecad_lcd_blink_off();
            }
            if (strcmp(arguments.cmdargs[i], "cursoroff") == 0) {
                pifacecad_lcd_cursor_off();
            }
        }

    } else if (strcmp(arguments.cmd, "read") == 0) {
        pfc_read_switch(arguments.bit_num, str2reg(arguments.cmdargs[0]));

    } else if (strcmp(arguments.cmd, "write") == 0) {
        pifacecad_lcd_write(arguments.cmdargs[0]);

    } else if (strcmp(arguments.cmd, "backlight") == 0) {
        if (strcmp(arguments.cmdargs[0], "on") == 0) {
            pifacecad_lcd_backlight_on();
        } else {
            pifacecad_lcd_backlight_off();
        }

    } else if (strcmp(arguments.cmd, "home") == 0) {
        pifacecad_lcd_home();

    } else if (strcmp(arguments.cmd, "clear") == 0) {
        pifacecad_lcd_clear();

    } else if (strcmp(arguments.cmd, "setcursor") == 0) {
        const uint8_t col = atoi(arguments.cmdargs[0]);
        const uint8_t row = atoi(arguments.cmdargs[1]);
        pifacecad_lcd_set_cursor(col, row);
    }

    pifacecad_close();

    exit(0);
}
示例#3
0
bool
str2operand(operand_t *op, char const *str)
{
    int val, tag, size;
    bool rex_used;
    uint64_t ival;
    char const *ptr = str;
    char *wptr;

    while (*ptr++ == ' ');
    ptr--;

    {
        char strcopy[strlen(ptr)+1];
        opertype_t type;
        strlcpy(strcopy, ptr, sizeof strcopy);
        wptr = strcopy + strlen(strcopy) - 1;
        while (*wptr == ' ') {
            wptr--;
        }
        *(++wptr) = '\0';
        ptr = strcopy;

        type = str_op_get_type(ptr);

        switch (type) {
        case op_reg:
            if (!str2reg(ptr, &val, &tag, &size, &rex_used)) {
                return false;
            }
            op->type = type;
            op->size = size;
            ASSERT(op->size == size);
            op->val.reg = val;
            ASSERT(op->val.reg == val);
            op->tag.reg = tag;
            op->rex_used = rex_used;
            ASSERT(op->rex_used == rex_used);
            return true;
        case op_imm:
            if (!str2imm(ptr, &ival, &tag, &size)) {
                return false;
            }
            op->type = type;
            op->size = size;
            op->val.imm = ival;
            op->tag.imm = tag;
            return true;
        case op_seg:
            if (!str2seg(ptr, &val, &tag)) {
                return false;
            }
            op->type = type;
            op->size = 0;
            op->val.seg = val;
            ASSERT(op->val.seg == val);
            op->tag.seg = tag;
            return true;
        case op_prefix:
            if (!str2prefix(ptr, &val, &tag)) {
                return false;
            }
            op->type = type;
            op->size = 0;
            op->val.prefix = val;
            op->tag.prefix = tag;
            return true;
        default:
            ASSERT(0);
            break;
        }
        return false;
    }
}