static int defaultKey(int s, voice_p voice) { static int step[15][OCTAVE_DIATON] = { /* c, d, e, f, g, a, b */ { 0, 0, 0, 0, 0, 0, 0 }, /* C */ { 0, 0, 0, 1, 0, 0, 0 }, /* 1# G */ { 1, 0, 0, 1, 0, 0, 0 }, /* 2# D */ { 1, 0, 0, 1, 1, 0, 0 }, /* 3# A */ { 1, 1, 0, 1, 1, 0, 0 }, /* 4# E */ { 1, 1, 0, 1, 1, 1, 0 }, /* 5# B */ { 1, 1, 1, 1, 1, 1, 0 }, /* 6# Fis */ { 1, 1, 1, 1, 1, 1, 1 }, /* 7# Cis */ { 0, 0, 0, 0, 0, 0, -1 }, /* 1b F */ { 0, 0, -1, 0, 0, 0, -1 }, /* 2b Bes */ { 0, 0, -1, 0, 0, -1, -1 }, /* 3b Es */ { 0, -1, -1, 0, 0, -1, -1 }, /* 4b As */ { 0, -1, -1, 0, -1, -1, -1 }, /* 5b Des */ { -1, -1, -1, 0, -1, -1, -1 }, /* 6b Ges */ { -1, -1, -1, -1, -1, -1, -1 }}; /* 7b Ces */ if (voice->key_current == KEY_RESET) { /* Missed a C major? */ if (1) { fprintf(stderr, "Warning: key reset not followed by key, ignore\n"); key_set(NULL, voice->key_previous_current, voice); } else { fprintf(stderr, "Warning: key reset not followed by key, assume C major\n"); key_set(NULL, 0, voice); } } return step[voice->key_current][s]; }
static void test_get_set_keys(CuTest *tc) { attrib *a = 0; key_set(&a, 42, 1); key_set(&a, 43, 2); key_set(&a, 44, 3); CuAssertIntEquals(tc, 1, key_get(a, 42)); CuAssertIntEquals(tc, 2, key_get(a, 43)); CuAssertIntEquals(tc, 3, key_get(a, 44)); key_unset(&a, 42); CuAssertIntEquals(tc, 0, key_get(a, 42)); CuAssertIntEquals(tc, 2, key_get(a, 43)); CuAssertIntEquals(tc, 3, key_get(a, 44)); a_removeall(&a, NULL); }
static void test_get_set_keys(CuTest *tc) { attrib *a = 0; key_set(&a, 42); key_set(&a, 43); key_set(&a, 44); CuAssertTrue(tc, key_get(a, 42)); CuAssertTrue(tc, key_get(a, 43)); CuAssertTrue(tc, key_get(a, 44)); key_unset(&a, 42); CuAssertTrue(tc, !key_get(a, 42)); CuAssertTrue(tc, key_get(a, 43)); CuAssertTrue(tc, key_get(a, 44)); a_removeall(&a, NULL); }
static void dumpKeySign(mpq_t *t, symbol_p s, voice_p voice) { key_sign_p k = &s->symbol.key_sign; key_set(s, k->code, voice); }
static void a_upgradekeys(attrib **alist, attrib *abegin) { attrib *a, *ak; ak = a_find(*alist, &at_keys); if (ak) alist = &ak; for (a = abegin; a && a->type == abegin->type; a = a->next) { key_set(alist, a->data.i, 1); } }
static int tolua_region_setkey(lua_State * L) { region *self = (region *)tolua_tousertype(L, 1, 0); const char *name = tolua_tostring(L, 2, 0); int value = tolua_toboolean(L, 3, 0); int flag = atoi36(name); if (value) { key_set(&self->attribs, flag); } else { key_unset(&self->attribs, flag); } return 0; }
static void test_group_readwrite(CuTest * tc) { faction * f; group *g; ally *al; int i; gamedata data; storage store; test_cleanup(); mstream_init(&data.strm); gamedata_init(&data, &store, RELEASE_VERSION); f = test_create_faction(0); new_group(f, "NW", 42); g = new_group(f, "Egoisten", 43); key_set(&g->attribs, 44); al = ally_add(&g->allies, f); al->status = HELP_GIVE; write_groups(&store, f); WRITE_INT(&store, 47); free_group(f->groups); free_group(g); f->groups = 0; data.strm.api->rewind(data.strm.handle); read_groups(&data, f); READ_INT(&store, &i); mstream_done(&data.strm); gamedata_done(&data); CuAssertIntEquals(tc, 47, i); CuAssertPtrNotNull(tc, f->groups); CuAssertIntEquals(tc, 42, f->groups->gid); CuAssertStrEquals(tc, "NW", f->groups->name); CuAssertPtrNotNull(tc, f->groups->next); CuAssertIntEquals(tc, 43, f->groups->next->gid); CuAssertStrEquals(tc, "Egoisten", f->groups->next->name); CuAssertPtrEquals(tc, 0, f->groups->allies); g = f->groups->next; CuAssertTrue(tc, key_get(g->attribs, 44)); CuAssertPtrNotNull(tc, g->allies); CuAssertPtrEquals(tc, 0, g->allies->next); CuAssertPtrEquals(tc, f, g->allies->faction); CuAssertIntEquals(tc, HELP_GIVE, g->allies->status); test_cleanup(); }
int get_key() { int i,cx, cy, fd; char key; static char *driver = "/dev/i2c/0"; //printf(" 5x4 Keyboard Test Example base on Linux.\n"); //printf(" Please Press a key...\n"); /* open device */ fd = open(driver, O_RDWR); if(fd < 0) { printf("device open fail\n"); return -1; } /* set zlg7290 slave address */ ioctl(fd, I2C_SLAVE_FORCE, ZLG_SLAVE_ADDR); /* set i2c bus clock 250KHz */ ioctl(fd, I2C_SET_BUS_CLOCK, 250*1000); /* display all segment */ key = 0xff; for(i=0; i<8; i++) { /* zlg7290 inner register access address */ ioctl(fd, I2C_SET_DATA_ADDR, REG_Dis7-i); write(fd, &key, 1); } sleep(2); /* zlg7290 inner register access address */ ioctl(fd, I2C_SET_DATA_ADDR, REG_Sys); read(fd, &key, 1); /* check key pressed */ if(key & 0x01)// if REG_Sys set as 1, a valid key pressed { /* zlg7290 inner register access address */ ioctl(fd, I2C_SET_DATA_ADDR, REG_Key); /* read key value */ read(fd, &key, 1); if(key > 0) { /* adjust base zero */ cx = ((key-1) % 8) + 1; cy = ((key-1) / 8) + 1; key = key_set(key); if(key != 0xFE)// key map for EduKitII { if(key<16) { if(key<10) key += 0x30; else key += 0x37; } if(key < 255) { //printf("(row %d, col %d) Key: %c\n", cy, cx,key); return key; } //if(key == 0xFF) printf("(row %d, col %d) Key: FUN\n", cy, cx); } if(cy == 4 && cx == 5)// 'FUN' to exit.. { //break; return -1; } } } //printf(" end.\n"); close(fd); return -1; }