in the previous chapter we studied FM's Auto FM, Next we'll look at how FM manual FM is conducted. If the FM auto-FM process is not clear, turn on the hyperlink to see the FM search frequency process.
First Look at the flowchart:
2. Slide the Dial Horizontalnumberpicker control in the listener event using the method Valuetofrequency (newval)
1. Long press the left and right arrows centered frequency string, the popup frequencypickerdialog FM dialog box determines the call Tuneradio (frequency) FM.
Get to Frequency
protected int valuetofrequency (int value) { mfrequency = mprefs.getlowerlimit () + value * Mprefs.getfrequencystepsize (); return mfrequency; }
Send a handler callback to a Tuneradio (frequency) FM.
Runnable mradiochangefrequency = new Runnable () {public void run () { mupdatepickervalue = false; Tuneradio (mfrequency); } };
3. Manually click the left and right arrows to listen for calls:
int frequency =fmsharedpreferences.getnexttunefrequency ();
int frequency =fmsharedpreferences.getprevtunefrequency ();
Tuneradio (frequency);
Getnexttunefrequency () method by judging the maximum frequency limit range, plus 200 (scale)
Getprevtunefrequency () method by judging frequency minimum limit range, minus 200 (scale)
Analysis of Frequency modulation method
private void Tuneradio (int frequency)
private void Tuneradio (int frequency) {/* Issue the tune command only if Tunecommand are already not active */if (mservice! = NULL) && (mcommandactive! = cmd_tune) && Isfmon ()) {Boolean bstatus = false; try {bstatus = Mservice.tune (frequency); if (bstatus) {Posttimeouthandler (cmd_tune); }else {if (Isfmon ()) {mcommandfailed = Cmd_tune; LOG.E (LogTag, "Mservice.tune failed"); ShowDialog (dialog_cmd_failed); }}mtunedstation.setname (""); MTUNEDSTATION.SETPI (0); Mtunedstation.setpty (0); Updatestationinfotoui (); }catch (RemoteException e) {e.printstacktrace (); }}else {log.e (LogTag, "Delayed Tune handler stopped"); } }
The tune () method of the Fmradioservice class is called by the callback reference class for FM
Bstatus = Mservice.tune (frequency);
Whether to send a broadcast connection timed out
Posttimeouthandler (Cmd_tune);
Set FM name, update Fmradioui interface information
Mtunedstation.setname ("");
MTUNEDSTATION.SETPI (0);
Mtunedstation.setpty (0);
Updatestationinfotoui ()
(the FM method in Fmradioservice is called by a reference to the class returned by the IFMRADIOSREVICE.AIDL communication mechanism Onbind)
The tune method in Fmradioservice
public boolean tune (int frequency)
public boolean tune (int frequency) { Boolean bcommandsent=false; Double doublefrequency = frequency/1000.00; LOG.D (LogTag, "Tuneradio: " + doublefrequency); if (mreceiver! = null) { mreceiver.setstation (frequency); Bcommandsent = true; } return bcommandsent; }
Call the Setstation method of the FMRECEIVER class FM
public boolean setstation (intfrequencykhz)
public boolean setstation (int frequencykhz) { int ret; Mcontrol.setfreq (frequencykhz); ret = mcontrol.setstation (sFd); if (Ret < 0) { return false; } else { return true; } }
Call the Fmrxcontrols class (FM read console information) to set the frequency
Mcontrol.setfreq (frequencykhz);
Set the frequency at which to optimize the FM core designation
ret = mcontrol.setstation (sFd);
public int setstation (int fd) { log.d (TAG, "* * Tune Using:" +FD); int ret = fmreceiverjni.setfreqnative (FD, mfreq); LOG.D (TAG, "* * returned:" +ret); return ret; }
Finally call the Fmreceiverjni class
Setfreqnative (FD, mfreq); Local method JNI to CPP file
/*native interface */static jint android_hardware_fmradio_fmreceiverjni_setfreqnative (jnienv * env, Jobject thiz, Jint FD, Jint freq) { int err; Double tune; struct v4l2_frequency freq_struct; Freq_struct.type = V4l2_tuner_radio; Freq_struct.frequency = (freq*tune_mult/1000); Err = IOCTL (FD, vidioc_s_frequency, &freq_struct); if (Err < 0) { return fm_jni_failure; } return fm_jni_success;}
Android FM Module Learn the three FM manual FM