From e1f820c3ffe021f1af098fde36e1ff25dbdd0ce8 Mon Sep 17 00:00:00 2001 From: Jan Altensen Date: Sun, 10 May 2020 16:22:47 +0200 Subject: [PATCH] libfmjni: wire it up Change-Id: I7b3bb0f2e2934e324a2a30dcb4aace856f0f0149 --- Android.mk | 1 + libfm_jni.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/Android.mk b/Android.mk index bee193f..23ef5d9 100644 --- a/Android.mk +++ b/Android.mk @@ -21,6 +21,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := \ + FmRadioController_slsi.cpp libfm_jni.cpp LOCAL_SHARED_LIBRARIES := \ diff --git a/libfm_jni.cpp b/libfm_jni.cpp index 0c4e4eb..a46d3cc 100644 --- a/libfm_jni.cpp +++ b/libfm_jni.cpp @@ -16,78 +16,174 @@ #include #include +#include +#include "FmRadioController_slsi.h" #ifdef LOG_TAG #undef LOG_TAG #endif -#define LOG_TAG "FMLIB_JNI" +#define LOG_TAG "FMLIB_SLSI_JNI" + +static FmRadioController_slsi * pFMRadio = NULL; jboolean openDev(JNIEnv *env, jobject thiz) { + pFMRadio = new FmRadioController_slsi(); + + if (pFMRadio->Initialise() == 0) { + ALOGI("%s FM Radio Initialized Successfully\n", __func__); + return JNI_TRUE; + } + + ALOGE("%s failed to initialise FmRadio\n", __func__); + return JNI_FALSE; } jboolean closeDev(JNIEnv *env, jobject thiz) { + delete pFMRadio; + pFMRadio = NULL; + ALOGI("%s FM Radio Un-Initialized Successfully\n", __func__); + + return JNI_TRUE; } jboolean powerUp(JNIEnv *env, jobject thiz, jfloat freq) { + pFMRadio->TuneChannel((int)(freq * 1000.00000000)); + ALOGI("%s [freq=%d] \n", __func__, (int)freq); + + return JNI_TRUE; } jboolean powerDown(JNIEnv *env, jobject thiz, jint type) { + ALOGI("%s \n", __func__); + + return JNI_TRUE; } jboolean tune(JNIEnv *env, jobject thiz, jfloat freq) { + pFMRadio->TuneChannel((int)(freq * 1000.00000000)); + ALOGI("%s [freq=%d] \n", __func__, (int)freq); + + return JNI_TRUE; } jfloat seek(JNIEnv *env, jobject thiz, jfloat freq, jboolean isUp) //jboolean isUp; { + int ret; + if (isup == JNI_TRUE) { + ret = pFMRadio->SeekUp(); + } else { + ret = pFMRadio->SeekDown(); + } + + ALOGI("%s [freq=%d] \n", __func__, ret); + + return roundf((ret/1000.00F) * 100) / 100; } jshortArray autoScan(JNIEnv *env, jobject thiz) { + ALOGD("%s not supported \n", __func__); + + return JNI_FALSE; } jshort readRds(JNIEnv *env, jobject thiz) { + ALOGD("%s not supported \n", __func__); + + return JNI_FALSE; } jbyteArray getPs(JNIEnv *env, jobject thiz) { + ALOGI("%s \n", __func__); + // TODO + jbyteArray PSName; + uint8_t *rt = NULL; + int rt_len = 0; + PSName = env->NewByteArray(rt_len); + env->SetByteArrayRegion(PSName, 0, rt_len, (const jbyte*)rt); + return PSName; } jbyteArray getLrText(JNIEnv *env, jobject thiz) { + ALOGI("%s \n", __func__); + // TODO + jbyteArray PSName; + uint8_t *rt = NULL; + int rt_len = 0; + PSName = env->NewByteArray(rt_len); + env->SetByteArrayRegion(PSName, 0, rt_len, (const jbyte*)rt); + return PSName; } jshort activeAf(JNIEnv *env, jobject thiz) { + ALOGI("%s \n", __func__); + + int ret = pFMRadio->GetChannel(); + + return roundf((ret/1000.00F) * 100) / 100; } jshortArray getAFList(JNIEnv *env, jobject thiz) { + ALOGD("%s not supported \n", __func__); + + return JNI_FALSE; } jint setRds(JNIEnv *env, jobject thiz, jboolean rdson) { + if (rdson == JNI_TRUE) { + pFMRadio->EnableRDS(); + } else { + pFMRadio->DisableRDS(); + } + + ALOGI("%s\n", __func__); + + return JNI_TRUE; } jboolean stopScan(JNIEnv *env, jobject thiz) { + ALOGD("%s not supported \n", __func__); + + return JNI_TRUE; } jint setMute(JNIEnv *env, jobject thiz, jboolean mute) { + if (mute == JNI_TRUE) { + pFMRadio->MuteOn(); + } else { + pFMRadio->MuteOff(); + } + + ALOGI("%s [mute=%d] \n", __func__, (int)mute); + + return JNI_TRUE; } jint isRdsSupport(JNIEnv *env, jobject thiz) { + ALOGD("%s not supported \n", __func__); + + return JNI_FALSE; } jint switchAntenna(JNIEnv *env, jobject thiz, jint antenna) { + ALOGD("%s not supported \n", __func__); + + return JNI_FALSE; } static const char *classPathNameRx = "com/android/fmradio/FmNative"; -- 2.20.1