-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoystick_read.c
183 lines (152 loc) · 5.46 KB
/
joystick_read.c
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/**
* joystick_read.c
*
* ABSTRACT:
* The purpose of this sfunction is to call a simple legacy
* function during simulation:
*
* double y1 = read_joystick()
*
* Simulink version : 9.0 (R2017b) 24-Jul-2017
* C source code generated on : 02-Aug-2018 11:27:50
*
* THIS S-FUNCTION IS GENERATED BY THE LEGACY CODE TOOL AND MAY NOT WORK IF MODIFIED
*/
/**
%%%-MATLAB_Construction_Commands_Start
def = legacy_code('initialize');
def.SFunctionName = 'joystick_read';
def.OutputFcnSpec = 'double y1 = read_joystick()';
def.StartFcnSpec = 'void init()';
def.HeaderFiles = {'joystick.h', 'stdio.h', 'ncurses.h', 'gamepad.h'};
def.SourceFiles = {'joystick.c'};
def.HostLibFiles = {'libgamepad.so.1'};
def.SampleTime = 0.001;
legacy_code('sfcn_cmex_generate', def);
legacy_code('compile', def);
%%%-MATLAB_Construction_Commands_End
*/
/* Must specify the S_FUNCTION_NAME as the name of the S-function */
#define S_FUNCTION_NAME joystick_read
#define S_FUNCTION_LEVEL 2
/**
* Need to include simstruc.h for the definition of the SimStruct and
* its associated macro definitions.
*/
#include "simstruc.h"
/* Specific header file(s) required by the legacy code function */
#include "joystick.h"
#include "stdio.h"
#include "ncurses.h"
#include "gamepad.h"
/* Function: mdlInitializeSizes ===========================================
* Abstract:
* The sizes information is used by Simulink to determine the S-function
* block's characteristics (number of inputs, outputs, states, etc.).
*/
static void mdlInitializeSizes(SimStruct *S)
{
/* Number of expected parameters */
ssSetNumSFcnParams(S, 0);
/* Set the number of work vectors */
if (!ssSetNumDWork(S, 0)) return;
ssSetNumPWork(S, 0);
/* Set the number of input ports */
if (!ssSetNumInputPorts(S, 0)) return;
/* Set the number of output ports */
if (!ssSetNumOutputPorts(S, 1)) return;
/* Configure the output port 1 */
ssSetOutputPortDataType(S, 0, SS_DOUBLE);
{
int_T y1Width = 1;
ssSetOutputPortWidth(S, 0, y1Width);
}
ssSetOutputPortComplexSignal(S, 0, COMPLEX_NO);
ssSetOutputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL);
ssSetOutputPortOutputExprInRTW(S, 0, 1);
/* Register reserved identifiers to avoid name conflict */
if (ssRTWGenIsCodeGen(S) || ssGetSimMode(S)==SS_SIMMODE_EXTERNAL) {
/* Register reserved identifier for */
ssRegMdlInfo(S, "init", MDL_INFO_ID_RESERVED, 0, 0, ssGetPath(S));
/* Register reserved identifier for */
ssRegMdlInfo(S, "read_joystick", MDL_INFO_ID_RESERVED, 0, 0, ssGetPath(S));
} /* if */
/* This S-function can be used in referenced model simulating in normal mode */
ssSetModelReferenceNormalModeSupport(S, MDL_START_AND_MDL_PROCESS_PARAMS_OK);
/* Set the number of sample time */
ssSetNumSampleTimes(S, 1);
/* Set the compliance with the SimState feature */
ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
ssSetArrayLayoutForCodeGen(S, SS_COLUMN_MAJOR);
/* Set the Simulink version this S-Function has been generated in */
ssSetSimulinkVersionGeneratedIn(S, "9.0");
/**
* All options have the form SS_OPTION_<name> and are documented in
* matlabroot/simulink/include/simstruc.h. The options should be
* bitwise or'd together as in
* ssSetOptions(S, (SS_OPTION_name1 | SS_OPTION_name2))
*/
ssSetOptions(S,
SS_OPTION_USE_TLC_WITH_ACCELERATOR |
SS_OPTION_CAN_BE_CALLED_CONDITIONALLY |
SS_OPTION_EXCEPTION_FREE_CODE |
SS_OPTION_WORKS_WITH_CODE_REUSE |
SS_OPTION_SFUNCTION_INLINED_FOR_RTW |
SS_OPTION_DISALLOW_CONSTANT_SAMPLE_TIME
);
}
/* Function: mdlInitializeSampleTimes =====================================
* Abstract:
* This function is used to specify the sample time(s) for your
* S-function. You must register the same number of sample times as
* specified in ssSetNumSampleTimes.
*/
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, (real_T)0.001);
ssSetOffsetTime(S, 0, (real_T)0);
#if defined(ssSetModelReferenceSampleTimeDisallowInheritance)
ssSetModelReferenceSampleTimeDisallowInheritance(S);
#endif
}
#define MDL_START
#if defined(MDL_START)
/* Function: mdlStart =====================================================
* Abstract:
* This function is called once at start of model execution. If you
* have states that should be initialized once, this is the place
* to do it.
*/
static void mdlStart(SimStruct *S)
{
/* Call the legacy code function */
init();
}
#endif
/* Function: mdlOutputs ===================================================
* Abstract:
* In this function, you compute the outputs of your S-function
* block. Generally outputs are placed in the output vector(s),
* ssGetOutputPortSignal.
*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
/* Get access to Parameter/Input/Output/DWork data */
real_T* y1 = (real_T*) ssGetOutputPortSignal(S, 0);
/* Call the legacy code function */
*y1 = read_joystick();
}
/* Function: mdlTerminate =================================================
* Abstract:
* In this function, you should perform any actions that are necessary
* at the termination of a simulation.
*/
static void mdlTerminate(SimStruct *S)
{
}
/* Required S-function trailer */
#ifdef MATLAB_MEX_FILE
# include "simulink.c"
#else
# include "cg_sfun.h"
#endif