summaryrefslogtreecommitdiffstats
path: root/libsensors_iio/software/simple_apps/common/helper.h
blob: b2da520c4dea7ce6ca657f9fb358853c401a1c61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 $License:
    Copyright (C) 2011 InvenSense Corporation, All Rights Reserved.
 $
 */

/*******************************************************************************
 *
 * $Id: helper-customer.h 5770 2011-07-14 01:34:10Z mcaramello $
 *
 *******************************************************************************/

#ifndef HELPER_C_H
#define HELPER_C_H

#ifdef __cplusplus
extern "C" {
#endif

#include "mltypes.h"
#include "mlerrorcode.h"

/*
    Defines 
*/

#define CALL_N_CHECK(f) {                                                   \
    unsigned int r35uLt = f;                                                \
    if(INV_SUCCESS != r35uLt) {                                              \
        printf("Error in file %s, line %d : %s returned code %s (#%d)\n",   \
                __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt);       \
    }                                                                       \
}

#define CALL_CHECK_N_RETURN_ERROR(f) {                                      \
    unsigned int r35uLt = f;                                                \
    if(INV_SUCCESS != r35uLt) {                                              \
        printf("Error in file %s, line %d : %s returned code %s (#%d)\n",   \
                __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt);       \
        return r35uLt;                                                      \
    }                                                                       \
}

// for functions returning void
#define CALL_CHECK_N_RETURN(f) {                                            \
    unsigned int r35uLt = f;                                                \
    if(INV_SUCCESS != r35uLt) {                                              \
        printf("Error in file %s, line %d : %s returned code %s (#%d)\n",   \
                __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt);       \
        return;                                                             \
    }                                                                       \
}

#define CALL_CHECK_N_EXIT(f) {                                              \
    unsigned int r35uLt = f;                                                \
    if(INV_SUCCESS != r35uLt) {                                              \
        printf("Error in file %s, line %d : %s returned code %s (#%d)\n",   \
                __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt);       \
        exit (r35uLt);                                                      \
    }                                                                       \
}

    
#define CALL_CHECK_N_CALLBACK(f, cb) {                                      \
    unsigned int r35uLt = f;                                                \
    if(INV_SUCCESS != r35uLt) {                                              \
        printf("Error in file %s, line %d : %s returned code %s (#%d)\n",   \
                __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt);       \
        cb;                                                                 \
    }                                                                       \
}

#define CALL_CHECK_N_GOTO(f, label) {                                       \
    unsigned int r35uLt = f;                                                \
    if(INV_SUCCESS != r35uLt) {                                              \
        printf("Error in file %s, line %d : %s returned code %s (#%d)\n",   \
                __FILE__, __LINE__, #f, MLErrorCode(r35uLt), r35uLt);       \
        goto label;                                                         \
    }                                                                       \
}

#define DEFAULT_PLATFORM        PLATFORM_ID_MSB_V2
#define DEFAULT_ACCEL_ID        ACCEL_ID_KXTF9
#define DEFAULT_COMPASS_ID      COMPASS_ID_AK8975

#define DataLogger(x)           NULL
#define DataLoggerSelector(x)   //
#define DataLoggerCb(x)         NULL
#define findComm()              (9)
#define MenuHwChoice(p,a,c)     (*p = DEFAULT_PLATFORM, *a = DEFAULT_ACCEL_ID, \
                                 *c = DEFAULT_COMPASS_ID, INV_ERROR)

    char ConsoleGetChar(void);
    int ConsoleKbhit(void);
    struct mpuirq_data **InterruptPoll(
        int *handles, int numHandles, long tv_sec, long tv_usec);
    void InterruptPollDone(struct mpuirq_data ** data);

#ifdef __cplusplus
}
#endif

#endif // HELPER_C_H