Skip to content

Commit d540be1

Browse files
committed
Sync buttons working
1 parent db1ba9f commit d540be1

7 files changed

Lines changed: 148 additions & 16 deletions

File tree

JavaGUI/jni/TSDRLibraryNDK.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,23 @@ JNIEXPORT jboolean JNICALL Java_martin_tempest_core_TSDRLibrary_isRunning (JNIE
182182
JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_setInvertedColors (JNIEnv * env, jobject obj, jboolean invertedEnabled) {
183183
inverted = invertedEnabled == JNI_TRUE;
184184
}
185+
186+
JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_sync (JNIEnv * env, jobject obj, jint pixels, jobject dir) {
187+
jclass enumClass = (*env)->FindClass(env, "martin/tempest/core/TSDRLibrary$SYNC_DIRECTION");
188+
jmethodID getNameMethod = (*env)->GetMethodID(env, enumClass, "name", "()Ljava/lang/String;");
189+
jstring value = (jstring)(*env)->CallObjectMethod(env, dir, getNameMethod);
190+
const char* valueNative = (*env)->GetStringUTFChars(env, value, 0);
191+
192+
if (strcmp(valueNative, "ANY") == 0)
193+
THROW(tsdr_sync(&tsdr_instance, (int) pixels, DIRECTION_CUSTOM));
194+
else if (strcmp(valueNative, "UP") == 0)
195+
THROW(tsdr_sync(&tsdr_instance, (int) pixels, DIRECTION_UP));
196+
else if (strcmp(valueNative, "DOWN") == 0)
197+
THROW(tsdr_sync(&tsdr_instance, (int) pixels, DIRECTION_DOWN));
198+
else if (strcmp(valueNative, "LEFT") == 0)
199+
THROW(tsdr_sync(&tsdr_instance, (int) pixels, DIRECTION_LEFT));
200+
else if (strcmp(valueNative, "RIGHT") == 0)
201+
THROW(tsdr_sync(&tsdr_instance, (int) pixels, DIRECTION_RIGHT));
202+
203+
(*env)->ReleaseStringUTFChars(env, value, valueNative);
204+
}

JavaGUI/jni/TSDRLibraryNDK.h

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JavaGUI/jni/include/TSDRLibrary.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
#include <stdint.h>
55

6+
#define DIRECTION_CUSTOM (0)
7+
#define DIRECTION_UP (1)
8+
#define DIRECTION_DOWN (2)
9+
#define DIRECTION_LEFT (3)
10+
#define DIRECTION_RIGHT (4)
11+
612
struct tsdr_lib {
713
void * plugin;
814
void * mutex_sync_unload;
@@ -19,6 +25,7 @@
1925
int frames_to_average;
2026
uint32_t centfreq;
2127
float gain;
28+
volatile int syncoffset;
2229
} typedef tsdr_lib_t;
2330

2431
typedef void(*tsdr_readasync_function)(float *buf, int width, int height, void *ctx);
@@ -32,5 +39,6 @@
3239
int tsdr_unloadplugin(tsdr_lib_t * tsdr);
3340
int tsdr_setresolution(tsdr_lib_t * tsdr, int width, int height, double refreshrate);
3441
int tsdr_isrunning(tsdr_lib_t * tsdr);
42+
int tsdr_sync(tsdr_lib_t * tsdr, int pixels, int direction);
3543

3644
#endif

JavaGUI/src/martin/tempest/Main.java

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import javax.swing.DefaultComboBoxModel;
1515

1616
import martin.tempest.core.TSDRLibrary;
17+
import martin.tempest.core.TSDRLibrary.SYNC_DIRECTION;
1718
import martin.tempest.core.exceptions.TSDRException;
1819
import martin.tempest.sources.TSDRSource;
1920

@@ -29,6 +30,8 @@
2930
import javax.swing.JCheckBox;
3031

3132
public class Main implements TSDRLibrary.FrameReadyCallback {
33+
34+
private static final int SYNC_AMOUNT = 10;
3235

3336
private JFrame frmTempestSdr;
3437
private JTextField textArgs;
@@ -215,6 +218,42 @@ public void actionPerformed(ActionEvent arg0) {
215218
chckbxInvertedColours.setBounds(568, 141, 159, 25);
216219
frmTempestSdr.getContentPane().add(chckbxInvertedColours);
217220

221+
JButton btnUp = new JButton("Up");
222+
btnUp.addActionListener(new ActionListener() {
223+
public void actionPerformed(ActionEvent arg0) {
224+
mSdrlib.sync(SYNC_AMOUNT, SYNC_DIRECTION.UP);
225+
}
226+
});
227+
btnUp.setBounds(608, 186, 78, 25);
228+
frmTempestSdr.getContentPane().add(btnUp);
229+
230+
JButton btnLeft = new JButton("Left");
231+
btnLeft.addActionListener(new ActionListener() {
232+
public void actionPerformed(ActionEvent e) {
233+
mSdrlib.sync(SYNC_AMOUNT, SYNC_DIRECTION.LEFT);
234+
}
235+
});
236+
btnLeft.setBounds(568, 211, 65, 25);
237+
frmTempestSdr.getContentPane().add(btnLeft);
238+
239+
JButton btnRight = new JButton("Right");
240+
btnRight.addActionListener(new ActionListener() {
241+
public void actionPerformed(ActionEvent e) {
242+
mSdrlib.sync(SYNC_AMOUNT, SYNC_DIRECTION.RIGHT);
243+
}
244+
});
245+
btnRight.setBounds(662, 211, 65, 25);
246+
frmTempestSdr.getContentPane().add(btnRight);
247+
248+
JButton btnDown = new JButton("Down");
249+
btnDown.addActionListener(new ActionListener() {
250+
public void actionPerformed(ActionEvent e) {
251+
mSdrlib.sync(SYNC_AMOUNT, SYNC_DIRECTION.DOWN);
252+
}
253+
});
254+
btnDown.setBounds(608, 237, 78, 25);
255+
frmTempestSdr.getContentPane().add(btnDown);
256+
218257
onVideoModeSelected(videomodes[0]);
219258
}
220259

@@ -257,20 +296,14 @@ public void run() {
257296
displayException(frmTempestSdr, e);
258297
return;
259298
}
260-
261-
new Thread() {
262-
public void run() {
263-
try {
264-
mSdrlib.startAsync(src, (Integer) spWidth.getValue(), (Integer) spHeight.getValue(), Double.parseDouble(spFramerate.getValue().toString()));
265-
} catch (TSDRException e1) {
266-
btnStartStop.setText("Start");
267-
displayException(frmTempestSdr, e1);
268-
}
269-
270-
};
271-
}.start();
272-
273-
299+
300+
try {
301+
mSdrlib.startAsync(src, (Integer) spWidth.getValue(), (Integer) spHeight.getValue(), Double.parseDouble(spFramerate.getValue().toString()));
302+
} catch (TSDRException e1) {
303+
displayException(frmTempestSdr, e1);
304+
btnStartStop.setText("Start");
305+
}
306+
274307
btnStartStop.setText("Stop");
275308
}
276309

JavaGUI/src/martin/tempest/core/TSDRLibrary.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class TSDRLibrary {
3030
private int width;
3131
private int height;
3232

33+
public enum SYNC_DIRECTION {ANY, UP, DOWN, LEFT, RIGHT};
34+
3335
volatile private boolean nativerunning = false;
3436

3537
// If the binaries weren't loaded, this will go off
@@ -143,7 +145,7 @@ public TSDRLibrary() throws TSDRException {
143145
public native void setGain(float gain) throws TSDRException;
144146
public native boolean isRunning();
145147
public native void setInvertedColors(boolean invertedEnabled);
146-
148+
public native void sync(int pixels, SYNC_DIRECTION dir);
147149
public native void setResolution(int width, int height, double refreshrate) throws TSDRException;
148150

149151
public void startAsync(final TSDRSource plugin, int width, int height, double refreshrate) throws TSDRException {

TempestSDR/src/TSDRLibrary.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void tsdr_init(tsdr_lib_t * tsdr) {
4141
tsdr->nativerunning = 0;
4242
tsdr->plugin = NULL;
4343
tsdr->centfreq = 0;
44+
tsdr->syncoffset = 0;
4445
}
4546

4647
int tsdr_isrunning(tsdr_lib_t * tsdr) {
@@ -123,6 +124,8 @@ void videodecodingthread(void * ctx) {
123124
float * circbuff = (float *) malloc(sizeof(float) * frames_to_average * bufsize);
124125
int circbuffidx = 0;
125126

127+
int stat;
128+
126129

127130

128131
//if (pix > max) max = pix; else if (pix < min) min = pix;
@@ -153,7 +156,20 @@ void videodecodingthread(void * ctx) {
153156
circbuff = (float *) realloc(circbuff, sizeof(float) * frames_to_average * bufsize);
154157
}
155158

156-
if (cb_rem_blocking(&context->circbuf, &circbuff[circbuffidx*sizetopoll], sizetopoll) == CB_OK) {
159+
// apply synchronisation offset
160+
const int syncoff = context->this->syncoffset;
161+
if (syncoff < 0) {
162+
stat = cb_rem_blocking(&context->circbuf, &circbuff[circbuffidx*sizetopoll], -syncoff);
163+
if (stat == CB_OK) context->this->syncoffset = 0;
164+
165+
stat = cb_rem_blocking(&context->circbuf, &circbuff[circbuffidx*sizetopoll], sizetopoll);
166+
} else if (syncoff > 0) {
167+
stat = cb_rem_blocking(&context->circbuf, &circbuff[circbuffidx*sizetopoll+syncoff], sizetopoll-syncoff);
168+
if (stat == CB_OK) context->this->syncoffset = 0;
169+
} else
170+
stat = cb_rem_blocking(&context->circbuf, &circbuff[circbuffidx*sizetopoll], sizetopoll);
171+
172+
if (stat == CB_OK) {
157173
circbuffidx=((circbuffidx+1) % frames_to_average);
158174

159175
int i, j;
@@ -389,3 +405,29 @@ int tsdr_setresolution(tsdr_lib_t * tsdr, int width, int height, double refreshr
389405
return TSDR_OK;
390406
}
391407

408+
int tsdr_sync(tsdr_lib_t * tsdr, int pixels, int direction) {
409+
if (pixels == 0) return TSDR_OK;
410+
switch(direction) {
411+
case DIRECTION_CUSTOM:
412+
tsdr->syncoffset += pixels;
413+
break;
414+
case DIRECTION_UP:
415+
if (pixels > tsdr->height || pixels < 0) return TSDR_WRONG_VIDEOPARAMS;
416+
tsdr->syncoffset += pixels * tsdr->width;
417+
break;
418+
case DIRECTION_DOWN:
419+
if (pixels > tsdr->height || pixels < 0) return TSDR_WRONG_VIDEOPARAMS;
420+
tsdr->syncoffset -= pixels * tsdr->width;
421+
break;
422+
case DIRECTION_LEFT:
423+
if (pixels > tsdr->width || pixels < 0) return TSDR_WRONG_VIDEOPARAMS;
424+
tsdr->syncoffset+=pixels;
425+
break;
426+
case DIRECTION_RIGHT:
427+
if (pixels > tsdr->width || pixels < 0) return TSDR_WRONG_VIDEOPARAMS;
428+
tsdr->syncoffset-=pixels;
429+
break;
430+
}
431+
return TSDR_OK;
432+
}
433+

TempestSDR/src/include/TSDRLibrary.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
#include <stdint.h>
55

6+
#define DIRECTION_CUSTOM (0)
7+
#define DIRECTION_UP (1)
8+
#define DIRECTION_DOWN (2)
9+
#define DIRECTION_LEFT (3)
10+
#define DIRECTION_RIGHT (4)
11+
612
struct tsdr_lib {
713
void * plugin;
814
void * mutex_sync_unload;
@@ -19,6 +25,7 @@
1925
int frames_to_average;
2026
uint32_t centfreq;
2127
float gain;
28+
volatile int syncoffset;
2229
} typedef tsdr_lib_t;
2330

2431
typedef void(*tsdr_readasync_function)(float *buf, int width, int height, void *ctx);
@@ -32,5 +39,6 @@
3239
int tsdr_unloadplugin(tsdr_lib_t * tsdr);
3340
int tsdr_setresolution(tsdr_lib_t * tsdr, int width, int height, double refreshrate);
3441
int tsdr_isrunning(tsdr_lib_t * tsdr);
42+
int tsdr_sync(tsdr_lib_t * tsdr, int pixels, int direction);
3543

3644
#endif

0 commit comments

Comments
 (0)