Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhid/src/hidpath.c

    r160b75e r5499a8b  
    4141#include <assert.h>
    4242
    43 
     43/*---------------------------------------------------------------------------*/
     44/**
     45 * Compares two usages if they are same or not or one of the usages is not
     46 * set.
     47 *
     48 * @param usage1
     49 * @param usage2
     50 * @return boolean
     51 */
     52#define USB_HID_SAME_USAGE(usage1, usage2)              \
     53        ((usage1 == usage2) || (usage1 == 0) || (usage2 == 0))
     54
     55/**
     56 * Compares two usage pages if they are same or not or one of them is not set.
     57 *
     58 * @param page1
     59 * @param page2
     60 * @return boolean
     61 */
     62#define USB_HID_SAME_USAGE_PAGE(page1, page2)   \
     63        ((page1 == page2) || (page1 == 0) || (page2 == 0))
     64
     65/*---------------------------------------------------------------------------*/
    4466/**
    4567 * Appends one item (couple of usage_path and usage) into the usage path
     
    7092}
    7193
     94/*---------------------------------------------------------------------------*/
    7295/**
    7396 * Removes last item from the usage path structure
     
    88111}
    89112
     113/*---------------------------------------------------------------------------*/
    90114/**
    91115 * Nulls last item of the usage path structure.
     
    99123       
    100124        if(!list_empty(&usage_path->head)){     
    101                 item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link);
     125                item = list_get_instance(usage_path->head.prev,
     126                        usb_hid_report_usage_path_t, link);
     127
    102128                memset(item, 0, sizeof(usb_hid_report_usage_path_t));
    103129        }
    104130}
    105131
     132/*---------------------------------------------------------------------------*/
    106133/**
    107134 * Modifies last item of usage path structure by given usage page or usage
     
    134161}
    135162
    136 
     163/*---------------------------------------------------------------------------*/
     164/**
     165 *
     166 *
     167 *
     168 *
     169 */
    137170void usb_hid_print_usage_path(usb_hid_report_path_t *path)
    138171{
     
    144177        while(item != &path->head) {
    145178
    146                 path_item = list_get_instance(item, usb_hid_report_usage_path_t, link);
     179                path_item = list_get_instance(item, usb_hid_report_usage_path_t,
     180                        link);
     181
    147182                usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page);
    148183                usb_log_debug("\tUSAGE: %X\n", path_item->usage);
    149184                usb_log_debug("\tFLAGS: %d\n", path_item->flags);               
    150185               
    151                 item = item->next;
    152         }
    153 }
    154 
     186        item = item->next;
     187        }
     188}
     189
     190/*---------------------------------------------------------------------------*/
    155191/**
    156192 * Compares two usage paths structures
     
    195231                        }
    196232
    197                         // projit skrz cestu a kdyz nekde sedi tak vratim EOK
    198                         // dojduli az za konec tak nnesedi
    199233                        report_link = report_path->head.next;
    200234                        path_link = path->head.next;
    201                         path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link);
     235                        path_item = list_get_instance(path_link,
     236                                usb_hid_report_usage_path_t, link);
    202237
    203238                        while(report_link != &report_path->head) {
    204                                 report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link);
    205                                 if(report_item->usage_page == path_item->usage_page){
     239                                report_item = list_get_instance(report_link,
     240                                        usb_hid_report_usage_path_t, link);
     241                               
     242                                if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
     243                                        path_item->usage_page)){
     244                                       
    206245                                        if(only_page == 0){
    207                                                 if(report_item->usage == path_item->usage) {
     246                                                if(USB_HID_SAME_USAGE(report_item->usage,
     247                                                        path_item->usage)) {
     248                                                       
    208249                                                        return EOK;
    209250                                                }
     
    235276                                                 
    236277                                        report_item = list_get_instance(report_link,
    237                                                                         usb_hid_report_usage_path_t,
    238                                                                         link);
     278                        usb_hid_report_usage_path_t, link);
    239279                                                 
    240280                                        path_item = list_get_instance(path_link,
    241                                                                       usb_hid_report_usage_path_t,
    242                                                                       link);           
    243 
    244                                         if((report_item->usage_page != path_item->usage_page) ||
    245                                            ((only_page == 0) &&
    246                                             (report_item->usage != path_item->usage))) {
     281                        usb_hid_report_usage_path_t, link);             
     282
     283                                        if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
     284                                                path_item->usage_page) || ((only_page == 0) &&
     285                                            !USB_HID_SAME_USAGE(report_item->usage,
     286                                                path_item->usage))) {
    247287                                                       
    248288                                                   return 1;
     
    254294                                }
    255295
    256                                 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && (path_link == &path->head)) ||
    257                                    ((report_link == &report_path->head) && (path_link == &path->head))) {
     296                                if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) &&
     297                                        (path_link == &path->head)) ||
     298                                   ((report_link == &report_path->head) &&
     299                                        (path_link == &path->head))) {
     300                                       
    258301                                        return EOK;
    259302                                }
     
    277320                                                 
    278321                                        report_item = list_get_instance(report_link,
    279                                                                         usb_hid_report_usage_path_t,
    280                                                                         link);
     322                                                usb_hid_report_usage_path_t, link);
     323
    281324                                        path_item = list_get_instance(path_link,
    282                                                                       usb_hid_report_usage_path_t,
    283                                                                       link);           
    284 
    285                                         if((report_item->usage_page != path_item->usage_page) ||
    286                                            ((only_page == 0) &&
    287                                             (report_item->usage != path_item->usage))) {
    288                                                    return 1;
     325                                                usb_hid_report_usage_path_t, link);             
     326                                                 
     327                                        if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
     328                                                path_item->usage_page) || ((only_page == 0) &&
     329                                            !USB_HID_SAME_USAGE(report_item->usage,
     330                                                path_item->usage))) {
     331                                               
     332                                                        return 1;
    289333                                        } else {
    290334                                                report_link = report_link->prev;
     
    308352}
    309353
     354/*---------------------------------------------------------------------------*/
    310355/**
    311356 * Allocates and initializes new usage path structure.
     
    329374}
    330375
     376/*---------------------------------------------------------------------------*/
    331377/**
    332378 * Releases given usage path structure.
     
    345391}
    346392
    347 
     393/*---------------------------------------------------------------------------*/
    348394/**
    349395 * Clone content of given usage path to the new one
     
    352398 * @return New copy of given usage path structure
    353399 */
    354 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path)
     400usb_hid_report_path_t *usb_hid_report_path_clone(
     401        usb_hid_report_path_t *usage_path)
    355402{
    356403        link_t *path_link;
     
    371418        path_link = usage_path->head.next;
    372419        while(path_link != &usage_path->head) {
    373                 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, 
     420                path_item = list_get_instance(path_link, usb_hid_report_usage_path_t,
    374421                                              link);
    375422                new_path_item = malloc(sizeof(usb_hid_report_usage_path_t));
     
    392439}
    393440
    394 
     441/*---------------------------------------------------------------------------*/
    395442/**
    396443 * Sets report id in usage path structure
     
    400447 * @return Error code
    401448 */
    402 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, uint8_t report_id)
     449int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path,
     450        uint8_t report_id)
    403451{
    404452        if(path == NULL){
Note: See TracChangeset for help on using the changeset viewer.