/* Box distribution */ static SourceObject* boxAttrib(TiXmlElement* pElement) { /* Initialize XML attribute checker */ static const string required[2] = {"id", "type"}; static const string optional[3] = {"x","y","z"}; static XmlParser::XmlAttributes surAttrib(vector<string>(required, required + 2), vector<string>(optional, optional + 3)); XmlParser::AttribMap mapAttrib = dump_attribs(pElement); /* Check user input */ surAttrib.checkAttributes(mapAttrib,"box distribution"); /* Get attributes */ DistributionId id = fromString<DistributionId>(mapAttrib["id"]); string type = mapAttrib["type"] + "-"; /* Get extent on coordinates */ vector<vector<double> > extent(3); /* Total coefficients */ vector<double> coeffs; for(size_t i = 0 ; i < 3 ; ++i) { extent[i] = getContainer<double>(mapAttrib[getAxisName(i)]); size_t extSize = extent[i].size(); if(extSize > 0) { type += getAxisName(i); for(size_t j = 0 ; j < extSize ; ++j) coeffs.push_back(extent[i][j]); } } /* Return surface definition */ return new DistributionObject(type,id,coeffs); }
static bool enumerateAxesJs(int fd, axes_t *axes) { axes->axes = 0; if(ioctl(fd, JSIOCGAXES, &(axes->axes)) < 0){ ltr_int_my_perror("ioctl(JSIOCGAXES)"); return false; } if((axes->axesList = (uint8_t*)malloc(axes->axes * sizeof(uint8_t))) == NULL){ ltr_int_my_perror("malloc"); return false; } if((axes->axisNames = (const char**)malloc(axes->axes * sizeof(char*))) == NULL){ ltr_int_my_perror("malloc"); return false; } if((axes->min = (int*)malloc(axes->axes * sizeof(int))) == NULL){ ltr_int_my_perror("malloc"); return false; } if((axes->max = (int*)malloc(axes->axes * sizeof(int))) == NULL){ ltr_int_my_perror("malloc"); return false; } memset(axes->axesList, 0, axes->axes); uint8_t axmap[AXMAP_SIZE] = {0}; if(ioctl(fd, JSIOCGAXMAP, axmap) < 0){ ltr_int_my_perror("ioctl(JSIOCGAXMAP)"); return false; } memcpy(axes->axesList, axmap, axes->axes); size_t i; for(i = 0; i < axes->axes; ++i){ axes->min[i] = -32767; axes->max[i] = 32767; axes->axisNames[i] = getAxisName(axes->axesList[i]); } return true; }
static bool enumerateAxesEvdev(int fd, axes_t *axes) { //printf("Enumerating evdev axes\n"); uint8_t bit[KEY_MAX / 8 + 1]; memset(bit, 0, sizeof(bit)); if(ioctl(fd, EVIOCGBIT(0, EV_MAX), bit) < 0){ ltr_int_my_perror("EVIOCGBIT_1"); return false; } int type; if(!(bit[0] & (1 << EV_ABS))){ //printf("No absolute events available.\n"); return false; } //printf("We have absolute events available!\n"); //We have some absolute axes memset(bit, 0, sizeof(bit)); if(ioctl(fd, EVIOCGBIT(EV_ABS, KEY_MAX), bit) < 0){ ltr_int_my_perror("EVIOCGBIT_2"); return false; } //Get axes number axes->axes = 0; for(type = 0; type < KEY_MAX; ++type){ if(bit[type >> 3] & (1 << (type & 7))){ ++axes->axes; } } if((axes->axesList = (uint8_t*)malloc(axes->axes * sizeof(uint8_t))) == NULL){ ltr_int_my_perror("malloc"); return false; } memset(axes->axesList, 0, axes->axes); if((axes->axisNames = (const char**)malloc(axes->axes * sizeof(char*))) == NULL){ ltr_int_my_perror("malloc"); return false; } if((axes->min = (int*)malloc(axes->axes * sizeof(int))) == NULL){ ltr_int_my_perror("malloc"); return false; } if((axes->max = (int*)malloc(axes->axes * sizeof(int))) == NULL){ ltr_int_my_perror("malloc"); return false; } size_t current = 0; for(type = 0; type < KEY_MAX; ++type){ if(bit[type >> 3] & (1 << (type & 7))){ axes->axesList[current] = type; axes->axisNames[current] = getAxisName(type); struct input_absinfo ai = {0}; if(ioctl(fd, EVIOCGABS(type), &ai) < 0){ ltr_int_my_perror("EVIOCGABS"); free(axes->axesList); free(axes->min); free(axes->max); axes->axesList = NULL; axes->min = NULL; axes->max = NULL; axes->axes = 0; return false; } ltr_int_log_message("Axis: %d (%s)\n", type, getAxisName(type)); ltr_int_log_message(" Val: %d\n", ai.value); ltr_int_log_message(" Minimum: %d\n", ai.minimum); ltr_int_log_message(" Maximum: %d\n", ai.maximum); ltr_int_log_message(" Fuzz: %d\n", ai.fuzz); ltr_int_log_message(" Flat: %d\n", ai.flat); ltr_int_log_message(" Resolution: %d\n", ai.resolution); axes->min[current] = ai.minimum; axes->max[current] = ai.maximum; ++current; } } return true; }