fix bugprone-multi-level-implicit-pointer-conversio
[liba.git] / java / src / pid.c
blob6fb8626312e90ecec7c4b70de3f058ebed257ab5
1 #include "a.h"
2 #include "a/pid.h"
3 #include "liba_pid.h"
4 #if A_PREREQ_GNUC(3, 0) || __has_warning("-Wfloat-equal")
5 #pragma GCC diagnostic ignored "-Wfloat-equal"
6 #endif /* -Wfloat-equal */
8 #undef L
9 #define L Java_liba_pid
10 static struct
12 jmethodID _new;
13 jfieldID ctx;
14 } L = {NULL, NULL};
16 JNIEXPORT void JNICALL Java_liba_pid_clinit(JNIEnv *_env, jclass _cls)
18 jclass _nbb = (*_env)->FindClass(_env, "Ljava/nio/ByteBuffer;");
19 L._new = (*_env)->GetStaticMethodID(_env, _nbb, "allocateDirect", "(I)Ljava/nio/ByteBuffer;");
20 L.ctx = (*_env)->GetFieldID(_env, _cls, "ctx", "Ljava/nio/ByteBuffer;");
23 JNIEXPORT void JNICALL Java_liba_pid_init(JNIEnv *_env, jobject _obj)
25 jobject _ctx = (*_env)->CallObjectMethod(_env, _obj, L._new, (jint)sizeof(a_pid));
26 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
27 (*_env)->SetObjectField(_env, _obj, L.ctx, _ctx);
28 ctx->kp = 1;
29 ctx->summax = +A_FLOAT_INF;
30 ctx->summin = -A_FLOAT_INF;
31 ctx->outmax = +A_FLOAT_INF;
32 ctx->outmin = -A_FLOAT_INF;
33 a_pid_init(ctx);
36 JNIEXPORT jdouble JNICALL Java_liba_pid_kp__(JNIEnv *_env, jobject _obj)
38 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
39 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
40 return ctx->kp;
43 JNIEXPORT jobject JNICALL Java_liba_pid_kp__D(JNIEnv *_env, jobject _obj, jdouble kp)
45 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
46 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
47 ctx->kp = kp;
48 return _obj;
51 JNIEXPORT jdouble JNICALL Java_liba_pid_ki__(JNIEnv *_env, jobject _obj)
53 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
54 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
55 return ctx->ki;
58 JNIEXPORT jobject JNICALL Java_liba_pid_ki__D(JNIEnv *_env, jobject _obj, jdouble ki)
60 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
61 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
62 ctx->ki = ki;
63 return _obj;
66 JNIEXPORT jdouble JNICALL Java_liba_pid_kd__(JNIEnv *_env, jobject _obj)
68 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
69 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
70 return ctx->kd;
73 JNIEXPORT jobject JNICALL Java_liba_pid_kd__D(JNIEnv *_env, jobject _obj, jdouble kd)
75 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
76 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
77 ctx->kd = kd;
78 return _obj;
81 JNIEXPORT jdouble JNICALL Java_liba_pid_summax__(JNIEnv *_env, jobject _obj)
83 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
84 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
85 return ctx->summax;
88 JNIEXPORT jobject JNICALL Java_liba_pid_summax__D(JNIEnv *_env, jobject _obj, jdouble summax)
90 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
91 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
92 ctx->summax = summax;
93 return _obj;
96 JNIEXPORT jdouble JNICALL Java_liba_pid_summin__(JNIEnv *_env, jobject _obj)
98 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
99 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
100 return ctx->summin;
103 JNIEXPORT jobject JNICALL Java_liba_pid_summin__D(JNIEnv *_env, jobject _obj, jdouble summin)
105 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
106 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
107 ctx->summin = summin;
108 return _obj;
111 JNIEXPORT jdouble JNICALL Java_liba_pid_sum(JNIEnv *_env, jobject _obj)
113 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
114 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
115 return ctx->sum;
118 JNIEXPORT jdouble JNICALL Java_liba_pid_outmax__(JNIEnv *_env, jobject _obj)
120 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
121 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
122 return ctx->outmax;
125 JNIEXPORT jobject JNICALL Java_liba_pid_outmax__D(JNIEnv *_env, jobject _obj, jdouble outmax)
127 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
128 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
129 ctx->outmax = outmax;
130 return _obj;
133 JNIEXPORT jdouble JNICALL Java_liba_pid_outmin__(JNIEnv *_env, jobject _obj)
135 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
136 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
137 return ctx->outmin;
140 JNIEXPORT jobject JNICALL Java_liba_pid_outmin__D(JNIEnv *_env, jobject _obj, jdouble outmin)
142 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
143 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
144 ctx->outmin = outmin;
145 return _obj;
148 JNIEXPORT jdouble JNICALL Java_liba_pid_out(JNIEnv *_env, jobject _obj)
150 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
151 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
152 return ctx->out;
155 JNIEXPORT jdouble JNICALL Java_liba_pid_fdb(JNIEnv *_env, jobject _obj)
157 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
158 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
159 return ctx->fdb;
162 JNIEXPORT jdouble JNICALL Java_liba_pid_err(JNIEnv *_env, jobject _obj)
164 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
165 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
166 return ctx->err;
169 JNIEXPORT jobject JNICALL Java_liba_pid_kpid(JNIEnv *_env, jobject _obj, jdouble kp, jdouble ki, jdouble kd)
171 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
172 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
173 a_pid_kpid(ctx, kp, ki, kd);
174 return _obj;
177 JNIEXPORT jdouble JNICALL Java_liba_pid_run(JNIEnv *_env, jobject _obj, jdouble set, jdouble fdb)
179 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
180 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
181 return a_pid_run(ctx, set, fdb);
183 JNIEXPORT jdouble JNICALL Java_liba_pid_pos(JNIEnv *_env, jobject _obj, jdouble set, jdouble fdb)
185 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
186 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
187 return a_pid_pos(ctx, set, fdb);
190 JNIEXPORT jdouble JNICALL Java_liba_pid_inc(JNIEnv *_env, jobject _obj, jdouble set, jdouble fdb)
192 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
193 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
194 return a_pid_inc(ctx, set, fdb);
197 JNIEXPORT jobject JNICALL Java_liba_pid_zero(JNIEnv *_env, jobject _obj)
199 jobject _ctx = (*_env)->GetObjectField(_env, _obj, L.ctx);
200 a_pid *ctx = (a_pid *)(*_env)->GetDirectBufferAddress(_env, _ctx);
201 a_pid_zero(ctx);
202 return _obj;