コード例 #1
0
    def get_settings(self):
        """Translate the MEM_FORMAT structs into settings in the UI"""
        # Define mem struct write-back shortcuts
        _sets = self._memobj.settings
        _asf = self._memobj.asf
        _ssf = self._memobj.ssf
        _mex = self._memobj.exset
        _chm = self._memobj.ch_mem
        basic = RadioSettingGroup("basic", "Basic Settings")
        pvfo = RadioSettingGroup("pvfo", "VFO Band Edges")
        mena = RadioSettingGroup("mena", "Menu A")
        menb = RadioSettingGroup("menb", "Menu B")
        amode = RadioSettingGroup("amode", "Auto Mode")
        ssc = RadioSettingGroup("ssc", "Slow Scan")
        group = RadioSettings(basic, pvfo, mena, menb, amode, ssc)

        mhz1 = 1000000.

        # Callback functions
        def _my_readonly(setting, obj, atrb):
            """NOP callback, prevents writing the setting"""
            vx = 0
            return

        def my_adjraw(setting, obj, atrb, fix=0, ndx=-1):
            """Callback for Integer add or subtract fix from value."""
            vx = int(str(setting.value))
            value = vx + int(fix)
            if value < 0:
                value = 0
            if ndx < 0:
                setattr(obj, atrb, value)
            else:
                setattr(obj[ndx], atrb, value)
            return

        def my_mhz_val(setting, obj, atrb, ndx=-1):
            """ Callback to set freq back to Htz"""
            vx = float(str(setting.value))
            vx = int(vx * mhz1)
            if ndx < 0:
                setattr(obj, atrb, vx)
            else:
                setattr(obj[ndx], atrb, vx)
            return

        def my_bool(setting, obj, atrb, ndx=-1):
            """ Callback to properly set boolean """
            # set_settings is not setting [indexed] booleans???
            vx = 0
            if str(setting.value) == "True":
                vx = 1
            if ndx < 0:
                setattr(obj, atrb, vx)
            else:
                setattr(obj[ndx], atrb, vx)
            return

        def my_asf_mode(setting, obj, nx=0):
            """ Callback to extract mode and create asmode, asdata """
            v1 = TS480_MODES.index(str(setting.value))
            v2 = 0  # asdata
            vx = v1 + 1  # stored as CAT values, same as xmode
            if v1 == 7:
                vx = 9
            if v1 > 7:  # a Data mode
                v2 = 1
                if v1 == 8:
                    vx = 1  # LSB
                elif v1 == 9:
                    vx = 2  # USB
                elif v1 == 10:
                    vx = 4  # FM
            setattr(obj[nx], "asdata", v2)
            setattr(obj[nx], "asmode", vx)
            return

        def my_fnctns(setting, obj, ndx, atrb):
            """ Filter only valid key function assignments """
            vx = int(str(setting.value))
            if vx > 79:
                vx = 99  # Off
            setattr(obj[ndx], atrb, vx)
            return

        def my_labels(kx):
            lbl = "%03i:" % kx  # SG EX number
            lbl += self.EX_LBL[kx]  # and the label to match
            return lbl

        # ===== BASIC GROUP =====

        options = [
            "TS-480HX (200W)", "TS-480SAT (100W + AT)", "Japanese 50W type",
            "Japanese 20W type"
        ]
        rx = RadioSettingValueString(14, 22, options[_sets.ty])
        rset = RadioSetting("settings.ty", "FirmwareVersion", rx)
        rset.set_apply_callback(_my_readonly, _sets, "ty")
        basic.append(rset)

        rx = RadioSettingValueInteger(0, 255, _sets.ag)
        rset = RadioSetting("settings.ag", "AF Gain", rx)
        #  rset.set_apply_callback(my_adjraw, _sets, "ag", -1)
        basic.append(rset)

        rx = RadioSettingValueInteger(0, 100, _sets.rg)
        rset = RadioSetting("settings.rg", "RF Gain", rx)
        #   rset.set_apply_callback(my_adjraw, _sets, "rg", -1)
        basic.append(rset)

        options = ["ANT1", "ANT2"]
        # CAUTION: an has value of 1 or 2
        rx = RadioSettingValueList(options, options[_sets.an - 1])
        rset = RadioSetting("settings.an", "Antenna Selected", rx)
        # Add 1 to the changed value. S/b 1/2
        rset.set_apply_callback(my_val_list, options, _sets, "an", 1)
        basic.append(rset)

        rx = RadioSettingValueInteger(0, 100, _sets.mg)
        rset = RadioSetting("settings.mg", "Microphone gain", rx)
        basic.append(rset)

        nx = 5  # Coarse step
        if bool(_mex[0].ex021):  # Power Fine enabled in menu A
            nx = 1
        vx = _sets.pc  # Trap invalid values from run_tests.py
        if vx < 5:
            vx = 5
        options = [200, 100, 50, 20]  # subject to firmware
        rx = RadioSettingValueInteger(5, options[_sets.ty], vx, nx)
        sx = "TX Output power (Watts)"
        rset = RadioSetting("settings.pc", sx, rx)
        basic.append(rset)

        val = _sets.fa / mhz1  # valid range is for receiver
        rx = RadioSettingValueFloat(0.05, 60.0, val, 0.001, 3)
        sx = "VFO-A Frequency (MHz)"
        rset = RadioSetting("settings.fa", sx, rx)
        rset.set_apply_callback(my_mhz_val, _sets, "fa")
        basic.append(rset)

        val = _sets.fb / mhz1
        rx = RadioSettingValueFloat(0.05, 60.0, val, 0.001, 3)
        sx = "VFO-B Frequency (MHz)"
        rset = RadioSetting("settings.fb", sx, rx)
        rset.set_apply_callback(my_mhz_val, _sets, "fb")
        basic.append(rset)

        options = ["Menu A", "Menu B"]
        rx = RadioSettingValueList(options, options[_sets.mf])
        sx = "Menu Selected"
        rset = RadioSetting("settings.mf", sx, rx)
        rset.set_apply_callback(my_val_list, options, _sets, "mf")
        basic.append(rset)

        # ==== VFO Edges Group ================

        for mx in range(100, 110):
            val = _chm[mx].rxfreq / mhz1
            if val < 1.8:  # Many operators never use this
                val = 1.8  # So default is 0.0
            rx = RadioSettingValueFloat(1.8, 54.0, val, 0.001, 3)
            sx = "VFO-Band %i lower limit (MHz)" % (mx - 100)
            rset = RadioSetting("ch_mem.rxfreq/%d" % mx, sx, rx)
            rset.set_apply_callback(my_mhz_val, _chm, "rxfreq", mx)
            pvfo.append(rset)

            val = _chm[mx].txfreq / mhz1
            if val < 1.8:
                val = 54.0
            rx = RadioSettingValueFloat(1.8, 54.0, val, 0.001, 3)
            sx = "    VFO-Band %i upper limit (MHz)" % (mx - 100)
            rset = RadioSetting("ch_mem.txfreq/%d" % mx, sx, rx)
            rset.set_apply_callback(my_mhz_val, _chm, "txfreq", mx)
            pvfo.append(rset)

            kx = _chm[mx].xmode
            options = [
                "None", "LSB", "USB", "CW", "FM", "AM", "FSK", "CW-R", "N/A",
                "FSK-R"
            ]
            rx = RadioSettingValueList(options, options[kx])
            sx = "    VFO-Band %i Tx/Rx Mode" % (mx - 100)
            rset = RadioSetting("ch_mem.xmode/%d" % mx, sx, rx)
            rset.set_apply_callback(my_val_list, options, _chm, "xmode", 0, mx)
            pvfo.append(rset)

        # ==== Menu A/B Group =================

        for mx in range(2):  # A/B index
            sx = my_labels(0)
            rx = RadioSettingValueInteger(0, 4, _mex[mx].ex000)
            rset = RadioSetting("exset.ex000", sx, rx)
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            rx = RadioSettingValueInteger(0, 9, _mex[mx].ex012)
            sx = my_labels(12)
            rset = RadioSetting("exset.ex012", sx, rx)
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            sx = my_labels(13)
            rx = RadioSettingValueInteger(0, 9, _mex[mx].ex013)
            rset = RadioSetting("exset.ex013", sx, rx)
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            sx = my_labels(14)
            rx = RadioSettingValueInteger(0, 9, _mex[mx].ex014)
            rset = RadioSetting("exset.ex014", sx, rx)
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            options = ["250", "500", "1000"]
            rx = RadioSettingValueList(options, options[_mex[mx].ex003])
            sx = my_labels(3)
            rset = RadioSetting("exset.ex003/%d" % mx, sx, rx)
            rset.set_apply_callback(my_val_list, options, _mex, "ex003", 0, mx)
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            rx = RadioSettingValueBoolean(bool(_mex[mx].ex007))
            sx = my_labels(7)
            rset = RadioSetting("exset.ex007/%d" % mx, sx, rx)
            rset.set_apply_callback(my_bool, _mex, "ex007", mx)
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            rx = RadioSettingValueBoolean(bool(_mex[mx].ex008))
            sx = my_labels(8)
            rset = RadioSetting("exset.ex008/%d" % mx, sx, rx)
            rset.set_apply_callback(my_bool, _mex, "ex008", mx)
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            options = ["100", "200", "300", "400", "500"]
            rx = RadioSettingValueList(options, options[_mex[mx].ex009])
            sx = my_labels(9)
            rset = RadioSetting("exset.ex009/%d" % mx, sx, rx)
            rset.set_apply_callback(my_val_list, options, _mex, "ex009", 0, mx)
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            rx = RadioSettingValueBoolean(bool(_mex[mx].ex010))
            sx = my_labels(10)
            rset = RadioSetting("exset.ex010/%d" % mx, sx, rx)
            rset.set_apply_callback(my_bool, _mex, "ex010", mx)
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            options = ["TO", "CO"]
            rx = RadioSettingValueList(options, options[_mex[mx].ex011])
            sx = my_labels(11)
            rset = RadioSetting("exset.ex011/%d" % mx, sx, rx)
            rset.set_apply_callback(my_val_list, options, _mex, "ex011", 0, mx)
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            rx = RadioSettingValueBoolean(bool(_mex[mx].ex021))
            sx = my_labels(21)
            rset = RadioSetting("exset.ex021/%d" % mx, sx, rx)
            rset.set_apply_callback(my_bool, _mex, "ex021", mx)
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            options = ["Off", "3", "5", "10", "20", "30"]
            rx = RadioSettingValueList(options, options[_mex[mx].ex022])
            sx = my_labels(22)
            rset = RadioSetting("exset.ex022/%d" % mx, sx, rx)
            rset.set_apply_callback(my_val_list, options, _mex, "ex022", 0, mx)
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            rx = RadioSettingValueInteger(0, 99, _mex[mx].ex048)
            sx = my_labels(48)
            rset = RadioSetting("exset.ex048/%d" % mx, sx, rx)
            rset.set_apply_callback(my_fnctns, _mex, mx, "ex048")
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            rx = RadioSettingValueInteger(0, 99, _mex[mx].ex049)
            sx = my_labels(49)
            rset = RadioSetting("exset.ex049/%d" % mx, sx, rx)
            rset.set_apply_callback(my_fnctns, _mex, mx, "ex049")
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            rx = RadioSettingValueInteger(0, 99, _mex[mx].ex050)
            sx = my_labels(50)
            rset = RadioSetting("exset.ex050/%d" % mx, sx, rx)
            rset.set_apply_callback(my_fnctns, _mex, mx, "ex050")
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            rx = RadioSettingValueInteger(0, 99, _mex[mx].ex051)
            sx = my_labels(51)
            rset = RadioSetting("exset.ex051/%d" % mx, sx, rx)
            rset.set_apply_callback(my_fnctns, _mex, mx, "ex051")
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)

            rx = RadioSettingValueInteger(0, 99, _mex[mx].ex052)
            sx = my_labels(52)
            rset = RadioSetting("exset.ex052/%d" % mx, sx, rx)
            rset.set_apply_callback(my_fnctns, _mex, mx, "ex052")
            if mx == 0:
                mena.append(rset)
            else:
                menb.append(rset)
        # End of for mx loop

        # ==== Auto Scan Params (amode) ==============
        for ix in range(32):
            val = _asf[ix].asfreq / mhz1
            rx = RadioSettingValueFloat(0.03, 60.0, val, 0.001, 3)
            rset = RadioSetting("asf.asfreq/%d" % ix,
                                "Scan %02i Freq (MHz)" % ix, rx)
            rset.set_apply_callback(my_mhz_val, _asf, "asfreq", ix)
            amode.append(rset)

            mx = _asf[ix].asmode - 1  # Same logic as xmode
            if _asf[ix].asmode == 9:
                mx = 7
            rx = RadioSettingValueList(TS480_MODES, TS480_MODES[mx])
            rset = RadioSetting("asf.asmode/%d" % ix, "   Mode", rx)
            rset.set_apply_callback(my_asf_mode, _asf, ix)
            amode.append(rset)

        # ==== Slow Scan Settings ===
        for ix in range(10):  # Chans
            for nx in range(5):  # spots
                px = ((ix * 5) + nx)
                val = _ssf[px].ssfreq / mhz1
                stx = "      -   -   -    Slot %02i Freq (MHz)" % nx
                if nx == 0:
                    stx = "Slow Scan %02i, Slot 0 Freq (MHz" % ix
                rx = RadioSettingValueFloat(0, 54.0, val, 0.001, 3)
                rset = RadioSetting("ssf.ssfreq/%d" % px, stx, rx)
                rset.set_apply_callback(my_mhz_val, _ssf, "ssfreq", px)
                ssc.append(rset)

        return group  # END get_settings()
コード例 #2
0
    def get_settings(self):
        """Translate the bit in the mem_struct into settings in the UI"""
        _mem = self._memobj
        basic = RadioSettingGroup("basic", "Basic Settings")
        other = RadioSettingGroup("other", "Other Settings")
        work = RadioSettingGroup("work", "Work Mode Settings")
        dtmf = RadioSettingGroup("dtmf", "DTMF Settings")
        top = RadioSettings(basic, other, work, dtmf)

        # Basic

        # Audio: A01-A04

        aftone = RadioSetting(
            "settings.aftone", "AF tone control",
            RadioSettingValueList(LIST_AFTONE,
                                  LIST_AFTONE[_mem.settings.aftone]))
        basic.append(aftone)

        spkr = RadioSetting(
            "settings.spkr", "Speaker",
            RadioSettingValueList(LIST_SPKR, LIST_SPKR[_mem.settings.spkr]))
        basic.append(spkr)

        audio = RadioSetting(
            "settings.audio", "Stereo/Mono",
            RadioSettingValueList(LIST_AUDIO, LIST_AUDIO[_mem.settings.audio]))
        basic.append(audio)

        sbmute = RadioSetting(
            "settings.sbmute", "Sub band mute",
            RadioSettingValueList(LIST_SBMUTE,
                                  LIST_SBMUTE[_mem.settings.sbmute]))
        basic.append(sbmute)

        # TX/RX: B01-B08

        mgain = RadioSetting(
            "settings.mgain", "Mic gain",
            RadioSettingValueList(LIST_MLNHM, LIST_MLNHM[_mem.settings.mgain]))
        basic.append(mgain)

        ptt = RadioSetting(
            "settings.ptt", "PTT mode",
            RadioSettingValueList(LIST_PTT, LIST_PTT[_mem.settings.ptt]))
        basic.append(ptt)

        # B03 (per channel)
        # B04 (per channel)

        rxexp = RadioSetting(
            "settings.rxexp", "RX expansion",
            RadioSettingValueList(LIST_RXEXP, LIST_RXEXP[_mem.settings.rxexp]))
        basic.append(rxexp)

        vox = RadioSetting(
            "settings.vox", "Vox",
            RadioSettingValueList(LIST_VOX, LIST_VOX[_mem.settings.vox]))
        basic.append(vox)

        voxs = RadioSetting(
            "settings.voxs", "Vox sensitivity",
            RadioSettingValueList(LIST_MLNHM, LIST_MLNHM[_mem.settings.voxs]))
        basic.append(voxs)

        # B08 (per channel)

        # Display: C01-C06

        display = RadioSetting(
            "settings.display", "Display select",
            RadioSettingValueList(LIST_DISPLAY,
                                  LIST_DISPLAY[_mem.settings.display]))
        basic.append(display)

        lcdb = RadioSetting(
            "settings.lcdb", "LCD brightness",
            RadioSettingValueList(LIST_MINMAX,
                                  LIST_MINMAX[_mem.settings.lcdb]))
        basic.append(lcdb)

        color = RadioSetting(
            "settings.color", "LCD color",
            RadioSettingValueList(LIST_COLOR, LIST_COLOR[_mem.settings.color]))
        basic.append(color)

        lcdc = RadioSetting(
            "settings.lcdc", "LCD contrast",
            RadioSettingValueList(LIST_MINMAX,
                                  LIST_MINMAX[_mem.settings.lcdc]))
        basic.append(lcdc)

        btime = RadioSetting(
            "settings.btime", "LCD backlight time",
            RadioSettingValueList(LIST_BTIME, LIST_BTIME[_mem.settings.btime]))
        basic.append(btime)

        keyb = RadioSetting(
            "settings.keyb", "Key brightness",
            RadioSettingValueList(LIST_MINMAX,
                                  LIST_MINMAX[_mem.settings.keyb]))
        basic.append(keyb)

        # Memory: D01-D04

        # D01 (per channel)
        # D02 (per channel)

        mrscan = RadioSetting(
            "settings.mrscan", "Memory scan type",
            RadioSettingValueList(LIST_MRSCAN,
                                  LIST_MRSCAN[_mem.settings.mrscan]))
        basic.append(mrscan)

        # D04 (per channel)

        # Scan: E01-E04

        dwstop = RadioSetting(
            "settings.dwstop", "Dual watch stop",
            RadioSettingValueList(LIST_DWSTOP,
                                  LIST_DWSTOP[_mem.settings.dwstop]))
        basic.append(dwstop)

        scand = RadioSetting(
            "settings.scand", "Scan direction",
            RadioSettingValueList(LIST_SCAND, LIST_SCAND[_mem.settings.scand]))
        basic.append(scand)

        scanr = RadioSetting(
            "settings.scanr", "Scan resume",
            RadioSettingValueList(LIST_SCANR, LIST_SCANR[_mem.settings.scanr]))
        basic.append(scanr)

        scansb = RadioSetting("settings.scansb", "Scan stop beep",
                              RadioSettingValueBoolean(_mem.settings.scansb))
        basic.append(scansb)

        # System: F01-F09

        apo = RadioSetting(
            "settings.apo", "Automatic power off [hours]",
            RadioSettingValueList(LIST_APO, LIST_APO[_mem.settings.apo]))
        basic.append(apo)

        ars = RadioSetting("settings.ars", "Automatic repeater shift",
                           RadioSettingValueBoolean(_mem.settings.ars))
        basic.append(ars)

        beep = RadioSetting(
            "settings.beep", "Beep volume",
            RadioSettingValueList(LIST_BEEP, LIST_BEEP[_mem.settings.beep]))
        basic.append(beep)

        fkey = RadioSetting(
            "settings.fkey", "F key",
            RadioSettingValueList(LIST_FKEY, LIST_FKEY[_mem.settings.fkey]))
        basic.append(fkey)

        pfkey1 = RadioSetting(
            "settings.pfkey1", "Mic P1 key",
            RadioSettingValueList(LIST_PFKEY,
                                  LIST_PFKEY[_mem.settings.pfkey1]))
        basic.append(pfkey1)

        pfkey2 = RadioSetting(
            "settings.pfkey2", "Mic P2 key",
            RadioSettingValueList(LIST_PFKEY,
                                  LIST_PFKEY[_mem.settings.pfkey2]))
        basic.append(pfkey2)

        pfkey3 = RadioSetting(
            "settings.pfkey3", "Mic P3 key",
            RadioSettingValueList(LIST_PFKEY,
                                  LIST_PFKEY[_mem.settings.pfkey3]))
        basic.append(pfkey3)

        pfkey4 = RadioSetting(
            "settings.pfkey4", "Mic P4 key",
            RadioSettingValueList(LIST_PFKEY,
                                  LIST_PFKEY[_mem.settings.pfkey4]))
        basic.append(pfkey4)

        omode = RadioSetting(
            "settings.omode", "Operation mode",
            RadioSettingValueList(LIST_AB, LIST_AB[_mem.settings.omode]))
        basic.append(omode)

        rxcoverm = RadioSetting(
            "settings.rxcoverm", "RX coverage - memory",
            RadioSettingValueList(LIST_COVERAGE,
                                  LIST_COVERAGE[_mem.settings.rxcoverm]))
        basic.append(rxcoverm)

        rxcoverv = RadioSetting(
            "settings.rxcoverv", "RX coverage - VFO",
            RadioSettingValueList(LIST_COVERAGE,
                                  LIST_COVERAGE[_mem.settings.rxcoverv]))
        basic.append(rxcoverv)

        tot = RadioSetting(
            "settings.tot", "Time out timer [min]",
            RadioSettingValueList(LIST_TOT, LIST_TOT[_mem.settings.tot]))
        basic.append(tot)

        # Timer/Clock: G01-G04

        # G01
        datefmt = RadioSetting(
            "settings.datefmt", "Date format",
            RadioSettingValueList(LIST_DATEFMT,
                                  LIST_DATEFMT[_mem.settings.datefmt]))
        basic.append(datefmt)

        timefmt = RadioSetting(
            "settings.timefmt", "Time format",
            RadioSettingValueList(LIST_TIMEFMT,
                                  LIST_TIMEFMT[_mem.settings.timefmt]))
        basic.append(timefmt)

        timesig = RadioSetting("settings.timesig", "Time signal",
                               RadioSettingValueBoolean(_mem.settings.timesig))
        basic.append(timesig)

        tz = RadioSetting(
            "settings.tz", "Time zone",
            RadioSettingValueList(LIST_TZ, LIST_TZ[_mem.settings.tz]))
        basic.append(tz)

        # Signaling: H01-H06

        bell = RadioSetting(
            "settings.bell", "Bell ringer",
            RadioSettingValueList(LIST_BELL, LIST_BELL[_mem.settings.bell]))
        basic.append(bell)

        # H02 (per channel)

        dtmfmodenc = RadioSetting(
            "settings.dtmfmodenc", "DTMF mode encode",
            RadioSettingValueBoolean(_mem.settings.dtmfmodenc))
        basic.append(dtmfmodenc)

        dtmfmoddec = RadioSetting(
            "settings.dtmfmoddec", "DTMF mode decode",
            RadioSettingValueBoolean(_mem.settings.dtmfmoddec))
        basic.append(dtmfmoddec)

        # H04 (per channel)

        decbandsel = RadioSetting(
            "settings.decbandsel", "DTMF band select",
            RadioSettingValueList(LIST_AB, LIST_AB[_mem.settings.decbandsel]))
        basic.append(decbandsel)

        sqlexp = RadioSetting("settings.sqlexp", "SQL expansion",
                              RadioSettingValueBoolean(_mem.settings.sqlexp))
        basic.append(sqlexp)

        # Pkt: I01-I03

        databnd = RadioSetting(
            "settings.databnd", "Packet data band",
            RadioSettingValueList(LIST_DATABND,
                                  LIST_DATABND[_mem.settings.databnd]))
        basic.append(databnd)

        dataspd = RadioSetting(
            "settings.dataspd", "Packet data speed",
            RadioSettingValueList(LIST_DATASPD,
                                  LIST_DATASPD[_mem.settings.dataspd]))
        basic.append(dataspd)

        datasql = RadioSetting(
            "settings.datasql", "Packet data squelch",
            RadioSettingValueList(LIST_DATASQL,
                                  LIST_DATASQL[_mem.settings.datasql]))
        basic.append(datasql)

        # Other

        dw = RadioSetting("settings.dw", "Dual watch",
                          RadioSettingValueBoolean(_mem.settings.dw))
        other.append(dw)

        cpuclk = RadioSetting(
            "settings.cpuclk", "CPU clock frequency",
            RadioSettingValueList(LIST_CPUCLK,
                                  LIST_CPUCLK[_mem.settings.cpuclk]))
        other.append(cpuclk)

        def _filter(name):
            filtered = ""
            for char in str(name):
                if char in VALID_CHARS:
                    filtered += char
                else:
                    filtered += " "
            return filtered

        line16 = RadioSetting(
            "poweron_msg.line16", "Power-on message",
            RadioSettingValueString(0, 16, _filter(_mem.poweron_msg.line16)))
        other.append(line16)

        line32 = RadioSetting(
            "embedded_msg.line32", "Embedded message",
            RadioSettingValueString(0, 32, _filter(_mem.embedded_msg.line32)))
        other.append(line32)

        # Work

        workmoda = RadioSetting(
            "settings.workmoda", "Work mode A",
            RadioSettingValueList(LIST_WORK,
                                  LIST_WORK[_mem.settings.workmoda]))
        work.append(workmoda)

        workmodb = RadioSetting(
            "settings.workmodb", "Work mode B",
            RadioSettingValueList(LIST_WORK,
                                  LIST_WORK[_mem.settings.workmodb]))
        work.append(workmodb)

        wbanda = RadioSetting(
            "settings.wbanda", "Work band A",
            RadioSettingValueList(LIST_WBANDA,
                                  LIST_WBANDA[(_mem.settings.wbanda) - 1]))
        work.append(wbanda)

        wbandb = RadioSetting(
            "settings.wbandb", "Work band B",
            RadioSettingValueList(LIST_WBANDB,
                                  LIST_WBANDB[(_mem.settings.wbandb) - 4]))
        work.append(wbandb)

        sqla = RadioSetting(
            "settings.sqla", "Squelch A",
            RadioSettingValueList(LIST_SQL, LIST_SQL[_mem.settings.sqla]))
        work.append(sqla)

        sqlb = RadioSetting(
            "settings.sqlb", "Squelch B",
            RadioSettingValueList(LIST_SQL, LIST_SQL[_mem.settings.sqlb]))
        work.append(sqlb)

        stepa = RadioSetting(
            "settings.stepa", "Auto step A",
            RadioSettingValueList(LIST_STEP, LIST_STEP[_mem.settings.stepa]))
        work.append(stepa)

        stepb = RadioSetting(
            "settings.stepb", "Auto step B",
            RadioSettingValueList(LIST_STEP, LIST_STEP[_mem.settings.stepb]))
        work.append(stepb)

        mrcha = RadioSetting(
            "settings.mrcha", "Current channel A",
            RadioSettingValueInteger(0, 499, _mem.settings.mrcha))
        work.append(mrcha)

        mrchb = RadioSetting(
            "settings.mrchb", "Current channel B",
            RadioSettingValueInteger(0, 499, _mem.settings.mrchb))
        work.append(mrchb)

        val = _mem.settings.offseta / 100.00
        offseta = RadioSetting("settings.offseta", "Offset A (0-37.95)",
                               RadioSettingValueFloat(0, 38.00, val, 0.05, 2))
        work.append(offseta)

        val = _mem.settings.offsetb / 100.00
        offsetb = RadioSetting("settings.offsetb", "Offset B (0-79.95)",
                               RadioSettingValueFloat(0, 80.00, val, 0.05, 2))
        work.append(offsetb)

        wpricha = RadioSetting(
            "settings.wpricha", "Priority channel A",
            RadioSettingValueInteger(0, 499, _mem.settings.wpricha))
        work.append(wpricha)

        wprichb = RadioSetting(
            "settings.wprichb", "Priority channel B",
            RadioSettingValueInteger(0, 499, _mem.settings.wprichb))
        work.append(wprichb)

        smode = RadioSetting(
            "settings.smode", "Smart function mode",
            RadioSettingValueList(LIST_SMODE, LIST_SMODE[_mem.settings.smode]))
        work.append(smode)

        # dtmf

        ttdkey = RadioSetting(
            "dtmf.ttdkey", "D key function",
            RadioSettingValueList(LIST_TTDKEY, LIST_TTDKEY[_mem.dtmf.ttdkey]))
        dtmf.append(ttdkey)

        ttdgt = RadioSetting(
            "dtmf.ttdgt", "Digit time",
            RadioSettingValueList(LIST_TT200,
                                  LIST_TT200[(_mem.dtmf.ttdgt) - 5]))
        dtmf.append(ttdgt)

        ttint = RadioSetting(
            "dtmf.ttint", "Interval time",
            RadioSettingValueList(LIST_TT200,
                                  LIST_TT200[(_mem.dtmf.ttint) - 5]))
        dtmf.append(ttint)

        tt1stdgt = RadioSetting(
            "dtmf.tt1stdgt", "1st digit time",
            RadioSettingValueList(LIST_TT200,
                                  LIST_TT200[(_mem.dtmf.tt1stdgt) - 5]))
        dtmf.append(tt1stdgt)

        tt1stdly = RadioSetting(
            "dtmf.tt1stdly", "1st digit delay time",
            RadioSettingValueList(LIST_TT1000,
                                  LIST_TT1000[(_mem.dtmf.tt1stdly) - 2]))
        dtmf.append(tt1stdly)

        ttdlyqt = RadioSetting(
            "dtmf.ttdlyqt", "Digit delay when use qt",
            RadioSettingValueList(LIST_TT1000,
                                  LIST_TT1000[(_mem.dtmf.ttdlyqt) - 2]))
        dtmf.append(ttdlyqt)

        ttsig = RadioSetting(
            "dtmf2.ttsig", "Signal",
            RadioSettingValueList(LIST_TTSIG, LIST_TTSIG[_mem.dtmf2.ttsig]))
        dtmf.append(ttsig)

        ttautorst = RadioSetting(
            "dtmf2.ttautorst", "Auto reset time",
            RadioSettingValueList(LIST_TTAUTORST,
                                  LIST_TTAUTORST[_mem.dtmf2.ttautorst]))
        dtmf.append(ttautorst)

        if _mem.dtmf2.ttgrpcode > 0x06:
            val = 0x00
        else:
            val = _mem.dtmf2.ttgrpcode
        ttgrpcode = RadioSetting(
            "dtmf2.ttgrpcode", "Group code",
            RadioSettingValueList(LIST_TTGRPCODE, LIST_TTGRPCODE[val]))
        dtmf.append(ttgrpcode)

        ttintcode = RadioSetting(
            "dtmf2.ttintcode", "Interval code",
            RadioSettingValueList(LIST_TTINTCODE,
                                  LIST_TTINTCODE[_mem.dtmf2.ttintcode]))
        dtmf.append(ttintcode)

        if _mem.dtmf2.ttalert > 0x04:
            val = 0x00
        else:
            val = _mem.dtmf2.ttalert
        ttalert = RadioSetting(
            "dtmf2.ttalert", "Alert tone/transpond",
            RadioSettingValueList(LIST_TTALERT, LIST_TTALERT[val]))
        dtmf.append(ttalert)

        ttautod = RadioSetting(
            "dtmf.ttautod", "Auto dial group",
            RadioSettingValueList(LIST_TTAUTOD,
                                  LIST_TTAUTOD[_mem.dtmf.ttautod]))
        dtmf.append(ttautod)

        # setup 9 dtmf autodial entries
        for i in map(str, range(1, 10)):
            objname = "code" + i
            strname = "Code " + str(i)
            dtmfsetting = getattr(_mem.dtmfcode, objname)
            dtmflen = getattr(_mem.dtmfcode, objname + "_len")
            dtmfstr = self._bbcd2dtmf(dtmfsetting, dtmflen)
            code = RadioSettingValueString(0, 16, dtmfstr)
            code.set_charset(DTMF_CHARS + list(" "))
            rs = RadioSetting("dtmfcode." + objname, strname, code)
            dtmf.append(rs)
        return top
コード例 #3
0
    def get_settings(self):
        """Translate the bit in the mem_struct into settings in the UI"""
        _mem = self._memobj
        basic = RadioSettingGroup("basic", "Basic Settings")
        advanced = RadioSettingGroup("advanced", "Advanced Settings")
        other = RadioSettingGroup("other", "Other Settings")
        work = RadioSettingGroup("work", "Work Mode Settings")
        fm_preset = RadioSettingGroup("fm_preset", "FM Preset")
        dtmfe = RadioSettingGroup("dtmfe", "DTMF Encode Settings")
        service = RadioSettingGroup("service", "Service Settings")
        top = RadioSettings(basic, advanced, other, work, fm_preset, dtmfe,
                            service)

        # Basic settings
        if _mem.settings.squelch > 0x09:
            val = 0x00
        else:
            val = _mem.settings.squelch
        rs = RadioSetting(
            "settings.squelch", "Squelch",
            RadioSettingValueList(LIST_OFF1TO9, LIST_OFF1TO9[val]))
        basic.append(rs)

        if _mem.settings.save > 0x04:
            val = 0x00
        else:
            val = _mem.settings.save
        rs = RadioSetting("settings.save", "Battery Saver",
                          RadioSettingValueList(LIST_SAVE, LIST_SAVE[val]))
        basic.append(rs)

        if _mem.settings.vox > 0x0A:
            val = 0x00
        else:
            val = _mem.settings.vox
        rs = RadioSetting(
            "settings.vox", "Vox",
            RadioSettingValueList(LIST_OFF1TO10, LIST_OFF1TO10[val]))
        basic.append(rs)

        if _mem.settings.abr > 0x0A:
            val = 0x00
        else:
            val = _mem.settings.abr
        rs = RadioSetting(
            "settings.abr", "Backlight Timeout",
            RadioSettingValueList(LIST_OFF1TO10, LIST_OFF1TO10[val]))
        basic.append(rs)

        rs = RadioSetting("settings.tdr", "Dual Watch",
                          RadioSettingValueBoolean(_mem.settings.tdr))
        basic.append(rs)

        rs = RadioSetting("settings.beep", "Beep",
                          RadioSettingValueBoolean(_mem.settings.beep))
        basic.append(rs)

        if _mem.settings.timeout > 0x27:
            val = 0x03
        else:
            val = _mem.settings.timeout
        rs = RadioSetting(
            "settings.timeout", "Timeout Timer",
            RadioSettingValueList(LIST_TIMEOUT, LIST_TIMEOUT[val]))
        basic.append(rs)

        if _mem.settings.voice > 0x02:
            val = 0x01
        else:
            val = _mem.settings.voice
        rs = RadioSetting("settings.voice", "Voice Prompt",
                          RadioSettingValueList(LIST_VOICE, LIST_VOICE[val]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.dtmfst", "DTMF Sidetone",
            RadioSettingValueList(LIST_DTMFST,
                                  LIST_DTMFST[_mem.settings.dtmfst]))
        basic.append(rs)

        if _mem.settings.screv > 0x02:
            val = 0x01
        else:
            val = _mem.settings.screv
        rs = RadioSetting("settings.screv", "Scan Resume",
                          RadioSettingValueList(LIST_RESUME, LIST_RESUME[val]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.pttid", "When to send PTT ID",
            RadioSettingValueList(LIST_PTTID, LIST_PTTID[_mem.settings.pttid]))
        basic.append(rs)

        if _mem.settings.pttlt > 0x1E:
            val = 0x05
        else:
            val = _mem.settings.pttlt
        rs = RadioSetting("pttlt", "PTT ID Delay",
                          RadioSettingValueInteger(0, 50, val))
        basic.append(rs)

        rs = RadioSetting(
            "settings.mdfa", "Display Mode (A)",
            RadioSettingValueList(LIST_MODE, LIST_MODE[_mem.settings.mdfa]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.mdfb", "Display Mode (B)",
            RadioSettingValueList(LIST_MODE, LIST_MODE[_mem.settings.mdfb]))
        basic.append(rs)

        rs = RadioSetting("settings.sync", "Sync A & B",
                          RadioSettingValueBoolean(_mem.settings.sync))
        basic.append(rs)

        rs = RadioSetting(
            "settings.wtled", "Standby LED Color",
            RadioSettingValueList(LIST_COLOR, LIST_COLOR[_mem.settings.wtled]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.rxled", "RX LED Color",
            RadioSettingValueList(LIST_COLOR, LIST_COLOR[_mem.settings.rxled]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.txled", "TX LED Color",
            RadioSettingValueList(LIST_COLOR, LIST_COLOR[_mem.settings.txled]))
        basic.append(rs)

        val = _mem.settings.almod
        rs = RadioSetting("settings.almod", "Alarm Mode",
                          RadioSettingValueList(LIST_ALMOD, LIST_ALMOD[val]))
        basic.append(rs)

        rs = RadioSetting("settings.dbptt", "Double PTT",
                          RadioSettingValueBoolean(_mem.settings.dbptt))
        basic.append(rs)

        rs = RadioSetting("settings.ste", "Squelch Tail Eliminate (HT to HT)",
                          RadioSettingValueBoolean(_mem.settings.ste))
        basic.append(rs)

        rs = RadioSetting(
            "settings.ponmsg", "Power-On Message",
            RadioSettingValueList(LIST_PONMSG,
                                  LIST_PONMSG[_mem.settings.ponmsg]))
        basic.append(rs)

        rs = RadioSetting("settings.roger", "Roger Beep",
                          RadioSettingValueBoolean(_mem.settings.roger))
        basic.append(rs)

        rs = RadioSetting(
            "settings.rtone", "Tone Burst Frequency",
            RadioSettingValueList(LIST_RTONE, LIST_RTONE[_mem.settings.rtone]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.rogerrx", "Roger Beep (RX)",
            RadioSettingValueList(LIST_OFFAB,
                                  LIST_OFFAB[_mem.settings.rogerrx]))
        basic.append(rs)

        # Advanced settings
        rs = RadioSetting("settings.reset", "RESET Menu",
                          RadioSettingValueBoolean(_mem.settings.reset))
        advanced.append(rs)

        rs = RadioSetting("settings.menu", "All Menus",
                          RadioSettingValueBoolean(_mem.settings.menu))
        advanced.append(rs)

        rs = RadioSetting("settings.fmradio", "Broadcast FM Radio",
                          RadioSettingValueBoolean(_mem.settings.fmradio))
        advanced.append(rs)

        rs = RadioSetting("settings.alarm", "Alarm Sound",
                          RadioSettingValueBoolean(_mem.settings.alarm))
        advanced.append(rs)

        # Other settings
        def _filter(name):
            filtered = ""
            for char in str(name):
                if char in chirp_common.CHARSET_ASCII:
                    filtered += char
                else:
                    filtered += " "
            return filtered

        _msg = _mem.firmware_msg
        val = RadioSettingValueString(0, 7, _filter(_msg.line1))
        val.set_mutable(False)
        rs = RadioSetting("firmware_msg.line1", "Firmware Message 1", val)
        other.append(rs)

        val = RadioSettingValueString(0, 7, _filter(_msg.line2))
        val.set_mutable(False)
        rs = RadioSetting("firmware_msg.line2", "Firmware Message 2", val)
        other.append(rs)

        _msg = _mem.sixpoweron_msg
        val = RadioSettingValueString(0, 7, _filter(_msg.line1))
        val.set_mutable(False)
        rs = RadioSetting("sixpoweron_msg.line1", "6+Power-On Message 1", val)
        other.append(rs)
        val = RadioSettingValueString(0, 7, _filter(_msg.line2))
        val.set_mutable(False)
        rs = RadioSetting("sixpoweron_msg.line2", "6+Power-On Message 2", val)
        other.append(rs)

        _msg = _mem.poweron_msg
        rs = RadioSetting("poweron_msg.line1", "Power-On Message 1",
                          RadioSettingValueString(0, 7, _filter(_msg.line1)))
        other.append(rs)
        rs = RadioSetting("poweron_msg.line2", "Power-On Message 2",
                          RadioSettingValueString(0, 7, _filter(_msg.line2)))
        other.append(rs)

        # Work mode settings
        rs = RadioSetting(
            "settings.displayab", "Display",
            RadioSettingValueList(LIST_AB, LIST_AB[_mem.settings.displayab]))
        work.append(rs)

        rs = RadioSetting("settings.keylock", "Keypad Lock",
                          RadioSettingValueBoolean(_mem.settings.keylock))
        work.append(rs)

        rs = RadioSetting(
            "wmchannel.mrcha", "MR A Channel",
            RadioSettingValueInteger(1, 15, _mem.wmchannel.mrcha))
        work.append(rs)

        rs = RadioSetting(
            "wmchannel.mrchb", "MR B Channel",
            RadioSettingValueInteger(1, 15, _mem.wmchannel.mrchb))
        work.append(rs)

        # broadcast FM settings
        _fm_presets = self._memobj.fm_presets
        if _fm_presets <= 108.0 * 10 - 650:
            preset = _fm_presets / 10.0 + 65
        elif _fm_presets >= 65.0 * 10 and _fm_presets <= 108.0 * 10:
            preset = _fm_presets / 10.0
        else:
            preset = 76.0
        rs = RadioSetting("fm_presets", "FM Preset(MHz)",
                          RadioSettingValueFloat(65, 108.0, preset, 0.1, 1))
        fm_preset.append(rs)

        # DTMF settings
        def apply_code(setting, obj, length):
            code = []
            for j in range(0, length):
                try:
                    code.append(DTMF_CHARS.index(str(setting.value)[j]))
                except IndexError:
                    code.append(0xFF)
            obj.code = code

        for i in range(0, 15):
            _codeobj = self._memobj.pttid[i].code
            _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
            val = RadioSettingValueString(0, 5, _code, False)
            val.set_charset(DTMF_CHARS)
            pttid = RadioSetting("pttid/%i.code" % i,
                                 "Signal Code %i" % (i + 1), val)
            pttid.set_apply_callback(apply_code, self._memobj.pttid[i], 5)
            dtmfe.append(pttid)

        if _mem.ani.dtmfon > 0xC3:
            val = 0x03
        else:
            val = _mem.ani.dtmfon
        rs = RadioSetting(
            "ani.dtmfon", "DTMF Speed (on)",
            RadioSettingValueList(LIST_DTMFSPEED, LIST_DTMFSPEED[val]))
        dtmfe.append(rs)

        if _mem.ani.dtmfoff > 0xC3:
            val = 0x03
        else:
            val = _mem.ani.dtmfoff
        rs = RadioSetting(
            "ani.dtmfoff", "DTMF Speed (off)",
            RadioSettingValueList(LIST_DTMFSPEED, LIST_DTMFSPEED[val]))
        dtmfe.append(rs)

        _codeobj = self._memobj.ani.code
        _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 5, _code, False)
        val.set_charset(DTMF_CHARS)
        rs = RadioSetting("ani.code", "ANI Code", val)
        rs.set_apply_callback(apply_code, self._memobj.ani, 5)
        dtmfe.append(rs)

        rs = RadioSetting(
            "ani.aniid", "When to send ANI ID",
            RadioSettingValueList(LIST_PTTID, LIST_PTTID[_mem.ani.aniid]))
        dtmfe.append(rs)

        # Service settings
        for index in range(0, 10):
            key = "squelch.vhf.sql%i" % (index)
            _obj = self._memobj.squelch.vhf
            val = RadioSettingValueInteger(0, 123,
                                           getattr(_obj, "sql%i" % (index)))
            if index == 0:
                val.set_mutable(False)
            name = "Squelch %i" % (index)
            rs = RadioSetting(key, name, val)
            service.append(rs)

        return top
コード例 #4
0
    def get_settings(self):
        _settings = self._memobj.settings
        basic = RadioSettingGroup("basic", "Basic Settings")

        group = RadioSettings(basic)

        options = ["Time", "Carrier", "Search"]
        rs = RadioSetting(
            "scantype", "Scan Type",
            RadioSettingValueList(options, options[_settings.scantype]))
        basic.append(rs)

        options = ["Off"] + ["%s min" % x for x in range(1, 8)]
        rs = RadioSetting(
            "timeout", "Time Out Timer",
            RadioSettingValueList(options, options[_settings.timeout]))
        basic.append(rs)

        options = ["A", "B"]
        rs = RadioSetting(
            "freqmode_ab", "Frequency Mode",
            RadioSettingValueList(options, options[_settings.freqmode_ab]))
        basic.append(rs)

        options = ["Frequency Mode", "Channel Mode"]
        rs = RadioSetting(
            "workmode_a", "Radio Work Mode(A)",
            RadioSettingValueList(options, options[_settings.workmode_a]))
        basic.append(rs)

        rs = RadioSetting(
            "workmode_b", "Radio Work Mode(B)",
            RadioSettingValueList(options, options[_settings.workmode_b]))
        basic.append(rs)

        options = ["Frequency", "Name", "Channel"]
        rs = RadioSetting(
            "mdf_a", "Display Format(F1)",
            RadioSettingValueList(options, options[_settings.mdf_a]))
        basic.append(rs)

        rs = RadioSetting(
            "mdf_b", "Display Format(F2)",
            RadioSettingValueList(options, options[_settings.mdf_b]))
        basic.append(rs)

        rs = RadioSetting(
            "mem_chan_a", "Mem Channel (A)",
            RadioSettingValueInteger(1, 99, _settings.mem_chan_a))
        basic.append(rs)

        rs = RadioSetting(
            "mem_chan_b", "Mem Channel (B)",
            RadioSettingValueInteger(1, 99, _settings.mem_chan_b))
        basic.append(rs)

        options = ["Off", "BOT", "EOT", "Both"]
        rs = RadioSetting(
            "pttid", "PTT-ID",
            RadioSettingValueList(options, options[_settings.pttid]))
        basic.append(rs)

        dtmfchars = "0123456789ABCD*#"
        _codeobj = self._memobj.pttid.code
        _code = "".join([dtmfchars[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 6, _code, False)
        val.set_charset(dtmfchars)
        rs = RadioSetting("pttid.code", "PTT-ID Code", val)

        def apply_code(setting, obj):
            code = []
            for j in range(0, 6):
                try:
                    code.append(dtmfchars.index(str(setting.value)[j]))
                except IndexError:
                    code.append(0xFF)
            obj.code = code

        rs.set_apply_callback(apply_code, self._memobj.pttid)
        basic.append(rs)

        rs = RadioSetting("squelch", "Squelch Level",
                          RadioSettingValueInteger(0, 9, _settings.squelch))
        basic.append(rs)

        rs = RadioSetting("vox", "VOX Level",
                          RadioSettingValueInteger(0, 9, _settings.vox))
        basic.append(rs)

        options = ["Frequency Mode", "Channel Mode"]
        rs = RadioSetting(
            "workmode_fm", "FM Work Mode",
            RadioSettingValueList(options, options[_settings.workmode_fm]))
        basic.append(rs)

        options = ["Current Frequency", "F1 Frequency", "F2 Frequency"]
        rs = RadioSetting(
            "txtdr", "Dual Standby TX Priority",
            RadioSettingValueList(options, options[_settings.txtdr]))
        basic.append(rs)

        options = ["English", "Chinese"]
        rs = RadioSetting(
            "language", "Language",
            RadioSettingValueList(options, options[_settings.language]))
        basic.append(rs)

        rs = RadioSetting("tdr", "Dual Standby",
                          RadioSettingValueBoolean(_settings.tdr))
        basic.append(rs)

        rs = RadioSetting("roger", "Roger Beep",
                          RadioSettingValueBoolean(_settings.roger))
        basic.append(rs)

        rs = RadioSetting("backlight", "Backlight",
                          RadioSettingValueBoolean(_settings.backlight))
        basic.append(rs)

        rs = RadioSetting("save_funct", "Save Mode",
                          RadioSettingValueBoolean(_settings.save_funct))
        basic.append(rs)

        rs = RadioSetting("fm", "FM Function",
                          RadioSettingValueBoolean(_settings.fm))
        basic.append(rs)

        rs = RadioSetting(
            "beep_tone_disabled", "Beep Prompt",
            RadioSettingValueBoolean(not _settings.beep_tone_disabled))
        basic.append(rs)

        rs = RadioSetting("voice_prompt", "Voice Prompt",
                          RadioSettingValueBoolean(_settings.voice_prompt))
        basic.append(rs)

        rs = RadioSetting("sidetone", "DTMF Side Tone",
                          RadioSettingValueBoolean(_settings.sidetone))
        basic.append(rs)

        rs = RadioSetting("ste_disabled", "Squelch Tail Eliminate",
                          RadioSettingValueBoolean(not _settings.ste_disabled))
        basic.append(rs)

        _limit = int(self._memobj.limits.lower_vhf) / 10
        rs = RadioSetting("limits.lower_vhf", "VHF Lower Limit (MHz)",
                          RadioSettingValueInteger(128, 270, _limit))

        def apply_limit(setting, obj):
            value = int(setting.value) * 10
            obj.lower_vhf = value

        rs.set_apply_callback(apply_limit, self._memobj.limits)
        basic.append(rs)

        _limit = int(self._memobj.limits.upper_vhf) / 10
        rs = RadioSetting("limits.upper_vhf", "VHF Upper Limit (MHz)",
                          RadioSettingValueInteger(128, 270, _limit))

        def apply_limit(setting, obj):
            value = int(setting.value) * 10
            obj.upper_vhf = value

        rs.set_apply_callback(apply_limit, self._memobj.limits)
        basic.append(rs)

        _limit = int(self._memobj.limits.lower_uhf) / 10
        rs = RadioSetting("limits.lower_uhf", "UHF Lower Limit (MHz)",
                          RadioSettingValueInteger(400, 520, _limit))

        def apply_limit(setting, obj):
            value = int(setting.value) * 10
            obj.lower_uhf = value

        rs.set_apply_callback(apply_limit, self._memobj.limits)
        basic.append(rs)

        _limit = int(self._memobj.limits.upper_uhf) / 10
        rs = RadioSetting("limits.upper_uhf", "UHF Upper Limit (MHz)",
                          RadioSettingValueInteger(400, 520, _limit))

        def apply_limit(setting, obj):
            value = int(setting.value) * 10
            obj.upper_uhf = value

        rs.set_apply_callback(apply_limit, self._memobj.limits)
        basic.append(rs)

        fm_preset = RadioSettingGroup("fm_preset", "FM Radio Presets")
        group.append(fm_preset)

        for i in range(0, 16):
            if self._memobj.fm_presets[i] < 0x01AF:
                used = True
                preset = self._memobj.fm_presets[i] / 10.0 + 65
            else:
                used = False
                preset = 65
            rs = RadioSetting("fm_presets_%1i" % i, "FM Preset %i" % (i + 1),
                              RadioSettingValueBoolean(used),
                              RadioSettingValueFloat(65, 108, preset, 0.1, 1))
            fm_preset.append(rs)

        testmode = RadioSettingGroup("testmode", "Test Mode Settings")
        group.append(testmode)

        vhfdata = [
            "136-139", "140-144", "145-149", "150-154", "155-159", "160-164",
            "165-169", "170-174"
        ]
        uhfdata = [
            "400-409", "410-419", "420-429", "430-439", "440-449", "450-459",
            "460-469", "470-479"
        ]
        powernamedata = ["Hi", "Lo"]
        powerkeydata = ["hipwr", "lopwr"]

        for power in range(0, 2):
            for index in range(0, 8):
                key = "test.vhf%s%i" % (powerkeydata[power], index)
                name = "%s Mhz %s Power" % (vhfdata[index],
                                            powernamedata[power])
                rs = RadioSetting(
                    key, name,
                    RadioSettingValueInteger(
                        0, 255,
                        getattr(self._memobj.test,
                                "vhf%s%i" % (powerkeydata[power], index))))
                testmode.append(rs)

        for power in range(0, 2):
            for index in range(0, 8):
                key = "test.uhf%s%i" % (powerkeydata[power], index)
                name = "%s Mhz %s Power" % (uhfdata[index],
                                            powernamedata[power])
                rs = RadioSetting(
                    key, name,
                    RadioSettingValueInteger(
                        0, 255,
                        getattr(self._memobj.test,
                                "uhf%s%i" % (powerkeydata[power], index))))
                testmode.append(rs)

        for band in ["vhf", "uhf"]:
            for index in range(0, 10):
                key = "test.%ssquelch%i" % (band, index)
                name = "%s Squelch %i" % (band.upper(), index)
                rs = RadioSetting(
                    key, name,
                    RadioSettingValueInteger(
                        0, 255,
                        getattr(self._memobj.test,
                                "%ssquelch%i" % (band, index))))
                testmode.append(rs)

        return group
コード例 #5
0
    def get_settings(self):
        """Translate the bit in the mem_struct into settings in the UI"""
        _mem = self._memobj
        basic = RadioSettingGroup("basic", "Basic Settings")
        advanced = RadioSettingGroup("advanced", "Advanced Settings")
        other = RadioSettingGroup("other", "Other Settings")
        work = RadioSettingGroup("work", "Work Mode Settings")
        fm_preset = RadioSettingGroup("fm_preset", "FM Preset")
        dtmfe = RadioSettingGroup("dtmfe", "DTMF Encode Settings")
        service = RadioSettingGroup("service", "Service Settings")
        top = RadioSettings(basic, advanced, other, work, fm_preset, dtmfe,
                            service)

        # Basic settings
        if _mem.settings.squelch > 0x09:
            val = 0x00
        else:
            val = _mem.settings.squelch
        rs = RadioSetting(
            "settings.squelch", "Squelch",
            RadioSettingValueList(LIST_OFF1TO9, LIST_OFF1TO9[val]))
        basic.append(rs)

        if _mem.settings.save > 0x04:
            val = 0x00
        else:
            val = _mem.settings.save
        rs = RadioSetting("settings.save", "Battery Saver",
                          RadioSettingValueList(LIST_SAVE, LIST_SAVE[val]))
        basic.append(rs)

        if _mem.settings.vox > 0x0A:
            val = 0x00
        else:
            val = _mem.settings.vox
        rs = RadioSetting(
            "settings.vox", "Vox",
            RadioSettingValueList(LIST_OFF1TO10, LIST_OFF1TO10[val]))
        basic.append(rs)

        if _mem.settings.abr > 0x0A:
            val = 0x00
        else:
            val = _mem.settings.abr
        rs = RadioSetting(
            "settings.abr", "Backlight Timeout",
            RadioSettingValueList(LIST_OFF1TO10, LIST_OFF1TO10[val]))
        basic.append(rs)

        rs = RadioSetting("settings.tdr", "Dual Watch",
                          RadioSettingValueBoolean(_mem.settings.tdr))
        basic.append(rs)

        rs = RadioSetting("settings.beep", "Beep",
                          RadioSettingValueBoolean(_mem.settings.beep))
        basic.append(rs)

        if _mem.settings.timeout > 0x27:
            val = 0x03
        else:
            val = _mem.settings.timeout
        rs = RadioSetting(
            "settings.timeout", "Timeout Timer",
            RadioSettingValueList(LIST_TIMEOUT, LIST_TIMEOUT[val]))
        basic.append(rs)

        if _mem.settings.voice > 0x02:
            val = 0x01
        else:
            val = _mem.settings.voice
        rs = RadioSetting("settings.voice", "Voice Prompt",
                          RadioSettingValueList(LIST_VOICE, LIST_VOICE[val]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.dtmfst", "DTMF Sidetone",
            RadioSettingValueList(LIST_DTMFST,
                                  LIST_DTMFST[_mem.settings.dtmfst]))
        basic.append(rs)

        if _mem.settings.screv > 0x02:
            val = 0x01
        else:
            val = _mem.settings.screv
        rs = RadioSetting("settings.screv", "Scan Resume",
                          RadioSettingValueList(LIST_RESUME, LIST_RESUME[val]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.pttid", "When to send PTT ID",
            RadioSettingValueList(LIST_PTTID, LIST_PTTID[_mem.settings.pttid]))
        basic.append(rs)

        if _mem.settings.pttlt > 0x1E:
            val = 0x05
        else:
            val = _mem.settings.pttlt
        rs = RadioSetting("pttlt", "PTT ID Delay",
                          RadioSettingValueInteger(0, 50, val))
        basic.append(rs)

        rs = RadioSetting(
            "settings.mdfa", "Display Mode (A)",
            RadioSettingValueList(LIST_MODE, LIST_MODE[_mem.settings.mdfa]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.mdfb", "Display Mode (B)",
            RadioSettingValueList(LIST_MODE, LIST_MODE[_mem.settings.mdfb]))
        basic.append(rs)

        rs = RadioSetting("settings.autolk", "Auto Lock Keypad",
                          RadioSettingValueBoolean(_mem.settings.autolk))
        basic.append(rs)

        rs = RadioSetting(
            "settings.wtled", "Standby LED Color",
            RadioSettingValueList(LIST_COLOR, LIST_COLOR[_mem.settings.wtled]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.rxled", "RX LED Color",
            RadioSettingValueList(LIST_COLOR, LIST_COLOR[_mem.settings.rxled]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.txled", "TX LED Color",
            RadioSettingValueList(LIST_COLOR, LIST_COLOR[_mem.settings.txled]))
        basic.append(rs)

        if _mem.settings.almod > 0x02:
            val = 0x00
        else:
            val = _mem.settings.almod
        rs = RadioSetting("settings.almod", "Alarm Mode",
                          RadioSettingValueList(LIST_ALMOD, LIST_ALMOD[val]))
        basic.append(rs)

        if _mem.settings.tcall > 0x05:
            val = 0x00
        else:
            val = _mem.settings.tcall
        rs = RadioSetting("settings.tcall", "Tone Burst Frequency",
                          RadioSettingValueList(LIST_TCALL, LIST_TCALL[val]))
        basic.append(rs)

        rs = RadioSetting("settings.ste", "Squelch Tail Eliminate (HT to HT)",
                          RadioSettingValueBoolean(_mem.settings.ste))
        basic.append(rs)

        if _mem.settings.rpste > 0x0A:
            val = 0x00
        else:
            val = _mem.settings.rpste
        rs = RadioSetting("settings.rpste",
                          "Squelch Tail Eliminate (repeater)",
                          RadioSettingValueList(LIST_RPSTE, LIST_RPSTE[val]))
        basic.append(rs)

        if _mem.settings.rptrl > 0x0A:
            val = 0x00
        else:
            val = _mem.settings.rptrl
        rs = RadioSetting(
            "settings.rptrl", "STE Repeater Delay",
            RadioSettingValueList(LIST_STEDELAY, LIST_STEDELAY[val]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.ponmsg", "Power-On Message",
            RadioSettingValueList(LIST_PONMSG,
                                  LIST_PONMSG[_mem.settings.ponmsg]))
        basic.append(rs)

        rs = RadioSetting("settings.roger", "Roger Beep",
                          RadioSettingValueBoolean(_mem.settings.roger))
        basic.append(rs)

        # Advanced settings
        rs = RadioSetting("settings.reset", "RESET Menu",
                          RadioSettingValueBoolean(_mem.settings.reset))
        advanced.append(rs)

        rs = RadioSetting("settings.menu", "All Menus",
                          RadioSettingValueBoolean(_mem.settings.menu))
        advanced.append(rs)

        rs = RadioSetting("settings.fmradio", "Broadcast FM Radio",
                          RadioSettingValueBoolean(_mem.settings.fmradio))
        advanced.append(rs)

        rs = RadioSetting("settings.alarm", "Alarm Sound",
                          RadioSettingValueBoolean(_mem.settings.alarm))
        advanced.append(rs)

        # Other settings
        def _filter(name):
            filtered = ""
            for char in str(name):
                if char in chirp_common.CHARSET_ASCII:
                    filtered += char
                else:
                    filtered += " "
            return filtered

        _msg = _mem.firmware_msg
        val = RadioSettingValueString(0, 8, _filter(_msg.line1))
        val.set_mutable(False)
        rs = RadioSetting("firmware_msg.line1", "Firmware Message 1", val)
        other.append(rs)

        val = RadioSettingValueString(0, 8, _filter(_msg.line2))
        val.set_mutable(False)
        rs = RadioSetting("firmware_msg.line2", "Firmware Message 2", val)
        other.append(rs)

        _msg = _mem.sixpoweron_msg
        val = RadioSettingValueString(0, 8, _filter(_msg.line1))
        val.set_mutable(False)
        rs = RadioSetting("sixpoweron_msg.line1", "6+Power-On Message 1", val)
        other.append(rs)
        val = RadioSettingValueString(0, 8, _filter(_msg.line2))
        val.set_mutable(False)
        rs = RadioSetting("sixpoweron_msg.line2", "6+Power-On Message 2", val)
        other.append(rs)

        _msg = _mem.poweron_msg
        rs = RadioSetting("poweron_msg.line1", "Power-On Message 1",
                          RadioSettingValueString(0, 7, _filter(_msg.line1)))
        other.append(rs)
        rs = RadioSetting("poweron_msg.line2", "Power-On Message 2",
                          RadioSettingValueString(0, 7, _filter(_msg.line2)))
        other.append(rs)

        lower = 136
        upper = 174
        rs = RadioSetting(
            "limits.vhf.lower", "VHF Lower Limit (MHz)",
            RadioSettingValueInteger(lower, upper, _mem.limits.vhf.lower))
        other.append(rs)

        rs = RadioSetting(
            "limits.vhf.upper", "VHF Upper Limit (MHz)",
            RadioSettingValueInteger(lower, upper, _mem.limits.vhf.upper))
        other.append(rs)

        lower = 400
        upper = 520
        rs = RadioSetting(
            "limits.uhf.lower", "UHF Lower Limit (MHz)",
            RadioSettingValueInteger(lower, upper, _mem.limits.uhf.lower))
        other.append(rs)

        rs = RadioSetting(
            "limits.uhf.upper", "UHF Upper Limit (MHz)",
            RadioSettingValueInteger(lower, upper, _mem.limits.uhf.upper))
        other.append(rs)

        # Work mode settings
        rs = RadioSetting(
            "settings.displayab", "Display",
            RadioSettingValueList(LIST_AB, LIST_AB[_mem.settings.displayab]))
        work.append(rs)

        rs = RadioSetting(
            "settings.workmode", "VFO/MR Mode",
            RadioSettingValueList(LIST_WORKMODE,
                                  LIST_WORKMODE[_mem.settings.workmode]))
        work.append(rs)

        rs = RadioSetting("settings.keylock", "Keypad Lock",
                          RadioSettingValueBoolean(_mem.settings.keylock))
        work.append(rs)

        rs = RadioSetting(
            "wmchannel.mrcha", "MR A Channel",
            RadioSettingValueInteger(0, 127, _mem.wmchannel.mrcha))
        work.append(rs)

        rs = RadioSetting(
            "wmchannel.mrchb", "MR B Channel",
            RadioSettingValueInteger(0, 127, _mem.wmchannel.mrchb))
        work.append(rs)

        def convert_bytes_to_freq(bytes):
            real_freq = 0
            for byte in bytes:
                real_freq = (real_freq * 10) + byte
            return chirp_common.format_freq(real_freq * 10)

        def my_validate(value):
            _vhf_lower = int(_mem.limits.vhf.lower)
            _vhf_upper = int(_mem.limits.vhf.upper)
            _uhf_lower = int(_mem.limits.uhf.lower)
            _uhf_upper = int(_mem.limits.uhf.upper)
            value = chirp_common.parse_freq(value)
            msg = ("Can't be less than %i.0000")
            if value > 99000000 and value < _vhf_lower * 1000000:
                raise InvalidValueError(msg % _vhf_lower)
            msg = ("Can't be between %i.9975-%i.0000")
            if _vhf_upper * 1000000 <= value and value < _uhf_lower * 1000000:
                raise InvalidValueError(msg % (_vhf_upper - 1, _uhf_lower))
            msg = ("Can't be greater than %i.9975")
            if value > 99000000 and value >= _uhf_upper * 1000000:
                raise InvalidValueError(msg % (_uhf_upper - 1))
            return chirp_common.format_freq(value)

        def apply_freq(setting, obj):
            value = chirp_common.parse_freq(str(setting.value)) / 10
            for i in range(7, -1, -1):
                obj.freq[i] = value % 10
                value /= 10

        val1a = RadioSettingValueString(0, 10,
                                        convert_bytes_to_freq(_mem.vfo.a.freq))
        val1a.set_validate_callback(my_validate)
        rs = RadioSetting("vfo.a.freq", "VFO A Frequency", val1a)
        rs.set_apply_callback(apply_freq, _mem.vfo.a)
        work.append(rs)

        val1b = RadioSettingValueString(0, 10,
                                        convert_bytes_to_freq(_mem.vfo.b.freq))
        val1b.set_validate_callback(my_validate)
        rs = RadioSetting("vfo.b.freq", "VFO B Frequency", val1b)
        rs.set_apply_callback(apply_freq, _mem.vfo.b)
        work.append(rs)

        rs = RadioSetting(
            "vfo.a.sftd", "VFO A Shift",
            RadioSettingValueList(LIST_SHIFTD, LIST_SHIFTD[_mem.vfo.a.sftd]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.b.sftd", "VFO B Shift",
            RadioSettingValueList(LIST_SHIFTD, LIST_SHIFTD[_mem.vfo.b.sftd]))
        work.append(rs)

        def convert_bytes_to_offset(bytes):
            real_offset = 0
            for byte in bytes:
                real_offset = (real_offset * 10) + byte
            return chirp_common.format_freq(real_offset * 1000)

        def apply_offset(setting, obj):
            value = chirp_common.parse_freq(str(setting.value)) / 1000
            for i in range(5, -1, -1):
                obj.offset[i] = value % 10
                value /= 10

        val1a = RadioSettingValueString(
            0, 10, convert_bytes_to_offset(_mem.vfo.a.offset))
        rs = RadioSetting("vfo.a.offset", "VFO A Offset", val1a)
        rs.set_apply_callback(apply_offset, _mem.vfo.a)
        work.append(rs)

        val1b = RadioSettingValueString(
            0, 10, convert_bytes_to_offset(_mem.vfo.b.offset))
        rs = RadioSetting("vfo.b.offset", "VFO B Offset", val1b)
        rs.set_apply_callback(apply_offset, _mem.vfo.b)
        work.append(rs)

        rs = RadioSetting(
            "vfo.a.txpower", "VFO A Power",
            RadioSettingValueList(LIST_TXPOWER,
                                  LIST_TXPOWER[_mem.vfo.a.txpower]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.b.txpower", "VFO B Power",
            RadioSettingValueList(LIST_TXPOWER,
                                  LIST_TXPOWER[_mem.vfo.b.txpower]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.a.widenarr", "VFO A Bandwidth",
            RadioSettingValueList(LIST_BANDWIDTH,
                                  LIST_BANDWIDTH[_mem.vfo.a.widenarr]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.b.widenarr", "VFO B Bandwidth",
            RadioSettingValueList(LIST_BANDWIDTH,
                                  LIST_BANDWIDTH[_mem.vfo.b.widenarr]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.a.scode", "VFO A S-CODE",
            RadioSettingValueList(LIST_SCODE, LIST_SCODE[_mem.vfo.a.scode]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.b.scode", "VFO B S-CODE",
            RadioSettingValueList(LIST_SCODE, LIST_SCODE[_mem.vfo.b.scode]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.a.step", "VFO A Tuning Step",
            RadioSettingValueList(LIST_STEP, LIST_STEP[_mem.vfo.a.step]))
        work.append(rs)
        rs = RadioSetting(
            "vfo.b.step", "VFO B Tuning Step",
            RadioSettingValueList(LIST_STEP, LIST_STEP[_mem.vfo.b.step]))
        work.append(rs)

        # broadcast FM settings
        _fm_presets = self._memobj.fm_presets
        if _fm_presets <= 108.0 * 10 - 650:
            preset = _fm_presets / 10.0 + 65
        elif _fm_presets >= 65.0 * 10 and _fm_presets <= 108.0 * 10:
            preset = _fm_presets / 10.0
        else:
            preset = 76.0
        rs = RadioSetting("fm_presets", "FM Preset(MHz)",
                          RadioSettingValueFloat(65, 108.0, preset, 0.1, 1))
        fm_preset.append(rs)

        # DTMF settings
        def apply_code(setting, obj, length):
            code = []
            for j in range(0, length):
                try:
                    code.append(DTMF_CHARS.index(str(setting.value)[j]))
                except IndexError:
                    code.append(0xFF)
            obj.code = code

        for i in range(0, 15):
            _codeobj = self._memobj.pttid[i].code
            _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
            val = RadioSettingValueString(0, 5, _code, False)
            val.set_charset(DTMF_CHARS)
            pttid = RadioSetting("pttid/%i.code" % i,
                                 "Signal Code %i" % (i + 1), val)
            pttid.set_apply_callback(apply_code, self._memobj.pttid[i], 5)
            dtmfe.append(pttid)

        if _mem.ani.dtmfon > 0xC3:
            val = 0x03
        else:
            val = _mem.ani.dtmfon
        rs = RadioSetting(
            "ani.dtmfon", "DTMF Speed (on)",
            RadioSettingValueList(LIST_DTMFSPEED, LIST_DTMFSPEED[val]))
        dtmfe.append(rs)

        if _mem.ani.dtmfoff > 0xC3:
            val = 0x03
        else:
            val = _mem.ani.dtmfoff
        rs = RadioSetting(
            "ani.dtmfoff", "DTMF Speed (off)",
            RadioSettingValueList(LIST_DTMFSPEED, LIST_DTMFSPEED[val]))
        dtmfe.append(rs)

        _codeobj = self._memobj.ani.code
        _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 5, _code, False)
        val.set_charset(DTMF_CHARS)
        rs = RadioSetting("ani.code", "ANI Code", val)
        rs.set_apply_callback(apply_code, self._memobj.ani, 5)
        dtmfe.append(rs)

        rs = RadioSetting(
            "ani.aniid", "When to send ANI ID",
            RadioSettingValueList(LIST_PTTID, LIST_PTTID[_mem.ani.aniid]))
        dtmfe.append(rs)

        # Service settings
        for index in range(0, 10):
            key = "squelch.sql%i" % (index)
            _obj = self._memobj.squelch
            val = RadioSettingValueInteger(0, 123,
                                           getattr(_obj, "sql%i" % (index)))
            if index == 0:
                val.set_mutable(False)
            name = "Squelch %i" % (index)
            rs = RadioSetting(key, name, val)
            service.append(rs)

        return top
コード例 #6
0
    def get_settings(self):
        _settings = self._memobj.settings
        basic = RadioSettingGroup("basic", "Basic Settings")
        fm = RadioSettingGroup("fm", "FM Radio")
        adv = RadioSettingGroup("adv", "Advanced Settings")
        group = RadioSettings(basic, fm, adv)

        # ## Basic Settings
        rs = RadioSetting("tx_pwr", "TX Power",
                          RadioSettingValueList(
                            POWER_LIST, POWER_LIST[_settings.tx_pwr]))
        basic.append(rs)

        rs = RadioSetting("channel", "Active Channel",
                          RadioSettingValueInteger(1, 20, _settings.channel))
        basic.append(rs)

        rs = RadioSetting("squelch", "Squelch Level",
                          RadioSettingValueInteger(0, 9, _settings.squelch))
        basic.append(rs)

        rs = RadioSetting("vox", "VOX Level",
                          RadioSettingValueInteger(0, 9, _settings.vox))
        basic.append(rs)

        # volume validation, as the OEM software set 0xFF on write
        _volume = _settings.volume
        if _volume > 7:
            _volume = 7
        rs = RadioSetting("volume", "Volume Level",
                          RadioSettingValueInteger(0, 7, _volume))
        basic.append(rs)

        rs = RadioSetting("scantype", "Scan Type",
                          RadioSettingValueList(SCAN_TYPE_LIST, SCAN_TYPE_LIST[
                              _settings.scantype]))
        basic.append(rs)

        rs = RadioSetting("timeout", "Time Out Timer (seconds)",
                          RadioSettingValueList(
                            TOT_LIST, TOT_LIST[_settings.timeout]))
        basic.append(rs)

        rs = RadioSetting("voice", "Voice Prompt",
                          RadioSettingValueList(
                            LANGUAGE_LIST, LANGUAGE_LIST[_settings.voice]))
        basic.append(rs)

        rs = RadioSetting("alarm", "Alarm Time",
                          RadioSettingValueList(
                            TIMER_LIST, TIMER_LIST[_settings.alarm]))
        basic.append(rs)

        rs = RadioSetting("backlight", "Backlight",
                          RadioSettingValueList(
                            BACKLIGHT_LIST,
                            BACKLIGHT_LIST[_settings.backlight]))
        basic.append(rs)

        rs = RadioSetting("blo", "Busy Lockout",
                          RadioSettingValueBoolean(_settings.blo))
        basic.append(rs)

        rs = RadioSetting("ste", "Squelch Tail Eliminate",
                          RadioSettingValueBoolean(_settings.ste))
        basic.append(rs)

        rs = RadioSetting("batsave", "Battery Save",
                          RadioSettingValueBoolean(_settings.batsave))
        basic.append(rs)

        rs = RadioSetting("lock", "Key Lock",
                          RadioSettingValueBoolean(_settings.lock))
        basic.append(rs)

        rs = RadioSetting("beep", "Key Beep",
                          RadioSettingValueBoolean(_settings.beep))
        basic.append(rs)

        # ## FM Settings
        rs = RadioSetting("fm_funct", "FM Function",
                          RadioSettingValueBoolean(_settings.fm_funct))
        fm.append(rs)

        rs = RadioSetting("fmrange", "FM Range",
                          RadioSettingValueList(
                            FM_RANGE_LIST, FM_RANGE_LIST[_settings.fmrange]))
        fm.append(rs)

        # callbacks for the FM VFO
        def apply_fm_freq(setting, obj):
            setattr(obj, setting.get_name(), int(setting.value.
                get_value() * 10) - 650)

        _fm_vfo = int(_settings.fm_vfo) * 0.1 + 65
        rs = RadioSetting("fm_vfo", "FM Station",
                          RadioSettingValueFloat(65, 108, _fm_vfo))
        rs.set_apply_callback(apply_fm_freq, _settings)
        fm.append(rs)

        # ## Advanced
        def apply_limit(setting, obj):
            setattr(obj, setting.get_name(), int(setting.value) * 10)

        rs = RadioSetting("vhfl", "VHF Low Limit",
                          RadioSettingValueInteger(130, 174, int(
                              _settings.vhfl) / 10))
        rs.set_apply_callback(apply_limit, _settings)
        adv.append(rs)

        rs = RadioSetting("vhfh", "VHF High Limit",
                          RadioSettingValueInteger(130, 174, int(
                              _settings.vhfh) / 10))
        rs.set_apply_callback(apply_limit, _settings)
        adv.append(rs)

        rs = RadioSetting("uhfl", "UHF Low Limit",
                          RadioSettingValueInteger(400, 520, int(
                              _settings.uhfl) / 10))
        rs.set_apply_callback(apply_limit, _settings)
        adv.append(rs)

        rs = RadioSetting("uhfh", "UHF High Limit",
                          RadioSettingValueInteger(400, 520, int(
                              _settings.uhfh) / 10))
        rs.set_apply_callback(apply_limit, _settings)
        adv.append(rs)

        rs = RadioSetting("relaym", "Relay Mode",
                          RadioSettingValueList(RELAY_MODE_LIST,
                              RELAY_MODE_LIST[_settings.relaym]))
        adv.append(rs)

        return group
コード例 #7
0
ファイル: ic2730.py プロジェクト: rozhuk-im/chirp
    def get_settings(self):
        """Translate the MEM_FORMAT structs into settings in the UI"""
        # Define mem struct write-back shortcuts
        _sets = self._memobj.settings
        _cmnt = self._memobj.comment
        _wxch = self._memobj.abwx
        _dtm = self._memobj.dtmfcode
        _pses = self._memobj.pgmscanedge
        _bklk = self._memobj.banklink

        basic = RadioSettingGroup("basic", "Basic Settings")
        mickey = RadioSettingGroup("mickey", "Microphone Keys")
        bluet = RadioSettingGroup("bluet", "Bluetooth")
        disp = RadioSettingGroup("disp", "Display")
        sound = RadioSettingGroup("sound", "Sounds")
        dtmf = RadioSettingGroup("dtmf", "DTMF Codes")
        abset = RadioSettingGroup("abset", "A/B Band Settings")
        edges = RadioSettingGroup("edges", "Program Scan Edges")
        pslnk = RadioSettingGroup("pslnk", "Program Scan Links")
        other = RadioSettingGroup("other", "Other Settings")

        group = RadioSettings(basic, disp, sound, mickey, dtmf, abset, bluet,
                              edges, pslnk, other)

        def mic_keys(setting, obj, atrb):
            """ Callback to set subset of mic key options """
            stx = str(setting.value)
            value = MICKEYOPTS.index(stx)
            setattr(obj, atrb, value)
            return

        def hex_val(setting, obj, atrb):
            """ Callback to store string as hex values """
            value = int(str(setting.value), 16)
            setattr(obj, atrb, value)
            return

        def unpack_str(codestr):
            """Convert u8 DTMF array to a string: NOT a callback."""
            stx = ""
            for i in range(0, 24):  # unpack up to ff
                if codestr[i] != 0xff:  # Issue  8159 fix
                    if codestr[i] == 0x0E:
                        stx += "*"
                    elif codestr[i] == 0x0F:
                        stx += "#"
                    else:
                        stx += format(int(codestr[i]), '0X')
            return stx

        def pack_chars(setting, obj, atrb, ndx):
            """Callback to build 0-9,A-D,*# nibble array from string"""
            # String will be f padded to 24 bytes
            # Chars are stored as hex values
            ary = []
            stx = str(setting.value).upper()
            stx = stx.strip()  # trim spaces
            # Remove illegal characters first
            sty = ""
            for j in range(0, len(stx)):
                if stx[j] in MDTMF_CHARS:
                    sty += stx[j]
            for j in range(0, 24):
                if j < len(sty):  # Issue 8159 fix
                    if sty[j] == "*":
                        chrv = 0xE
                    elif sty[j] == "#":
                        chrv = 0xF
                    else:
                        chrv = int(sty[j], 16)
                else:  # pad to 24 bytes
                    chrv = 0xFF
                ary.append(chrv)  # append byte
            setattr(obj[ndx], atrb, ary)
            return

        def myset_comment(setting, obj, atrb, knt):
            """ Callback to create space-padded char array"""
            stx = str(setting.value)
            for i in range(0, knt):
                if i > len(stx):
                    str.append(0x20)
            setattr(obj, atrb, stx)
            return

        def myset_psnam(setting, obj, ndx, atrb, knt):
            """ Callback to generate space-padded, uppercase char array """
            # This sub also is specific to object arrays
            stx = str(setting.value).upper()
            for i in range(0, knt):
                if i > len(stx):
                    str.append(0x20)
            setattr(obj[ndx], atrb, stx)
            return

        def myset_frqflgs(setting, obj, ndx, flg, frq):
            """ Callback to gen flag/freq pairs """
            vfrq = float(str(setting.value))
            vfrq = int(vfrq * 1000000)
            vflg = 0x10
            if vfrq % 6250 == 0:
                vflg = 0x08
                vfrq = int(vfrq / 6250)
            elif vfrq % 5000 == 0:
                vflg = 0
                vfrq = int(vfrq / 5000)
            else:
                vfrq = int(vfrq / 8333)
            setattr(obj[ndx], flg, vflg)
            setattr(obj[ndx], frq, vfrq)
            return

        def banklink(ary):
            """ Sub to generate A-J string from 2-byte bit pattern """
            stx = ""
            for kx in range(0, 10):
                if kx < 8:
                    val = ary[0]
                    msk = 1 << kx
                else:
                    val = ary[1]
                    msk = 1 << (kx - 8)
                if val & msk:
                    stx += chr(kx + 65)
                else:
                    stx += "_"
            return stx

        def myset_banklink(setting, obj, atrb):
            """Callback to create 10-bit, u8[2] array from 10 char string"""
            stx = str(setting.value).upper()
            ary = [0, 0]
            for kx in range(0, 10):
                if stx[kx] == chr(kx + 65):
                    if kx < 8:
                        ary[0] = ary[0] + (1 << kx)
                    else:
                        ary[1] = ary[1] + (1 << (kx - 8))
            setattr(obj, atrb, ary)
            return

        def myset_tsopt(setting, obj, ndx, atrb, bx):
            """ Callback to set scan Edge tstep """
            stx = str(setting.value)
            flg = 0
            if stx == "-":
                val = 0xff
            else:
                if bx == 1:  # Air band
                    if stx == "Auto":
                        val = 0xe
                    elif stx == "25k":
                        val = 8
                    elif stx == "8.33k":
                        val = 2
                else:  # VHF or UHF
                    optx = [
                        "-", "5k", "6.25k", "10k", "12.5k", "15k", "20k",
                        "25k", "30k", "50k"
                    ]
                    val = optx.index(stx) + 1
            setattr(obj[ndx], atrb, val)
            # and set flag
            setattr(obj[ndx], "flag", flg)
            return

        def myset_mdopt(setting, obj, ndx, atrb, bx):
            """ Callback to set Scan Edge mode """
            stx = str(setting.value)
            if stx == "-":
                val = 0xf
            elif stx == "FM":
                val = 0
            else:
                val = 1
            setattr(obj[ndx], atrb, val)
            return

        def myset_bitmask(setting, obj, ndx, atrb, knt):
            """ Callback to gnerate byte-array bitmask from string"""
            # knt is BIT count to process
            lsx = str(setting.value).strip().split(",")
            for kx in range(0, len(lsx)):
                try:
                    lsx[kx] = int(lsx[kx])
                except Exception:
                    lsx[kx] = -99  # will nop
            ary = [0, 0, 0, 0xfe]
            for kx in range(0, knt):
                if kx < 8:
                    if kx in lsx:
                        ary[0] += 1 << kx
                elif kx >= 8 and kx < 16:
                    if kx in lsx:
                        ary[1] += 1 << (kx - 8)
                elif kx >= 16 and kx < 24:
                    if kx in lsx:
                        ary[2] += 1 << (kx - 16)
                else:
                    if kx in lsx:  # only bit 25
                        ary[3] += 1
            setattr(obj[ndx], atrb, ary)
            return

        # --- Basic
        options = ["Off", "S-Meter Squelch", "ATT"]
        rx = RadioSettingValueList(options, options[_sets.sqlatt])
        rset = RadioSetting("settings.sqlatt", "Squelch/ATT", rx)
        basic.append(rset)

        options = ["Short", "Long"]
        rx = RadioSettingValueList(options, options[_sets.sqldly])
        rset = RadioSetting("settings.sqldly", "Squelch Delay", rx)
        basic.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.pttlock))
        rset = RadioSetting("settings.pttlock", "PTT Lockout", rx)
        basic.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.bcl))
        rset = RadioSetting("settings.bcl", "Busy Channel Lockout", rx)
        basic.append(rset)

        options = ["Off", "1m", "3m", "5m", "10m", "15m", "30m"]
        rx = RadioSettingValueList(options, options[_sets.tot])
        rset = RadioSetting("settings.tot", "Tx Timeout", rx)
        basic.append(rset)

        val = int(_sets.vfohome)
        if val == 0xffff:
            val = 0
        val = val / 1000000.0
        rx = RadioSettingValueFloat(0.0, 550.0, val, 0.005, 4)
        rx.set_mutable(False)
        rset = RadioSetting("settings.vfohome", "Home VFO (Read-Only)", rx)
        basic.append(rset)

        val = _sets.homech
        if val == 0xffff:
            val = -1
        rx = RadioSettingValueInteger(-1, 999, val)
        rx.set_mutable(False)
        rset = RadioSetting("settings.homech", "Home Channel (Read-Only)", rx)
        basic.append(rset)

        options = ["1", "2", "3", "4"]
        rx = RadioSettingValueList(options, options[_sets.micgain])
        rset = RadioSetting("settings.micgain", "Microphone Gain", rx)
        basic.append(rset)

        _bmem = self._memobj.initmem
        rx = RadioSettingValueInteger(0, 999, _bmem.left_memory)
        rset = RadioSetting("initmem.left_memory",
                            "Left Bank Initial Mem Chan", rx)
        basic.append(rset)

        rx = RadioSettingValueInteger(0, 999, _bmem.right_memory)
        rset = RadioSetting("initmem.right_memory",
                            "Right Bank Initial Mem Chan", rx)
        basic.append(rset)

        stx = ""
        for i in range(0, 16):
            stx += chr(_cmnt.com[i])
        stx = stx.rstrip()
        rx = RadioSettingValueString(0, 16, stx)
        rset = RadioSetting("comment.com", "Comment (16 chars)", rx)
        rset.set_apply_callback(myset_comment, _cmnt, "com", 16)
        basic.append(rset)

        # --- Other
        rset = RadioSetting("drv_clone_speed", "Use Hi-Speed Clone",
                            RadioSettingValueBoolean(self._can_hispeed))
        other.append(rset)

        options = ["Single", "All", "Ham"]
        rx = RadioSettingValueList(options, options[_sets.actband])
        rset = RadioSetting("settings.actband", "Active Band", rx)
        other.append(rset)

        options = ["Slow", "Mid", "Fast", "Auto"]
        rx = RadioSettingValueList(options, options[_sets.fanspeed])
        rset = RadioSetting("settings.fanspeed", "Fan Speed", rx)
        other.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.dialspdup))
        rset = RadioSetting("settings.dialspdup", "Dial Speed-Up", rx)
        other.append(rset)

        options = ["Off", "On(Dup)", "On(Dup+Tone)"]
        rx = RadioSettingValueList(options, options[_sets.autorptr])
        rset = RadioSetting("settings.autorptr", "Auto Repeater", rx)
        other.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.rmtmic))
        rset = RadioSetting("settings.rmtmic", "One-Touch PTT (Remote Mic)",
                            rx)
        other.append(rset)

        options = ["Low", "Mid", "High"]
        rx = RadioSettingValueList(options, options[_sets.vhfpower])
        rset = RadioSetting("settings.vhfpower", "VHF Power Default", rx)
        other.append(rset)

        rx = RadioSettingValueList(options, options[_sets.uhfpower])
        rset = RadioSetting("settings.uhfpower", "UHF Power Default", rx)
        other.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.toneburst))
        rset = RadioSetting("settings.toneburst", "1750 Htz Tone Burst", rx)
        other.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.ifxchg))
        rset = RadioSetting("settings.ifxchg", "IF Exchange", rx)
        other.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.rpthangup))
        rset = RadioSetting("settings.rpthangup", "Repeater Hang up Timeout",
                            rx)
        other.append(rset)

        stx = str(_sets.civaddr)[2:]  # Hex value
        rx = RadioSettingValueString(1, 2, stx)
        rset = RadioSetting("settings.civaddr", "CI-V Address (90)", rx)
        rset.set_apply_callback(hex_val, _sets, "civaddr")
        other.append(rset)

        options = ["1200", "2400", "4800", "9600", "19200", "Auto"]
        rx = RadioSettingValueList(options, options[_sets.civbaud])
        rset = RadioSetting("settings.civbaud", "CI-V Baud Rate (bps)", rx)
        other.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.civtcvr))
        rset = RadioSetting("settings.civtcvr", "CI-V Transceive", rx)
        other.append(rset)

        # A/B Band Settings
        options = ["Off", "On", "Bell"]
        rx = RadioSettingValueList(options, options[_sets.aprichn])
        rset = RadioSetting("settings.aprichn",
                            "A Band: VFO Priority Watch Mode", rx)
        abset.append(rset)

        options = [
            "2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "Hold"
        ]
        rx = RadioSettingValueList(options, options[_sets.ascanpause])
        rset = RadioSetting("settings.ascanpause",
                            "-- A Band: Scan Pause Time (Secs)", rx)
        abset.append(rset)

        options = ["0", "1", "2", "3", "4", "5", "Hold"]
        rx = RadioSettingValueList(options, options[_sets.ascanresume])
        rset = RadioSetting("settings.ascanresume",
                            "-- A Band: Scan Resume Time (Secs)", rx)
        abset.append(rset)

        options = ["5", "10", "15"]
        rx = RadioSettingValueList(options, options[_sets.atmpskiptym])
        rset = RadioSetting("settings.atmpskiptym",
                            "-- A Band: Temp Skip Time (Secs)", rx)
        abset.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.aprgskpscn))
        rset = RadioSetting("settings.aprgskpscn",
                            "-- A Band: Program Skip Scan", rx)
        abset.append(rset)

        rx = RadioSettingValueString(10, 10, banklink(_bklk.alnk))
        rset = RadioSetting("banklink.alnk",
                            "-- A Band Banklink (use _ to skip)", rx)
        rset.set_apply_callback(myset_banklink, _bklk, "alnk")
        abset.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.awxalert))
        rset = RadioSetting("settings.awxalert", "-- A Band: Weather Alert",
                            rx)
        abset.append(rset)

        # Use list for Wx chans since chan 1 = index 0
        options = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
        rx = RadioSettingValueList(options, options[_wxch.awxchan])
        rset = RadioSetting("abwx.awxchan", "-- A Band: Weather Channel", rx)
        abset.append(rset)

        options = ["Off", "On", "Bell"]
        rx = RadioSettingValueList(options, options[_sets.bprichn])
        rset = RadioSetting("settings.bprichn",
                            "B Band: VFO Priority Watch Mode", rx)
        abset.append(rset)

        options = [
            "2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "Hold"
        ]
        rx = RadioSettingValueList(options, options[_sets.bscanpause])
        rset = RadioSetting("settings.bscanpause",
                            "-- B Band: Scan Pause Time (Secs)", rx)
        abset.append(rset)

        options = ["0", "1", "2", "3", "4", "5", "Hold"]
        rx = RadioSettingValueList(options, options[_sets.bscanresume])
        rset = RadioSetting("settings.bscanresume",
                            "-- B Band: Scan Resume Time (Secs)", rx)
        abset.append(rset)

        options = ["5", "10", "15"]
        rx = RadioSettingValueList(options, options[_sets.btmpskiptym])
        rset = RadioSetting("settings.btmpskiptym",
                            "-- B Band: Temp Skip Time (Secs)", rx)
        abset.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.bprgskpscn))
        rset = RadioSetting("settings.bprgskpscn",
                            "-- B Band: Program Skip Scan", rx)
        abset.append(rset)

        rx = RadioSettingValueString(10, 10, banklink(_bklk.blnk))
        rset = RadioSetting("banklink.blnk",
                            "-- B Band Banklink (use _ to skip)", rx)
        rset.set_apply_callback(myset_banklink, _bklk, "blnk")
        abset.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.bwxalert))
        rset = RadioSetting("settings.bwxalert", "-- B Band: Weather Alert",
                            rx)
        abset.append(rset)

        options = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
        rx = RadioSettingValueList(options, options[_wxch.bwxchan])
        rset = RadioSetting("abwx.bwxchan", "-- B Band: Weather Channel", rx)
        abset.append(rset)

        # --- Microphone Keys
        # The Mic keys get wierd: stored values are indecis to the full
        # options list, but only a subset is valid...
        shortopts = [
            "Off", "Monitor", "MR (Ch 0)", "MR (Ch 1)", "Band/Bank", "Scan",
            "Temp Skip", "Mode", "Low", "Dup", "Priority", "Tone", "MW",
            "Mute", "DTMF Direct", "T-Call"
        ]
        ptr = shortopts.index(MICKEYOPTS[_sets.mickyrxf1])
        rx = RadioSettingValueList(shortopts, shortopts[ptr])
        rset = RadioSetting("settings.mickyrxf1", "During Rx/Standby [F-1]",
                            rx)
        rset.set_apply_callback(mic_keys, _sets, "mickyrxf1")
        mickey.append(rset)

        ptr = shortopts.index(MICKEYOPTS[_sets.mickyrxf2])
        rx = RadioSettingValueList(shortopts, shortopts[ptr])
        rset = RadioSetting("settings.mickyrxf2", "During Rx/Standby [F-2]",
                            rx)
        rset.set_apply_callback(mic_keys, _sets, "mickyrxf2")
        mickey.append(rset)

        options = ["Off", "Low", "T-Call"]  # NOT a subset of MICKEYOPTS
        rx = RadioSettingValueList(options, options[_sets.mickytxf1])
        rset = RadioSetting("settings.mickytxf1", "During Tx [F-1]", rx)
        mickey.append(rset)

        rx = RadioSettingValueList(options, options[_sets.mickytxf2])
        rset = RadioSetting("settings.mickytxf2", "During Tx [F-2]", rx)
        mickey.append(rset)

        # These next two get the full options list
        rx = RadioSettingValueList(MICKEYOPTS, MICKEYOPTS[_sets.mickyrxup])
        rset = RadioSetting("settings.mickyrxup", "During Rx/Standby [Up]", rx)
        mickey.append(rset)

        rx = RadioSettingValueList(MICKEYOPTS, MICKEYOPTS[_sets.mickyrxdn])
        rset = RadioSetting("settings.mickyrxdn", "During Rx/Standby [Down]",
                            rx)
        mickey.append(rset)

        options = ["Off", "Low", "T-Call"]
        rx = RadioSettingValueList(options, options[_sets.mickytxup])
        rset = RadioSetting("settings.mickytxup", "During Tx [Up]", rx)
        mickey.append(rset)

        rx = RadioSettingValueList(options, options[_sets.mickytxdn])
        rset = RadioSetting("settings.mickytxdn", "During Tx [Down]", rx)
        mickey.append(rset)

        # --- Bluetooth
        rx = RadioSettingValueBoolean(bool(_sets.btoothon))
        rset = RadioSetting("settings.btoothon", "Bluetooth", rx)
        bluet.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.btoothauto))
        rset = RadioSetting("settings.btoothauto", "Auto Connect", rx)
        bluet.append(rset)

        options = ["Headset Only", "Headset & Speaker"]
        rx = RadioSettingValueList(options, options[_sets.bthdset])
        rset = RadioSetting("settings.bthdset", "Headset Audio", rx)
        bluet.append(rset)

        options = [
            "Normal", "Microphone", "PTT (Audio:Main)", "PTT(Audio:Controller)"
        ]
        rx = RadioSettingValueList(options, options[_sets.bthfctn])
        rset = RadioSetting("settings.bthfctn", "Headset Function", rx)
        bluet.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.bthvox))
        rset = RadioSetting("settings.bthvox", "Vox", rx)
        bluet.append(rset)

        options = ["Off", "1.0", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
        rx = RadioSettingValueList(options, options[_sets.bthvoxlvl])
        rset = RadioSetting("settings.bthvoxlvl", "Vox Level", rx)
        bluet.append(rset)

        options = ["0.5", "1.0", "1.5", "2.0", "2.5", "3.0"]
        rx = RadioSettingValueList(options, options[_sets.bthvoxdly])
        rset = RadioSetting("settings.bthvoxdly", "Vox Delay (Secs)", rx)
        bluet.append(rset)

        options = ["Off", "1", "2", "3", "4", "5", "10", "15"]
        rx = RadioSettingValueList(options, options[_sets.bthvoxtot])
        rset = RadioSetting("settings.bthvoxtot", "Vox Time-Out (Mins)", rx)
        bluet.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.bthhdpsav))
        rset = RadioSetting("settings.bthhdpsav", "ICOM Headset Power-Save",
                            rx)
        bluet.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.bth1ptt))
        rset = RadioSetting("settings.bth1ptt", "ICOM Headset One-Touch PTT",
                            rx)
        bluet.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.bthpttbeep))
        rset = RadioSetting("settings.bthpttbeep", "ICOM Headset PTT Beep", rx)
        bluet.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.bthcustbeep))
        rset = RadioSetting("settings.bthcustbeep",
                            "ICOM Headset Custom Key Beep", rx)
        bluet.append(rset)

        rx = RadioSettingValueList(MICKEYOPTS, MICKEYOPTS[_sets.bthplaykey])
        rset = RadioSetting("settings.bthplaykey",
                            "ICOM Headset Custom Key [Play]", rx)
        bluet.append(rset)

        rx = RadioSettingValueList(MICKEYOPTS, MICKEYOPTS[_sets.bthfwdkey])
        rset = RadioSetting("settings.bthfwdkey",
                            "ICOM Headset Custom Key [Fwd]", rx)
        bluet.append(rset)

        rx = RadioSettingValueList(MICKEYOPTS, MICKEYOPTS[_sets.bthrwdkey])
        rset = RadioSetting("settings.bthrwdkey",
                            "ICOM Headset Custom Key [Rwd]", rx)
        bluet.append(rset)

        # ---- Display
        options = ["1: Dark", "2", "3", "4: Bright"]
        rx = RadioSettingValueList(options, options[_sets.backlight])
        rset = RadioSetting("settings.backlight", "Backlight Level", rx)
        disp.append(rset)

        options = ["Off", "Auto-Off", "Auto-1", "Auto-2", "Auto-3"]
        rx = RadioSettingValueList(options, options[_sets.autodim])
        rset = RadioSetting("settings.autodim", "Auto Dimmer", rx)
        disp.append(rset)

        options = ["5", "10"]
        rx = RadioSettingValueList(options, options[_sets.autodimtot])
        rset = RadioSetting("settings.autodimtot",
                            "Auto-Dimmer Timeout (Secs)", rx)
        disp.append(rset)

        options = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
        rx = RadioSettingValueList(options, options[_sets.contrast])
        rset = RadioSetting("settings.contrast", "LCD Contrast", rx)
        disp.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.openmsg))
        rset = RadioSetting("settings.openmsg", "Opening Message", rx)
        disp.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.memname))
        rset = RadioSetting("settings.memname", "Memory Names", rx)
        disp.append(rset)

        options = ["CH ID", "Frequency"]
        rx = RadioSettingValueList(options, options[_sets.airbandch])
        rset = RadioSetting("settings.airbandch", "Air Band Display", rx)
        disp.append(rset)

        # -- Sounds
        rx = RadioSettingValueInteger(0, 9, _sets.beeplvl)
        rset = RadioSetting("settings.beeplvl", "Beep Level", rx)
        sound.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.homebeep))
        rset = RadioSetting("settings.homebeep", "Home Chan Beep", rx)
        sound.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.keybeep))
        rset = RadioSetting("settings.keybeep", "Key Touch Beep", rx)
        sound.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.bandedgbeep))
        rset = RadioSetting("settings.bandedgbeep", "Band Edge Beep", rx)
        sound.append(rset)

        rx = RadioSettingValueBoolean(bool(_sets.scanstpbeep))
        rset = RadioSetting("settings.scanstpbeep", "Scan Stop Beep", rx)
        sound.append(rset)

        options = ["Off", "Mute", "Beep", "Mute & Beep"]
        rx = RadioSettingValueList(options, options[_sets.subandmute])
        rset = RadioSetting("settings.subandmute", "Sub Band Mute", rx)
        sound.append(rset)

        # --- DTMF Codes
        options = ["100", "200", "300", "500"]
        rx = RadioSettingValueList(options, options[_sets.dtmfspd])
        rset = RadioSetting("settings.dtmfspd", "DTMF Speed (mSecs)", rx)
        dtmf.append(rset)

        for kx in range(0, 16):
            stx = unpack_str(_dtm[kx].codes)
            rx = RadioSettingValueString(0, 24, stx)
            # NOTE the / to indicate indexed array
            rset = RadioSetting("dtmfcode/%d.codes" % kx, "DTMF Code %X" % kx,
                                rx)
            rset.set_apply_callback(pack_chars, _dtm, "codes", kx)
            dtmf.append(rset)

        # --- Program Scan Edges
        for kx in range(0, 25):
            stx = ""
            for i in range(0, 6):
                stx += chr(_pses[kx].name[i])
            stx = stx.rstrip()
            rx = RadioSettingValueString(0, 6, stx)
            rset = RadioSetting("pgmscanedge/%d.name" % kx,
                                "Program Scan %d Name" % kx, rx)
            rset.set_apply_callback(myset_psnam, _pses, kx, "name", 6)
            edges.append(rset)

            # Freq's use the multiplier flags
            fmult = 5000.0
            if _pses[kx].loflags == 0x10:
                fmult = 8333
            if _pses[kx].loflags == 0x08:
                fmult = 6250.0
            flow = (int(_pses[kx].lofreq) * fmult) / 1000000.0
            flow = round(flow, 4)

            fmult = 5000.0
            if _pses[kx].hiflags == 0x10:
                fmult = 8333
            if _pses[kx].hiflags == 0x08:
                fmult = 6250.0
            fhigh = (int(_pses[kx].hifreq) * fmult) / 1000000.0
            fhigh = round(fhigh, 4)
            if (flow > 0) and (flow >= fhigh):  # reverse em
                val = flow
                flow = fhigh
                fhigh = val
            rx = RadioSettingValueFloat(0, 550.0, flow, 0.010, 3)
            rset = RadioSetting("pgmscanedge/%d.lofreq" % kx,
                                "-- Scan %d Low Limit" % kx, rx)
            rset.set_apply_callback(myset_frqflgs, _pses, kx, "loflags",
                                    "lofreq")
            edges.append(rset)

            rx = RadioSettingValueFloat(0, 550.0, fhigh, 0.010, 3)
            rset = RadioSetting("pgmscanedge/%d.hifreq" % kx,
                                "-- Scan %d High Limit" % kx, rx)
            rset.set_apply_callback(myset_frqflgs, _pses, kx, "hiflags",
                                    "hifreq")
            edges.append(rset)

            # Tstep and Mode depend on the bands
            ndxt = 0
            ndxm = 0
            bxnd = 0
            tsopt = [
                "-", "5k", "6.25k", "10k", "12.5k", "15k", "20k", "25k", "30k",
                "50k"
            ]
            mdopt = ["-", "FM", "FM-N"]
            if fhigh > 0:
                if fhigh < 135.0:  # Air band
                    bxnd = 1
                    tsopt = ["-", "8.33k", "25k", "Auto"]
                    ndxt = _pses[kx].tstp
                    if ndxt == 0xe:  # Auto
                        ndxt = 3
                    elif ndxt == 8:  # 25k
                        ndxt = 2
                    elif ndxt == 2:  # 8.33k
                        ndxt = 1
                    else:
                        ndxt = 0
                    mdopt = ["-"]
                elif (flow >= 137.0) and (fhigh <= 174.0):  # VHF
                    ndxt = _pses[kx].tstp - 1
                    ndxm = _pses[kx].mode + 1
                    bxnd = 2
                elif (flow >= 375.0) and (fhigh <= 550.0):  # UHF
                    ndxt = _pses[kx].tstp - 1
                    ndxm = _pses[kx].mode + 1
                    bxnd = 3
                else:  # Mixed, ndx's = 0 default
                    tsopt = ["-"]
                    mdopt = ["-"]
                    bxnd = 4
                if (ndxt > 9) or (ndxt < 0):
                    ndxt = 0  # trap ff
                if ndxm > 2:
                    ndxm = 0
            # end if fhigh > 0
            rx = RadioSettingValueList(tsopt, tsopt[ndxt])
            rset = RadioSetting("pgmscanedge/%d.tstp" % kx,
                                "-- Scan %d Freq Step" % kx, rx)
            rset.set_apply_callback(myset_tsopt, _pses, kx, "tstp", bxnd)
            edges.append(rset)

            rx = RadioSettingValueList(mdopt, mdopt[ndxm])
            rset = RadioSetting("pgmscanedge/%d.mode" % kx,
                                "-- Scan %d Mode" % kx, rx)
            rset.set_apply_callback(myset_mdopt, _pses, kx, "mode", bxnd)
            edges.append(rset)
        # End for kx

        # --- Program Scan Links
        _psln = self._memobj.pslnam
        _pslg = self._memobj.pslgrps
        for kx in range(0, 10):
            stx = ""
            for i in range(0, 6):
                stx += chr(_psln[kx].nam[i])
            stx = stx.rstrip()
            rx = RadioSettingValueString(0, 6, stx)
            rset = RadioSetting("pslnam/%d.nam" % kx,
                                "Program Scan Link %d Name" % kx, rx)
            rset.set_apply_callback(myset_psnam, _psln, kx, "nam", 6)
            pslnk.append(rset)

            for px in range(0, 25):
                # Generate string numeric representation of 4-byte bitmask
                stx = ""
                for nx in range(0, 25):
                    if nx < 8:
                        if (_pslg[kx].msk[0] & (1 << nx)):
                            stx += "%0d, " % nx
                    elif (nx >= 8) and (nx < 16):
                        if (_pslg[kx].msk[1] & (1 << (nx - 8))):
                            sstx += "%0d, " % nx
                    elif (nx >= 16) and (nx < 24):
                        if (_pslg[kx].msk[2] & (1 << (nx - 16))):
                            stx += "%0d, " % nx
                    elif (nx >= 24):
                        if (_pslg[kx].msk[3] & (1 << (nx - 24))):
                            stx += "%0d, " % nx
            rx = RadioSettingValueString(0, 80, stx)
            rset = RadioSetting("pslgrps/%d.msk" % kx,
                                "--- Scan Link %d Scans" % kx, rx)
            rset.set_apply_callback(myset_bitmask, _pslg, kx, "msk", 25)
            pslnk.append(rset)
            # end for px
        # End for kx
        return group  # END get_settings()
コード例 #8
0
ファイル: uv5x3.py プロジェクト: Cabalist/chirp
    def get_settings(self):
        """Translate the bit in the mem_struct into settings in the UI"""
        _mem = self._memobj
        basic = RadioSettingGroup("basic", "Basic Settings")
        advanced = RadioSettingGroup("advanced", "Advanced Settings")
        other = RadioSettingGroup("other", "Other Settings")
        work = RadioSettingGroup("work", "Work Mode Settings")
        fm_preset = RadioSettingGroup("fm_preset", "FM Preset")
        dtmfe = RadioSettingGroup("dtmfe", "DTMF Encode Settings")
        dtmfd = RadioSettingGroup("dtmfd", "DTMF Decode Settings")
        service = RadioSettingGroup("service", "Service Settings")
        top = RadioSettings(basic, advanced, other, work, fm_preset, dtmfe,
                            dtmfd, service)

        # Basic settings
        if _mem.settings.squelch > 0x09:
            val = 0x00
        else:
            val = _mem.settings.squelch
        rs = RadioSetting(
            "settings.squelch", "Squelch",
            RadioSettingValueList(LIST_OFF1TO9, LIST_OFF1TO9[val]))
        basic.append(rs)

        if _mem.settings.save > 0x04:
            val = 0x00
        else:
            val = _mem.settings.save
        rs = RadioSetting("settings.save", "Battery Saver",
                          RadioSettingValueList(LIST_SAVE, LIST_SAVE[val]))
        basic.append(rs)

        if _mem.settings.vox > 0x0A:
            val = 0x00
        else:
            val = _mem.settings.vox
        rs = RadioSetting(
            "settings.vox", "Vox",
            RadioSettingValueList(LIST_OFF1TO10, LIST_OFF1TO10[val]))
        basic.append(rs)

        if _mem.settings.abr > 0x0A:
            val = 0x00
        else:
            val = _mem.settings.abr
        rs = RadioSetting(
            "settings.abr", "Backlight Timeout",
            RadioSettingValueList(LIST_OFF1TO10, LIST_OFF1TO10[val]))
        basic.append(rs)

        rs = RadioSetting("settings.tdr", "Dual Watch",
                          RadioSettingValueBoolean(_mem.settings.tdr))
        basic.append(rs)

        rs = RadioSetting("settings.beep", "Beep",
                          RadioSettingValueBoolean(_mem.settings.beep))
        basic.append(rs)

        if _mem.settings.timeout > 0x27:
            val = 0x03
        else:
            val = _mem.settings.timeout
        rs = RadioSetting(
            "settings.timeout", "Timeout Timer",
            RadioSettingValueList(LIST_TIMEOUT, LIST_TIMEOUT[val]))
        basic.append(rs)

        if _mem.settings.voice > 0x02:
            val = 0x01
        else:
            val = _mem.settings.voice
        rs = RadioSetting("settings.voice", "Voice Prompt",
                          RadioSettingValueList(LIST_VOICE, LIST_VOICE[val]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.dtmfst", "DTMF Sidetone",
            RadioSettingValueList(LIST_DTMFST,
                                  LIST_DTMFST[_mem.settings.dtmfst]))
        basic.append(rs)

        if _mem.settings.screv > 0x02:
            val = 0x01
        else:
            val = _mem.settings.screv
        rs = RadioSetting("settings.screv", "Scan Resume",
                          RadioSettingValueList(LIST_RESUME, LIST_RESUME[val]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.pttid", "When to send PTT ID",
            RadioSettingValueList(LIST_PTTID, LIST_PTTID[_mem.settings.pttid]))
        basic.append(rs)

        if _mem.settings.pttlt > 0x1E:
            val = 0x05
        else:
            val = _mem.settings.pttlt
        rs = RadioSetting("pttlt", "PTT ID Delay",
                          RadioSettingValueInteger(0, 50, val))
        basic.append(rs)

        rs = RadioSetting(
            "settings.mdfa", "Display Mode (A)",
            RadioSettingValueList(LIST_MODE, LIST_MODE[_mem.settings.mdfa]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.mdfb", "Display Mode (B)",
            RadioSettingValueList(LIST_MODE, LIST_MODE[_mem.settings.mdfb]))
        basic.append(rs)

        rs = RadioSetting("settings.sync", "Sync A & B",
                          RadioSettingValueBoolean(_mem.settings.sync))
        basic.append(rs)

        rs = RadioSetting(
            "settings.wtled", "Standby LED Color",
            RadioSettingValueList(LIST_COLOR, LIST_COLOR[_mem.settings.wtled]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.rxled", "RX LED Color",
            RadioSettingValueList(LIST_COLOR, LIST_COLOR[_mem.settings.rxled]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.txled", "TX LED Color",
            RadioSettingValueList(LIST_COLOR, LIST_COLOR[_mem.settings.txled]))
        basic.append(rs)

        if _mem.settings.almod > 0x02:
            val = 0x00
        else:
            val = _mem.settings.almod
        rs = RadioSetting("settings.almod", "Alarm Mode",
                          RadioSettingValueList(LIST_ALMOD, LIST_ALMOD[val]))
        basic.append(rs)

        if _mem.settings.tdrab > 0x02:
            val = 0x00
        else:
            val = _mem.settings.tdrab
        rs = RadioSetting("settings.tdrab", "Dual Watch TX Priority",
                          RadioSettingValueList(LIST_OFFAB, LIST_OFFAB[val]))
        basic.append(rs)

        rs = RadioSetting("settings.ste", "Squelch Tail Eliminate (HT to HT)",
                          RadioSettingValueBoolean(_mem.settings.ste))
        basic.append(rs)

        if _mem.settings.rpste > 0x0A:
            val = 0x00
        else:
            val = _mem.settings.rpste
        rs = RadioSetting("settings.rpste",
                          "Squelch Tail Eliminate (repeater)",
                          RadioSettingValueList(LIST_RPSTE, LIST_RPSTE[val]))
        basic.append(rs)

        if _mem.settings.rptrl > 0x0A:
            val = 0x00
        else:
            val = _mem.settings.rptrl
        rs = RadioSetting(
            "settings.rptrl", "STE Repeater Delay",
            RadioSettingValueList(LIST_STEDELAY, LIST_STEDELAY[val]))
        basic.append(rs)

        rs = RadioSetting(
            "settings.ponmsg", "Power-On Message",
            RadioSettingValueList(LIST_PONMSG,
                                  LIST_PONMSG[_mem.settings.ponmsg]))
        basic.append(rs)

        rs = RadioSetting("settings.roger", "Roger Beep",
                          RadioSettingValueBoolean(_mem.settings.roger))
        basic.append(rs)

        rs = RadioSetting("settings.dani", "Decode ANI",
                          RadioSettingValueBoolean(_mem.settings.dani))
        basic.append(rs)

        if _mem.settings.dtmfg > 0x3C:
            val = 0x14
        else:
            val = _mem.settings.dtmfg
        rs = RadioSetting("settings.dtmfg", "DTMF Gain",
                          RadioSettingValueInteger(0, 60, val))
        basic.append(rs)

        # Advanced settings
        rs = RadioSetting("settings.reset", "RESET Menu",
                          RadioSettingValueBoolean(_mem.settings.reset))
        advanced.append(rs)

        rs = RadioSetting("settings.menu", "All Menus",
                          RadioSettingValueBoolean(_mem.settings.menu))
        advanced.append(rs)

        rs = RadioSetting("settings.fmradio", "Broadcast FM Radio",
                          RadioSettingValueBoolean(_mem.settings.fmradio))
        advanced.append(rs)

        rs = RadioSetting("settings.alarm", "Alarm Sound",
                          RadioSettingValueBoolean(_mem.settings.alarm))
        advanced.append(rs)

        # Other settings
        def _filter(name):
            filtered = ""
            for char in str(name):
                if char in chirp_common.CHARSET_ASCII:
                    filtered += char
                else:
                    filtered += " "
            return filtered

        _msg = _mem.firmware_msg
        val = RadioSettingValueString(0, 7, _filter(_msg.line1))
        val.set_mutable(False)
        rs = RadioSetting("firmware_msg.line1", "Firmware Message 1", val)
        other.append(rs)

        val = RadioSettingValueString(0, 7, _filter(_msg.line2))
        val.set_mutable(False)
        rs = RadioSetting("firmware_msg.line2", "Firmware Message 2", val)
        other.append(rs)

        _msg = _mem.sixpoweron_msg
        val = RadioSettingValueString(0, 7, _filter(_msg.line1))
        val.set_mutable(False)
        rs = RadioSetting("sixpoweron_msg.line1", "6+Power-On Message 1", val)
        other.append(rs)
        val = RadioSettingValueString(0, 7, _filter(_msg.line2))
        val.set_mutable(False)
        rs = RadioSetting("sixpoweron_msg.line2", "6+Power-On Message 2", val)
        other.append(rs)

        _msg = _mem.poweron_msg
        rs = RadioSetting("poweron_msg.line1", "Power-On Message 1",
                          RadioSettingValueString(0, 7, _filter(_msg.line1)))
        other.append(rs)
        rs = RadioSetting("poweron_msg.line2", "Power-On Message 2",
                          RadioSettingValueString(0, 7, _filter(_msg.line2)))
        other.append(rs)

        if str(_mem.firmware_msg.line1) == "UVVG302":
            lower = 136
            upper = 174
        else:
            lower = 130
            upper = 179
        rs = RadioSetting(
            "limits.vhf.lower", "VHF Lower Limit (MHz)",
            RadioSettingValueInteger(lower, upper, _mem.limits.vhf.lower))
        other.append(rs)

        rs = RadioSetting(
            "limits.vhf.upper", "VHF Upper Limit (MHz)",
            RadioSettingValueInteger(lower, upper, _mem.limits.vhf.upper))
        other.append(rs)

        if str(_mem.firmware_msg.line1) == "UVVG302":
            lower = 200
            upper = 230
        else:
            lower = 220
            upper = 225
        rs = RadioSetting(
            "limits.vhf2.lower", "VHF2 Lower Limit (MHz)",
            RadioSettingValueInteger(lower, upper, _mem.limits.vhf2.lower))
        other.append(rs)

        rs = RadioSetting(
            "limits.vhf2.upper", "VHF2 Upper Limit (MHz)",
            RadioSettingValueInteger(lower, upper, _mem.limits.vhf2.upper))
        other.append(rs)

        if str(_mem.firmware_msg.line1) == "UVVG302":
            lower = 400
            upper = 480
        else:
            lower = 400
            upper = 520
        rs = RadioSetting(
            "limits.uhf.lower", "UHF Lower Limit (MHz)",
            RadioSettingValueInteger(lower, upper, _mem.limits.uhf.lower))
        other.append(rs)

        rs = RadioSetting(
            "limits.uhf.upper", "UHF Upper Limit (MHz)",
            RadioSettingValueInteger(lower, upper, _mem.limits.uhf.upper))
        other.append(rs)

        # Work mode settings
        rs = RadioSetting(
            "settings.displayab", "Display",
            RadioSettingValueList(LIST_AB, LIST_AB[_mem.settings.displayab]))
        work.append(rs)

        rs = RadioSetting(
            "settings.workmode", "VFO/MR Mode",
            RadioSettingValueList(LIST_WORKMODE,
                                  LIST_WORKMODE[_mem.settings.workmode]))
        work.append(rs)

        rs = RadioSetting("settings.keylock", "Keypad Lock",
                          RadioSettingValueBoolean(_mem.settings.keylock))
        work.append(rs)

        rs = RadioSetting(
            "wmchannel.mrcha", "MR A Channel",
            RadioSettingValueInteger(0, 127, _mem.wmchannel.mrcha))
        work.append(rs)

        rs = RadioSetting(
            "wmchannel.mrchb", "MR B Channel",
            RadioSettingValueInteger(0, 127, _mem.wmchannel.mrchb))
        work.append(rs)

        def convert_bytes_to_freq(bytes):
            real_freq = 0
            for byte in bytes:
                real_freq = (real_freq * 10) + byte
            return chirp_common.format_freq(real_freq * 10)

        def my_validate(value):
            _vhf_lower = int(_mem.limits.vhf.lower)
            _vhf_upper = int(_mem.limits.vhf.upper)
            _vhf2_lower = int(_mem.limits.vhf2.lower)
            _vhf2_upper = int(_mem.limits.vhf2.upper)
            _uhf_lower = int(_mem.limits.uhf.lower)
            _uhf_upper = int(_mem.limits.uhf.upper)
            value = chirp_common.parse_freq(value)
            msg = ("Can't be less than %i.0000")
            if value > 99000000 and value < _vhf_lower * 1000000:
                raise InvalidValueError(msg % (_vhf_lower))
            msg = ("Can't be between %i.9975-%i.0000")
            if (_vhf_upper + 1) * 1000000 <= value and \
                value < _vhf2_lower * 1000000:
                raise InvalidValueError(msg % (_vhf_upper, _vhf2_lower))
            if (_vhf2_upper + 1) * 1000000 <= value and \
                value < _uhf_lower * 1000000:
                raise InvalidValueError(msg % (_vhf2_upper, _uhf_lower))
            msg = ("Can't be greater than %i.9975")
            if value > 99000000 and value >= (_uhf_upper + 1) * 1000000:
                raise InvalidValueError(msg % (_uhf_upper))
            return chirp_common.format_freq(value)

        def apply_freq(setting, obj):
            value = chirp_common.parse_freq(str(setting.value)) / 10
            for i in range(7, -1, -1):
                obj.freq[i] = value % 10
                value /= 10

        val1a = RadioSettingValueString(0, 10,
                                        convert_bytes_to_freq(_mem.vfo.a.freq))
        val1a.set_validate_callback(my_validate)
        rs = RadioSetting("vfo.a.freq", "VFO A Frequency", val1a)
        rs.set_apply_callback(apply_freq, _mem.vfo.a)
        work.append(rs)

        val1b = RadioSettingValueString(0, 10,
                                        convert_bytes_to_freq(_mem.vfo.b.freq))
        val1b.set_validate_callback(my_validate)
        rs = RadioSetting("vfo.b.freq", "VFO B Frequency", val1b)
        rs.set_apply_callback(apply_freq, _mem.vfo.b)
        work.append(rs)

        rs = RadioSetting(
            "vfo.a.sftd", "VFO A Shift",
            RadioSettingValueList(LIST_SHIFTD, LIST_SHIFTD[_mem.vfo.a.sftd]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.b.sftd", "VFO B Shift",
            RadioSettingValueList(LIST_SHIFTD, LIST_SHIFTD[_mem.vfo.b.sftd]))
        work.append(rs)

        def convert_bytes_to_offset(bytes):
            real_offset = 0
            for byte in bytes:
                real_offset = (real_offset * 10) + byte
            return chirp_common.format_freq(real_offset * 1000)

        def apply_offset(setting, obj):
            value = chirp_common.parse_freq(str(setting.value)) / 1000
            for i in range(5, -1, -1):
                obj.offset[i] = value % 10
                value /= 10

        val1a = RadioSettingValueString(
            0, 10, convert_bytes_to_offset(_mem.vfo.a.offset))
        rs = RadioSetting("vfo.a.offset", "VFO A Offset", val1a)
        rs.set_apply_callback(apply_offset, _mem.vfo.a)
        work.append(rs)

        val1b = RadioSettingValueString(
            0, 10, convert_bytes_to_offset(_mem.vfo.b.offset))
        rs = RadioSetting("vfo.b.offset", "VFO B Offset", val1b)
        rs.set_apply_callback(apply_offset, _mem.vfo.b)
        work.append(rs)

        rs = RadioSetting(
            "vfo.a.txpower", "VFO A Power",
            RadioSettingValueList(LIST_TXPOWER,
                                  LIST_TXPOWER[_mem.vfo.a.txpower]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.b.txpower", "VFO B Power",
            RadioSettingValueList(LIST_TXPOWER,
                                  LIST_TXPOWER[_mem.vfo.b.txpower]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.a.widenarr", "VFO A Bandwidth",
            RadioSettingValueList(LIST_BANDWIDTH,
                                  LIST_BANDWIDTH[_mem.vfo.a.widenarr]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.b.widenarr", "VFO B Bandwidth",
            RadioSettingValueList(LIST_BANDWIDTH,
                                  LIST_BANDWIDTH[_mem.vfo.b.widenarr]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.a.scode", "VFO A S-CODE",
            RadioSettingValueList(LIST_SCODE, LIST_SCODE[_mem.vfo.a.scode]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.b.scode", "VFO B S-CODE",
            RadioSettingValueList(LIST_SCODE, LIST_SCODE[_mem.vfo.b.scode]))
        work.append(rs)

        rs = RadioSetting(
            "vfo.a.step", "VFO A Tuning Step",
            RadioSettingValueList(LIST_STEP, LIST_STEP[_mem.vfo.a.step]))
        work.append(rs)
        rs = RadioSetting(
            "vfo.b.step", "VFO B Tuning Step",
            RadioSettingValueList(LIST_STEP, LIST_STEP[_mem.vfo.b.step]))
        work.append(rs)

        # broadcast FM settings
        _fm_presets = self._memobj.fm_presets
        if _fm_presets <= 108.0 * 10 - 650:
            preset = _fm_presets / 10.0 + 65
        elif _fm_presets >= 65.0 * 10 and _fm_presets <= 108.0 * 10:
            preset = _fm_presets / 10.0
        else:
            preset = 76.0
        rs = RadioSetting("fm_presets", "FM Preset(MHz)",
                          RadioSettingValueFloat(65, 108.0, preset, 0.1, 1))
        fm_preset.append(rs)

        # DTMF encode settings
        for i in range(0, 15):
            _codeobj = self._memobj.pttid[i].code
            _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
            val = RadioSettingValueString(0, 16, _code, False)
            val.set_charset(DTMF_CHARS)
            rs = RadioSetting("pttid/%i.code" % i, "Signal Code %i" % (i + 1),
                              val)

            def apply_code(setting, obj):
                code = []
                for j in range(0, 16):
                    try:
                        code.append(DTMF_CHARS.index(str(setting.value)[j]))
                    except IndexError:
                        code.append(0xFF)
                obj.code = code

            rs.set_apply_callback(apply_code, self._memobj.pttid[i])
            dtmfe.append(rs)

        if _mem.ani.dtmfon > 0xC3:
            val = 0x03
        else:
            val = _mem.ani.dtmfon
        rs = RadioSetting(
            "ani.dtmfon", "DTMF Speed (on)",
            RadioSettingValueList(LIST_DTMFSPEED, LIST_DTMFSPEED[val]))
        dtmfe.append(rs)

        if _mem.ani.dtmfoff > 0xC3:
            val = 0x03
        else:
            val = _mem.ani.dtmfoff
        rs = RadioSetting(
            "ani.dtmfoff", "DTMF Speed (off)",
            RadioSettingValueList(LIST_DTMFSPEED, LIST_DTMFSPEED[val]))
        dtmfe.append(rs)

        _codeobj = self._memobj.ani.code
        _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 7, _code, False)
        val.set_charset(DTMF_CHARS)
        rs = RadioSetting("ani.code", "ANI Code", val)

        def apply_code(setting, obj):
            code = []
            for j in range(0, 7):
                try:
                    code.append(DTMF_CHARS.index(str(setting.value)[j]))
                except IndexError:
                    code.append(0xFF)
            obj.code = code

        rs.set_apply_callback(apply_code, self._memobj.ani)
        dtmfe.append(rs)

        rs = RadioSetting(
            "ani.aniid", "When to send ANI ID",
            RadioSettingValueList(LIST_PTTID, LIST_PTTID[_mem.ani.aniid]))
        dtmfe.append(rs)

        # DTMF decode settings
        rs = RadioSetting("ani.mastervice", "Master and Vice ID",
                          RadioSettingValueBoolean(_mem.ani.mastervice))
        dtmfd.append(rs)

        _codeobj = _mem.ani.masterid
        _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 5, _code, False)
        val.set_charset(DTMF_CHARS)
        rs = RadioSetting("ani.masterid", "Master Control ID", val)

        def apply_code(setting, obj):
            code = []
            for j in range(0, 5):
                try:
                    code.append(DTMF_CHARS.index(str(setting.value)[j]))
                except IndexError:
                    code.append(0xFF)
            obj.masterid = code

        rs.set_apply_callback(apply_code, self._memobj.ani)
        dtmfd.append(rs)

        rs = RadioSetting("ani.minspection", "Master Inspection",
                          RadioSettingValueBoolean(_mem.ani.minspection))
        dtmfd.append(rs)

        rs = RadioSetting("ani.mmonitor", "Master Monitor",
                          RadioSettingValueBoolean(_mem.ani.mmonitor))
        dtmfd.append(rs)

        rs = RadioSetting("ani.mstun", "Master Stun",
                          RadioSettingValueBoolean(_mem.ani.mstun))
        dtmfd.append(rs)

        rs = RadioSetting("ani.mkill", "Master Kill",
                          RadioSettingValueBoolean(_mem.ani.mkill))
        dtmfd.append(rs)

        rs = RadioSetting("ani.mrevive", "Master Revive",
                          RadioSettingValueBoolean(_mem.ani.mrevive))
        dtmfd.append(rs)

        _codeobj = _mem.ani.viceid
        _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 5, _code, False)
        val.set_charset(DTMF_CHARS)
        rs = RadioSetting("ani.viceid", "Vice Control ID", val)

        def apply_code(setting, obj):
            code = []
            for j in range(0, 5):
                try:
                    code.append(DTMF_CHARS.index(str(setting.value)[j]))
                except IndexError:
                    code.append(0xFF)
            obj.viceid = code

        rs.set_apply_callback(apply_code, self._memobj.ani)
        dtmfd.append(rs)

        rs = RadioSetting("ani.vinspection", "Vice Inspection",
                          RadioSettingValueBoolean(_mem.ani.vinspection))
        dtmfd.append(rs)

        rs = RadioSetting("ani.vmonitor", "Vice Monitor",
                          RadioSettingValueBoolean(_mem.ani.vmonitor))
        dtmfd.append(rs)

        rs = RadioSetting("ani.vstun", "Vice Stun",
                          RadioSettingValueBoolean(_mem.ani.vstun))
        dtmfd.append(rs)

        rs = RadioSetting("ani.vkill", "Vice Kill",
                          RadioSettingValueBoolean(_mem.ani.vkill))
        dtmfd.append(rs)

        rs = RadioSetting("ani.vrevive", "Vice Revive",
                          RadioSettingValueBoolean(_mem.ani.vrevive))
        dtmfd.append(rs)

        _codeobj = _mem.ani.inspection
        _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 8, _code, False)
        val.set_charset(DTMF_CHARS)
        rs = RadioSetting("ani.inspection", "Inspection Code", val)

        def apply_code(setting, obj):
            code = []
            for j in range(0, 8):
                try:
                    code.append(DTMF_CHARS.index(str(setting.value)[j]))
                except IndexError:
                    code.append(0xFF)
            obj.inspection = code

        rs.set_apply_callback(apply_code, self._memobj.ani)
        dtmfd.append(rs)

        _codeobj = _mem.ani.monitor
        _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 8, _code, False)
        val.set_charset(DTMF_CHARS)
        rs = RadioSetting("ani.monitor", "Monitor Code", val)

        def apply_code(setting, obj):
            code = []
            for j in range(0, 8):
                try:
                    code.append(DTMF_CHARS.index(str(setting.value)[j]))
                except IndexError:
                    code.append(0xFF)
            obj.monitor = code

        rs.set_apply_callback(apply_code, self._memobj.ani)
        dtmfd.append(rs)

        _codeobj = _mem.ani.alarmcode
        _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 8, _code, False)
        val.set_charset(DTMF_CHARS)
        rs = RadioSetting("ani.alarm", "Alarm Code", val)

        def apply_code(setting, obj):
            code = []
            for j in range(0, 8):
                try:
                    code.append(DTMF_CHARS.index(str(setting.value)[j]))
                except IndexError:
                    code.append(0xFF)
            obj.alarmcode = code

        rs.set_apply_callback(apply_code, self._memobj.ani)
        dtmfd.append(rs)

        _codeobj = _mem.ani.stun
        _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 8, _code, False)
        val.set_charset(DTMF_CHARS)
        rs = RadioSetting("ani.stun", "Stun Code", val)

        def apply_code(setting, obj):
            code = []
            for j in range(0, 8):
                try:
                    code.append(DTMF_CHARS.index(str(setting.value)[j]))
                except IndexError:
                    code.append(0xFF)
            obj.stun = code

        rs.set_apply_callback(apply_code, self._memobj.ani)
        dtmfd.append(rs)

        _codeobj = _mem.ani.kill
        _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 8, _code, False)
        val.set_charset(DTMF_CHARS)
        rs = RadioSetting("ani.kill", "Kill Code", val)

        def apply_code(setting, obj):
            code = []
            for j in range(0, 8):
                try:
                    code.append(DTMF_CHARS.index(str(setting.value)[j]))
                except IndexError:
                    code.append(0xFF)
            obj.kill = code

        rs.set_apply_callback(apply_code, self._memobj.ani)
        dtmfd.append(rs)

        _codeobj = _mem.ani.revive
        _code = "".join([DTMF_CHARS[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 8, _code, False)
        val.set_charset(DTMF_CHARS)
        rs = RadioSetting("ani.revive", "Revive Code", val)

        def apply_code(setting, obj):
            code = []
            for j in range(0, 8):
                try:
                    code.append(DTMF_CHARS.index(str(setting.value)[j]))
                except IndexError:
                    code.append(0xFF)
            obj.revive = code

        rs.set_apply_callback(apply_code, self._memobj.ani)
        dtmfd.append(rs)

        def apply_dmtf_listvalue(setting, obj):
            LOG.debug("Setting value: " + str(setting.value) + " from list")
            val = str(setting.value)
            index = LIST_DTMF_SPECIAL_DIGITS.index(val)
            val = LIST_DTMF_SPECIAL_VALUES[index]
            obj.set_value(val)

        if _mem.ani.groupcode in LIST_DTMF_SPECIAL_VALUES:
            idx = LIST_DTMF_SPECIAL_VALUES.index(_mem.ani.groupcode)
        else:
            idx = LIST_DTMF_SPECIAL_VALUES.index(0x0B)
        rs = RadioSetting(
            "ani.groupcode", "Group Code",
            RadioSettingValueList(LIST_DTMF_SPECIAL_DIGITS,
                                  LIST_DTMF_SPECIAL_DIGITS[idx]))
        rs.set_apply_callback(apply_dmtf_listvalue, _mem.ani.groupcode)
        dtmfd.append(rs)

        if _mem.ani.spacecode in LIST_DTMF_SPECIAL_VALUES:
            idx = LIST_DTMF_SPECIAL_VALUES.index(_mem.ani.spacecode)
        else:
            idx = LIST_DTMF_SPECIAL_VALUES.index(0x0C)
        rs = RadioSetting(
            "ani.spacecode", "Space Code",
            RadioSettingValueList(LIST_DTMF_SPECIAL_DIGITS,
                                  LIST_DTMF_SPECIAL_DIGITS[idx]))
        rs.set_apply_callback(apply_dmtf_listvalue, _mem.ani.spacecode)
        dtmfd.append(rs)

        if _mem.ani.resettime > 0x9F:
            val = 0x4F
        else:
            val = _mem.ani.resettime
        rs = RadioSetting(
            "ani.resettime", "Reset Time",
            RadioSettingValueList(LIST_RESETTIME, LIST_RESETTIME[val]))
        dtmfd.append(rs)

        if _mem.ani.delayproctime > 0x27:
            val = 0x04
        else:
            val = _mem.ani.delayproctime
        rs = RadioSetting(
            "ani.delayproctime", "Delay Processing Time",
            RadioSettingValueList(LIST_DELAYPROCTIME, LIST_DELAYPROCTIME[val]))
        dtmfd.append(rs)

        # Service settings
        for band in ["vhf", "uhf"]:
            for index in range(0, 10):
                key = "squelch.%s.sql%i" % (band, index)
                if band == "vhf":
                    _obj = self._memobj.squelch.vhf
                elif band == "uhf":
                    _obj = self._memobj.squelch.uhf
                val = RadioSettingValueInteger(
                    0, 123, getattr(_obj, "sql%i" % (index)))
                if index == 0:
                    val.set_mutable(False)
                name = "%s Squelch %i" % (band.upper(), index)
                rs = RadioSetting(key, name, val)
                service.append(rs)

        return top
コード例 #9
0
ファイル: lt725uv.py プロジェクト: SDoradus/py3-CHIRP
    def get_settings(self):
        """Translate the bit in the mem_struct into settings in the UI"""
        # Define mem struct write-back shortcuts
        _sets = self._memobj.settings
        _vfoa = self._memobj.upper.vfoa
        _vfob = self._memobj.lower.vfob
        _lims = self._memobj.hello_lims
        _codes = self._memobj.codes
        _dtmf = self._memobj.dtmf_tab

        basic = RadioSettingGroup("basic", "Basic Settings")
        a_band = RadioSettingGroup("a_band", "VFO A-Upper Settings")
        b_band = RadioSettingGroup("b_band", "VFO B-Lower Settings")
        codes = RadioSettingGroup("codes", "Codes & DTMF Groups")
        lims = RadioSettingGroup("lims", "PowerOn & Freq Limits")
        group = RadioSettings(basic, a_band, b_band, lims, codes)

        # Basic Settings
        bnd_mode = RadioSetting(
            "settings.init_bank", "TDR Band Default",
            RadioSettingValueList(LIST_TDR_DEF, LIST_TDR_DEF[_sets.init_bank]))
        basic.append(bnd_mode)

        volume = RadioSetting("settings.volume", "Volume",
                              RadioSettingValueInteger(0, 20, _sets.volume))
        basic.append(volume)

        val = _vfoa.bpower  # 2bits values 0,1,2= Low, Mid, High
        rx = RadioSettingValueList(LIST_BPOWER, LIST_BPOWER[val])
        powera = RadioSetting("upper.vfoa.bpower", "Power (Upper)", rx)
        basic.append(powera)

        val = _vfob.bpower
        rx = RadioSettingValueList(LIST_BPOWER, LIST_BPOWER[val])
        powerb = RadioSetting("lower.vfob.bpower", "Power (Lower)", rx)
        basic.append(powerb)

        def my_word2raw(setting, obj, atrb, mlt=10):
            """Callback function to convert UI floating value to u16 int"""
            if str(setting.value) == "Off":
                frq = 0x0FFFF
            else:
                frq = int(float(str(setting.value)) * float(mlt))
            if frq == 0:
                frq = 0xFFFF
            setattr(obj, atrb, frq)
            return

        def my_adjraw(setting, obj, atrb, fix):
            """Callback: add or subtract fix from value."""
            vx = int(str(setting.value))
            value = vx + int(fix)
            if value < 0:
                value = 0
            if atrb == "frq_chn_mode" and int(str(setting.value)) == 2:
                value = vx * 2  # Special handling for frq_chn_mode
            setattr(obj, atrb, value)
            return

        def my_dbl2raw(setting, obj, atrb, flg=1):
            """Callback: convert from freq 146.7600 to 14760000 U32."""
            value = chirp_common.parse_freq(str(setting.value)) / 10
            # flg=1 means 0 becomes ff, else leave as possible 0
            if flg == 1 and value == 0:
                value = 0xFFFFFFFF
            setattr(obj, atrb, value)
            return

        def my_val_list(setting, obj, atrb):
            """Callback:from ValueList with non-sequential, actual values."""
            value = int(str(setting.value))  # Get the integer value
            if atrb == "tot":
                value = int(value / 30)  # 30 second increments
            setattr(obj, atrb, value)
            return

        def my_spcl(setting, obj, atrb):
            """Callback: Special handling based on atrb."""
            if atrb == "frq_chn_mode":
                idx = LIST_VFOMODE.index(str(setting.value))  # Returns 0 or 1
                value = idx * 2  # Set bit 1
            setattr(obj, atrb, value)
            return

        def my_tone_strn(obj, is_atr, pol_atr, tone_atr):
            """Generate the CTCS/DCS tone code string."""
            vx = int(getattr(obj, tone_atr))
            if vx == 16383 or vx == 0:
                return "Off"  # 16383 is all bits set
            if getattr(obj, is_atr) == 0:  # Simple CTCSS code
                tstr = str(vx / 10.0)
            else:  # DCS
                if getattr(obj, pol_atr) == 0:
                    tstr = "D{:03x}R".format(vx)
                else:
                    tstr = "D{:03x}N".format(vx)
            return tstr

        def my_set_tone(setting, obj, is_atr, pol_atr, tone_atr):
            """Callback- create the tone setting from string code."""
            sx = str(setting.value)  # '131.8'  or 'D231N' or 'Off'
            if sx == "Off":
                isx = 1
                polx = 1
                tonx = 0x3FFF
            elif sx[0] == "D":  # DCS
                isx = 1
                if sx[4] == "N":
                    polx = 1
                else:
                    polx = 0
                tonx = int(sx[1:4], 16)
            else:  # CTCSS
                isx = 0
                polx = 0
                tonx = int(float(sx) * 10.0)
            setattr(obj, is_atr, isx)
            setattr(obj, pol_atr, polx)
            setattr(obj, tone_atr, tonx)
            return

        val = _sets.fm_freq / 10.0
        if val == 0:
            val = 88.9  # 0 is not valid
        rx = RadioSettingValueFloat(65, 108.0, val, 0.1, 1)
        rs = RadioSetting("settings.fm_freq", "FM Broadcast Freq (MHz)", rx)
        rs.set_apply_callback(my_word2raw, _sets, "fm_freq")
        basic.append(rs)

        wtled = RadioSetting(
            "settings.wtled", "Standby LED Color",
            RadioSettingValueList(LIST_COLOR, LIST_COLOR[_sets.wtled]))
        basic.append(wtled)

        rxled = RadioSetting(
            "settings.rxled", "RX LED Color",
            RadioSettingValueList(LIST_COLOR, LIST_COLOR[_sets.rxled]))
        basic.append(rxled)

        txled = RadioSetting(
            "settings.txled", "TX LED Color",
            RadioSettingValueList(LIST_COLOR, LIST_COLOR[_sets.txled]))
        basic.append(txled)

        ledsw = RadioSetting(
            "settings.ledsw", "Back light mode",
            RadioSettingValueList(LIST_LEDSW, LIST_LEDSW[_sets.ledsw]))
        basic.append(ledsw)

        beep = RadioSetting("settings.beep", "Beep",
                            RadioSettingValueBoolean(bool(_sets.beep)))
        basic.append(beep)

        ring = RadioSetting(
            "settings.ring", "Ring",
            RadioSettingValueList(LIST_RING, LIST_RING[_sets.ring]))
        basic.append(ring)

        bcl = RadioSetting("settings.bcl", "Busy channel lockout",
                           RadioSettingValueBoolean(bool(_sets.bcl)))
        basic.append(bcl)

        if _vfoa.sql == 0xFF:
            val = 0x04
        else:
            val = _vfoa.sql
        sqla = RadioSetting("upper.vfoa.sql", "Squelch (Upper)",
                            RadioSettingValueInteger(0, 9, val))
        basic.append(sqla)

        if _vfob.sql == 0xFF:
            val = 0x04
        else:
            val = _vfob.sql
        sqlb = RadioSetting("lower.vfob.sql", "Squelch (Lower)",
                            RadioSettingValueInteger(0, 9, val))
        basic.append(sqlb)

        tmp = str(int(_sets.tot) * 30)  # 30 sec step counter
        rs = RadioSetting("settings.tot", "Transmit Timeout (Secs)",
                          RadioSettingValueList(LIST_TIMEOUT, tmp))
        rs.set_apply_callback(my_val_list, _sets, "tot")
        basic.append(rs)

        tmp = str(int(_sets.sig_freq))
        rs = RadioSetting("settings.sig_freq", "Single Signaling Tone (Htz)",
                          RadioSettingValueList(LIST_SSF, tmp))
        rs.set_apply_callback(my_val_list, _sets, "sig_freq")
        basic.append(rs)

        tmp = str(int(_sets.dtmf_txms))
        rs = RadioSetting("settings.dtmf_txms", "DTMF Tx Duration (mSecs)",
                          RadioSettingValueList(LIST_DTMFTX, tmp))
        rs.set_apply_callback(my_val_list, _sets, "dtmf_txms")
        basic.append(rs)

        rs = RadioSetting("settings.rptr_mode", "Repeater Mode",
                          RadioSettingValueBoolean(bool(_sets.rptr_mode)))
        basic.append(rs)

        # UPPER BAND SETTINGS

        # Freq Mode, convert bit 1 state to index pointer
        val = _vfoa.frq_chn_mode / 2

        rx = RadioSettingValueList(LIST_VFOMODE, LIST_VFOMODE[val])
        rs = RadioSetting("upper.vfoa.frq_chn_mode", "Default Mode", rx)
        rs.set_apply_callback(my_spcl, _vfoa, "frq_chn_mode")
        a_band.append(rs)

        val = _vfoa.chan_num + 1  # Add 1 for 1-128 displayed
        rs = RadioSetting("upper.vfoa.chan_num", "Initial Chan",
                          RadioSettingValueInteger(1, 128, val))
        rs.set_apply_callback(my_adjraw, _vfoa, "chan_num", -1)
        a_band.append(rs)

        val = _vfoa.rxfreq / 100000.0
        if (val < 136.0 or val > 176.0):
            val = 146.520  # 2m calling
        rs = RadioSetting("upper.vfoa.rxfreq ", "Default Recv Freq (MHz)",
                          RadioSettingValueFloat(136.0, 176.0, val, 0.001, 5))
        rs.set_apply_callback(my_dbl2raw, _vfoa, "rxfreq")
        a_band.append(rs)

        tmp = my_tone_strn(_vfoa, "is_rxdigtone", "rxdtcs_pol", "rx_tone")
        rs = RadioSetting("rx_tone", "Default Recv CTCSS (Htz)",
                          RadioSettingValueList(LIST_CTCSS, tmp))
        rs.set_apply_callback(my_set_tone, _vfoa, "is_rxdigtone", "rxdtcs_pol",
                              "rx_tone")
        a_band.append(rs)

        rx = RadioSettingValueList(LIST_RECVMODE, LIST_RECVMODE[_vfoa.rx_mode])
        rs = RadioSetting("upper.vfoa.rx_mode", "Default Recv Mode", rx)
        a_band.append(rs)

        tmp = my_tone_strn(_vfoa, "is_txdigtone", "txdtcs_pol", "tx_tone")
        rs = RadioSetting("tx_tone", "Default Xmit CTCSS (Htz)",
                          RadioSettingValueList(LIST_CTCSS, tmp))
        rs.set_apply_callback(my_set_tone, _vfoa, "is_txdigtone", "txdtcs_pol",
                              "tx_tone")
        a_band.append(rs)

        rs = RadioSetting(
            "upper.vfoa.launch_sig", "Launch Signaling",
            RadioSettingValueList(LIST_SIGNAL, LIST_SIGNAL[_vfoa.launch_sig]))
        a_band.append(rs)

        rx = RadioSettingValueList(LIST_SIGNAL, LIST_SIGNAL[_vfoa.tx_end_sig])
        rs = RadioSetting("upper.vfoa.tx_end_sig", "Xmit End Signaling", rx)
        a_band.append(rs)

        rx = RadioSettingValueList(LIST_BW, LIST_BW[_vfoa.fm_bw])
        rs = RadioSetting("upper.vfoa.fm_bw", "Wide/Narrow Band", rx)
        a_band.append(rs)

        rx = RadioSettingValueBoolean(bool(_vfoa.cmp_nder))
        rs = RadioSetting("upper.vfoa.cmp_nder", "Compandor", rx)
        a_band.append(rs)

        rs = RadioSetting("upper.vfoa.scrm_blr", "Scrambler",
                          RadioSettingValueBoolean(bool(_vfoa.scrm_blr)))
        a_band.append(rs)

        rx = RadioSettingValueList(LIST_SHIFT, LIST_SHIFT[_vfoa.shift])
        rs = RadioSetting("upper.vfoa.shift", "Xmit Shift", rx)
        a_band.append(rs)

        val = _vfoa.offset / 100000.0
        rs = RadioSetting("upper.vfoa.offset", "Xmit Offset (MHz)",
                          RadioSettingValueFloat(0, 100.0, val, 0.001, 3))
        # Allow zero value
        rs.set_apply_callback(my_dbl2raw, _vfoa, "offset", 0)
        a_band.append(rs)

        tmp = str(_vfoa.step / 100.0)
        rs = RadioSetting("step", "Freq step (KHz)",
                          RadioSettingValueList(LIST_STEPS, tmp))
        rs.set_apply_callback(my_word2raw, _vfoa, "step", 100)
        a_band.append(rs)

        # LOWER BAND SETTINGS

        val = _vfob.frq_chn_mode / 2
        rx = RadioSettingValueList(LIST_VFOMODE, LIST_VFOMODE[val])
        rs = RadioSetting("lower.vfob.frq_chn_mode", "Default Mode", rx)
        rs.set_apply_callback(my_spcl, _vfob, "frq_chn_mode")
        b_band.append(rs)

        val = _vfob.chan_num + 1
        rs = RadioSetting("lower.vfob.chan_num", "Initial Chan",
                          RadioSettingValueInteger(0, 127, val))
        rs.set_apply_callback(my_adjraw, _vfob, "chan_num", -1)
        b_band.append(rs)

        val = _vfob.rxfreq / 100000.0
        if (val < 400.0 or val > 480.0):
            val = 446.0  # UHF calling
        rs = RadioSetting("lower.vfob.rxfreq ", "Default Recv Freq (MHz)",
                          RadioSettingValueFloat(400.0, 480.0, val, 0.001, 5))
        rs.set_apply_callback(my_dbl2raw, _vfob, "rxfreq")
        b_band.append(rs)

        tmp = my_tone_strn(_vfob, "is_rxdigtone", "rxdtcs_pol", "rx_tone")
        rs = RadioSetting("rx_tone", "Default Recv CTCSS (Htz)",
                          RadioSettingValueList(LIST_CTCSS, tmp))
        rs.set_apply_callback(my_set_tone, _vfob, "is_rxdigtone", "rxdtcs_pol",
                              "rx_tone")
        b_band.append(rs)

        rx = RadioSettingValueList(LIST_RECVMODE, LIST_RECVMODE[_vfob.rx_mode])
        rs = RadioSetting("lower.vfob.rx_mode", "Default Recv Mode", rx)
        b_band.append(rs)

        tmp = my_tone_strn(_vfob, "is_txdigtone", "txdtcs_pol", "tx_tone")
        rs = RadioSetting("tx_tone", "Default Xmit CTCSS (Htz)",
                          RadioSettingValueList(LIST_CTCSS, tmp))
        rs.set_apply_callback(my_set_tone, _vfob, "is_txdigtone", "txdtcs_pol",
                              "tx_tone")
        b_band.append(rs)

        rx = RadioSettingValueList(LIST_SIGNAL, LIST_SIGNAL[_vfob.launch_sig])
        rs = RadioSetting("lower.vfob.launch_sig", "Launch Signaling", rx)
        b_band.append(rs)

        rx = RadioSettingValueList(LIST_SIGNAL, LIST_SIGNAL[_vfob.tx_end_sig])
        rs = RadioSetting("lower.vfob.tx_end_sig", "Xmit End Signaling", rx)
        b_band.append(rs)

        rx = RadioSettingValueList(LIST_BW, LIST_BW[_vfob.fm_bw])
        rs = RadioSetting("lower.vfob.fm_bw", "Wide/Narrow Band", rx)
        b_band.append(rs)

        rs = RadioSetting("lower.vfob.cmp_nder", "Compandor",
                          RadioSettingValueBoolean(bool(_vfob.cmp_nder)))
        b_band.append(rs)

        rs = RadioSetting("lower.vfob.scrm_blr", "Scrambler",
                          RadioSettingValueBoolean(bool(_vfob.scrm_blr)))
        b_band.append(rs)

        rx = RadioSettingValueList(LIST_SHIFT, LIST_SHIFT[_vfob.shift])
        rs = RadioSetting("lower.vfob.shift", "Xmit Shift", rx)
        b_band.append(rs)

        val = _vfob.offset / 100000.0
        rs = RadioSetting("lower.vfob.offset", "Xmit Offset (MHz)",
                          RadioSettingValueFloat(0, 100.0, val, 0.001, 3))
        rs.set_apply_callback(my_dbl2raw, _vfob, "offset", 0)
        b_band.append(rs)

        tmp = str(_vfob.step / 100.0)
        rs = RadioSetting("step", "Freq step (KHz)",
                          RadioSettingValueList(LIST_STEPS, tmp))
        rs.set_apply_callback(my_word2raw, _vfob, "step", 100)
        b_band.append(rs)

        # PowerOn & Freq Limits Settings

        def chars2str(cary, knt):
            """Convert raw memory char array to a string: NOT a callback."""
            stx = ""
            for char in cary[:knt]:
                stx += chr(char)
            return stx

        def my_str2ary(setting, obj, atrba, atrbc):
            """Callback: convert 7-char string to char array with count."""
            ary = ""
            knt = 7
            for j in range(6, -1, -1):  # Strip trailing spaces
                if str(setting.value)[j] == "" or str(setting.value)[j] == " ":
                    knt = knt - 1
                else:
                    break
            for j in range(0, 7, 1):
                if j < knt: ary += str(setting.value)[j]
                else: ary += chr(0xFF)
            setattr(obj, atrba, ary)
            setattr(obj, atrbc, knt)
            return

        tmp = chars2str(_lims.hello1, _lims.hello1_cnt)
        rs = RadioSetting("hello_lims.hello1", "Power-On Message 1",
                          RadioSettingValueString(0, 7, tmp))
        rs.set_apply_callback(my_str2ary, _lims, "hello1", "hello1_cnt")
        lims.append(rs)

        tmp = chars2str(_lims.hello2, _lims.hello2_cnt)
        rs = RadioSetting("hello_lims.hello2", "Power-On Message 2",
                          RadioSettingValueString(0, 7, tmp))
        rs.set_apply_callback(my_str2ary, _lims, "hello2", "hello2_cnt")
        lims.append(rs)

        # VALID_BANDS = [(136000000, 176000000),400000000, 480000000)]

        lval = _lims.vhf_low / 100000.0
        uval = _lims.vhf_high / 100000.0
        if lval >= uval:
            lval = 144.0
            uval = 158.0

        rs = RadioSetting("hello_lims.vhf_low", "Lower VHF Band Limit (MHz)",
                          RadioSettingValueFloat(136.0, 176.0, lval, 0.001, 3))
        rs.set_apply_callback(my_dbl2raw, _lims, "vhf_low")
        lims.append(rs)

        rs = RadioSetting("hello_lims.vhf_high", "Upper VHF Band Limit (MHz)",
                          RadioSettingValueFloat(136.0, 176.0, uval, 0.001, 3))
        rs.set_apply_callback(my_dbl2raw, _lims, "vhf_high")
        lims.append(rs)

        lval = _lims.uhf_low / 100000.0
        uval = _lims.uhf_high / 100000.0
        if lval >= uval:
            lval = 420.0
            uval = 470.0

        rs = RadioSetting("hello_lims.uhf_low", "Lower UHF Band Limit (MHz)",
                          RadioSettingValueFloat(400.0, 480.0, lval, 0.001, 3))
        rs.set_apply_callback(my_dbl2raw, _lims, "uhf_low")
        lims.append(rs)

        rs = RadioSetting("hello_lims.uhf_high", "Upper UHF Band Limit (MHz)",
                          RadioSettingValueFloat(400.0, 480.0, uval, 0.001, 3))
        rs.set_apply_callback(my_dbl2raw, _lims, "uhf_high")
        lims.append(rs)

        # Codes and DTMF Groups Settings

        def make_dtmf(ary, knt):
            """Generate the DTMF code 1-8, NOT a callback."""
            tmp = ""
            if knt > 0 and knt != 0xff:
                for val in ary[:knt]:
                    if val > 0 and val <= 9:
                        tmp += chr(val + 48)
                    elif val == 0x0a:
                        tmp += "0"
                    elif val == 0x0d:
                        tmp += "A"
                    elif val == 0x0e:
                        tmp += "B"
                    elif val == 0x0f:
                        tmp += "C"
                    elif val == 0x00:
                        tmp += "D"
                    elif val == 0x0b:
                        tmp += "*"
                    elif val == 0x0c:
                        tmp += "#"
                    else:
                        msg = ("Invalid Character. Must be: 0-9,A,B,C,D,*,#")
                        raise InvalidValueError(msg)
            return tmp

        def my_dtmf2raw(setting, obj, atrba, atrbc, syz=7):
            """Callback: DTMF Code; sends 5 or 7-byte string."""
            draw = []
            knt = syz
            for j in range(syz - 1, -1, -1):  # Strip trailing spaces
                if str(setting.value)[j] == "" or str(setting.value)[j] == " ":
                    knt = knt - 1
                else:
                    break
            for j in range(0, syz):
                bx = str(setting.value)[j]
                obx = ord(bx)
                dig = 0x0ff
                if j < knt and knt > 0:  # (Else) is pads
                    if bx == "0":
                        dig = 0x0a
                    elif bx == "A":
                        dig = 0x0d
                    elif bx == "B":
                        dig = 0x0e
                    elif bx == "C":
                        dig = 0x0f
                    elif bx == "D":
                        dig = 0x00
                    elif bx == "*":
                        dig = 0x0b
                    elif bx == "#":
                        dig = 0x0c
                    elif obx >= 49 and obx <= 57:
                        dig = obx - 48
                    else:
                        msg = ("Must be: 0-9,A,B,C,D,*,#")
                        raise InvalidValueError(msg)
                    # - End if/elif/else for bx
                # - End if J<=knt
                draw.append(dig)  # Generate string of bytes
            # - End for j
            setattr(obj, atrba, draw)
            setattr(obj, atrbc, knt)
            return

        tmp = make_dtmf(_codes.native_id_code, _codes.native_id_cnt)
        rs = RadioSetting("codes.native_id_code", "Native ID Code",
                          RadioSettingValueString(0, 7, tmp))
        rs.set_apply_callback(my_dtmf2raw, _codes, "native_id_code",
                              "native_id_cnt", 7)
        codes.append(rs)

        tmp = make_dtmf(_codes.master_id_code, _codes.master_id_cnt)
        rs = RadioSetting("codes.master_id_code", "Master Control ID Code",
                          RadioSettingValueString(0, 7, tmp))
        rs.set_apply_callback(my_dtmf2raw, _codes, "master_id_code",
                              "master_id_cnt", 7)
        codes.append(rs)

        tmp = make_dtmf(_codes.alarm_code, _codes.alarm_cnt)
        rs = RadioSetting("codes.alarm_code", "Alarm Code",
                          RadioSettingValueString(0, 5, tmp))
        rs.set_apply_callback(my_dtmf2raw, _codes, "alarm_code", "alarm_cnt",
                              5)
        codes.append(rs)

        tmp = make_dtmf(_codes.id_disp_code, _codes.id_disp_cnt)
        rs = RadioSetting("codes.id_disp_code", "Identify Display Code",
                          RadioSettingValueString(0, 5, tmp))
        rs.set_apply_callback(my_dtmf2raw, _codes, "id_disp_code",
                              "id_disp_cnt", 5)
        codes.append(rs)

        tmp = make_dtmf(_codes.revive_code, _codes.revive_cnt)
        rs = RadioSetting("codes.revive_code", "Revive Code",
                          RadioSettingValueString(0, 5, tmp))
        rs.set_apply_callback(my_dtmf2raw, _codes, "revive_code", "revive_cnt",
                              5)
        codes.append(rs)

        tmp = make_dtmf(_codes.stun_code, _codes.stun_cnt)
        rs = RadioSetting("codes.stun_code", "Remote Stun Code",
                          RadioSettingValueString(0, 5, tmp))
        rs.set_apply_callback(my_dtmf2raw, _codes, "stun_code", "stun_cnt", 5)
        codes.append(rs)

        tmp = make_dtmf(_codes.kill_code, _codes.kill_cnt)
        rs = RadioSetting("codes.kill_code", "Remote KILL Code",
                          RadioSettingValueString(0, 5, tmp))
        rs.set_apply_callback(my_dtmf2raw, _codes, "kill_code", "kill_cnt", 5)
        codes.append(rs)

        tmp = make_dtmf(_codes.monitor_code, _codes.monitor_cnt)
        rs = RadioSetting("codes.monitor_code", "Monitor Code",
                          RadioSettingValueString(0, 5, tmp))
        rs.set_apply_callback(my_dtmf2raw, _codes, "monitor_code",
                              "monitor_cnt", 5)
        codes.append(rs)

        val = _codes.state_now
        if val > 2:
            val = 0

        rx = RadioSettingValueList(LIST_STATE, LIST_STATE[val])
        rs = RadioSetting("codes.state_now", "Current State", rx)
        codes.append(rs)

        dtm = make_dtmf(_dtmf.dtmf1, _dtmf.dtmf1_cnt)
        rs = RadioSetting("dtmf_tab.dtmf1", "DTMF1 String",
                          RadioSettingValueString(0, 7, dtm))
        rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf1", "dtmf1_cnt")
        codes.append(rs)

        dtm = make_dtmf(_dtmf.dtmf2, _dtmf.dtmf2_cnt)
        rs = RadioSetting("dtmf_tab.dtmf2", "DTMF2 String",
                          RadioSettingValueString(0, 7, dtm))
        rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf2", "dtmf2_cnt")
        codes.append(rs)

        dtm = make_dtmf(_dtmf.dtmf3, _dtmf.dtmf3_cnt)
        rs = RadioSetting("dtmf_tab.dtmf3", "DTMF3 String",
                          RadioSettingValueString(0, 7, dtm))
        rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf3", "dtmf3_cnt")
        codes.append(rs)

        dtm = make_dtmf(_dtmf.dtmf4, _dtmf.dtmf4_cnt)
        rs = RadioSetting("dtmf_tab.dtmf4", "DTMF4 String",
                          RadioSettingValueString(0, 7, dtm))
        rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf4", "dtmf4_cnt")
        codes.append(rs)

        dtm = make_dtmf(_dtmf.dtmf5, _dtmf.dtmf5_cnt)
        rs = RadioSetting("dtmf_tab.dtmf5", "DTMF5 String",
                          RadioSettingValueString(0, 7, dtm))
        rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf5", "dtmf5_cnt")
        codes.append(rs)

        dtm = make_dtmf(_dtmf.dtmf6, _dtmf.dtmf6_cnt)
        rs = RadioSetting("dtmf_tab.dtmf6", "DTMF6 String",
                          RadioSettingValueString(0, 7, dtm))
        rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf6", "dtmf6_cnt")
        codes.append(rs)

        dtm = make_dtmf(_dtmf.dtmf7, _dtmf.dtmf7_cnt)
        rs = RadioSetting("dtmf_tab.dtmf7", "DTMF7 String",
                          RadioSettingValueString(0, 7, dtm))
        rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf7", "dtmf7_cnt")
        codes.append(rs)

        dtm = make_dtmf(_dtmf.dtmf8, _dtmf.dtmf8_cnt)
        rs = RadioSetting("dtmf_tab.dtmf8", "DTMF8 String",
                          RadioSettingValueString(0, 7, dtm))
        rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf8", "dtmf8_cnt")
        codes.append(rs)

        return group  # END get_settings()
コード例 #10
0
ファイル: bjuv55.py プロジェクト: jz09bed/chirp.hg
    def _get_settings(self):
        _settings = self._memobj.settings
        basic = RadioSettingGroup("basic", "Basic Settings")
        advanced = RadioSettingGroup("advanced", "Advanced Settings")
        group = RadioSettings(basic, advanced)

        rs = RadioSetting("squelch", "Carrier Squelch Level",
                          RadioSettingValueInteger(0, 9, _settings.squelch))
        basic.append(rs)

        rs = RadioSetting("save", "Battery Saver",
                          RadioSettingValueInteger(0, 4, _settings.save))
        basic.append(rs)

        rs = RadioSetting("abr", "Backlight",
                          RadioSettingValueBoolean(_settings.abr))
        basic.append(rs)

        rs = RadioSetting("tdr", "Dual Watch (BDR)",
                          RadioSettingValueBoolean(_settings.tdr))
        advanced.append(rs)

        rs = RadioSetting("tdrab", "Dual Watch TX Priority",
                          RadioSettingValueList(
                              uv5r.TDRAB_LIST,
                              uv5r.TDRAB_LIST[_settings.tdrab]))
        advanced.append(rs)

        rs = RadioSetting("alarm", "Alarm",
                          RadioSettingValueBoolean(_settings.alarm))
        advanced.append(rs)

        rs = RadioSetting("beep", "Beep",
                          RadioSettingValueBoolean(_settings.beep))
        basic.append(rs)

        rs = RadioSetting("timeout", "Timeout Timer",
                          RadioSettingValueList(
                              uv5r.TIMEOUT_LIST,
                              uv5r.TIMEOUT_LIST[_settings.timeout]))
        basic.append(rs)

        rs = RadioSetting("screv", "Scan Resume",
                          RadioSettingValueList(
                              uv5r.RESUME_LIST,
                              uv5r.RESUME_LIST[_settings.screv]))
        advanced.append(rs)

        rs = RadioSetting("mdfa", "Display Mode (A)",
                          RadioSettingValueList(
                              uv5r.MODE_LIST, uv5r.MODE_LIST[_settings.mdfa]))
        basic.append(rs)

        rs = RadioSetting("mdfb", "Display Mode (B)",
                          RadioSettingValueList(
                              uv5r.MODE_LIST, uv5r.MODE_LIST[_settings.mdfb]))
        basic.append(rs)

        rs = RadioSetting("bcl", "Busy Channel Lockout",
                          RadioSettingValueBoolean(_settings.bcl))
        advanced.append(rs)

        rs = RadioSetting("autolk", "Automatic Key Lock",
                          RadioSettingValueBoolean(_settings.autolk))
        advanced.append(rs)

        rs = RadioSetting("fmradio", "Broadcast FM Radio",
                          RadioSettingValueBoolean(_settings.fmradio))
        advanced.append(rs)

        rs = RadioSetting("wtled", "Standby LED Color",
                          RadioSettingValueList(
                              COLOR_LIST, COLOR_LIST[_settings.wtled]))
        basic.append(rs)

        rs = RadioSetting("rxled", "RX LED Color",
                          RadioSettingValueList(
                              COLOR_LIST, COLOR_LIST[_settings.rxled]))
        basic.append(rs)

        rs = RadioSetting("txled", "TX LED Color",
                          RadioSettingValueList(
                              COLOR_LIST, COLOR_LIST[_settings.txled]))
        basic.append(rs)

        rs = RadioSetting("reset", "RESET Menu",
                          RadioSettingValueBoolean(_settings.reset))
        advanced.append(rs)

        rs = RadioSetting("menu", "All Menus",
                          RadioSettingValueBoolean(_settings.menu))
        advanced.append(rs)

        if len(self._mmap.get_packed()) == 0x1808:
            # Old image, without aux block
            return group

        other = RadioSettingGroup("other", "Other Settings")
        group.append(other)

        def _filter(name):
            filtered = ""
            for char in str(name):
                if char in chirp_common.CHARSET_ASCII:
                    filtered += char
                else:
                    filtered += " "
            return filtered

        _msg = self._memobj.poweron_msg
        rs = RadioSetting("poweron_msg.line1", "Power-On Message 1",
                          RadioSettingValueString(0, 7, _filter(_msg.line1)))
        other.append(rs)
        rs = RadioSetting("poweron_msg.line2", "Power-On Message 2",
                          RadioSettingValueString(0, 7, _filter(_msg.line2)))
        other.append(rs)

        limit = "limits"
        vhf_limit = getattr(self._memobj, limit).vhf
        rs = RadioSetting("%s.vhf.lower" % limit, "VHF Lower Limit (MHz)",
                          RadioSettingValueInteger(
                              1, 1000, vhf_limit.lower))
        other.append(rs)

        rs = RadioSetting("%s.vhf.upper" % limit, "VHF Upper Limit (MHz)",
                          RadioSettingValueInteger(
                              1, 1000, vhf_limit.upper))
        other.append(rs)

        rs = RadioSetting("%s.vhf.enable" % limit, "VHF TX Enabled",
                          RadioSettingValueBoolean(vhf_limit.enable))
        other.append(rs)

        uhf_limit = getattr(self._memobj, limit).uhf
        rs = RadioSetting("%s.uhf.lower" % limit, "UHF Lower Limit (MHz)",
                          RadioSettingValueInteger(
                              1, 1000, uhf_limit.lower))
        other.append(rs)
        rs = RadioSetting("%s.uhf.upper" % limit, "UHF Upper Limit (MHz)",
                          RadioSettingValueInteger(
                              1, 1000, uhf_limit.upper))
        other.append(rs)
        rs = RadioSetting("%s.uhf.enable" % limit, "UHF TX Enabled",
                          RadioSettingValueBoolean(uhf_limit.enable))
        other.append(rs)

        workmode = RadioSettingGroup("workmode", "Work Mode Settings")
        group.append(workmode)

        options = ["A", "B"]
        rs = RadioSetting("displayab", "Display Selected",
                          RadioSettingValueList(
                              options, options[_settings.displayab]))
        workmode.append(rs)

        options = ["Frequency", "Channel"]
        rs = RadioSetting("workmode", "VFO/MR Mode",
                          RadioSettingValueList(
                              options, options[_settings.workmode]))
        workmode.append(rs)

        rs = RadioSetting("keylock", "Keypad Lock",
                          RadioSettingValueBoolean(_settings.keylock))
        workmode.append(rs)

        _mrcna = self._memobj.wmchannel.mrcha
        rs = RadioSetting("wmchannel.mrcha", "MR A Channel",
                          RadioSettingValueInteger(0, 127, _mrcna))
        workmode.append(rs)

        _mrcnb = self._memobj.wmchannel.mrchb
        rs = RadioSetting("wmchannel.mrchb", "MR B Channel",
                          RadioSettingValueInteger(0, 127, _mrcnb))
        workmode.append(rs)

        def convert_bytes_to_freq(bytes):
            real_freq = 0
            for byte in bytes:
                real_freq = (real_freq * 10) + byte
            return chirp_common.format_freq(real_freq * 10)

        def my_validate(value):
            value = chirp_common.parse_freq(value)
            if 17400000 <= value and value < 40000000:
                raise InvalidValueError("Can't be between 174.00000-400.00000")
            return chirp_common.format_freq(value)

        def apply_freq(setting, obj):
            value = chirp_common.parse_freq(str(setting.value)) / 10
            obj.band = value >= 40000000
            for i in range(7, -1, -1):
                obj.freq[i] = value % 10
                value /= 10

        val1a = RadioSettingValueString(
                0, 10, convert_bytes_to_freq(self._memobj.vfoa.freq))
        val1a.set_validate_callback(my_validate)
        rs = RadioSetting("vfoa.freq", "VFO A Frequency", val1a)
        rs.set_apply_callback(apply_freq, self._memobj.vfoa)
        workmode.append(rs)

        val1b = RadioSettingValueString(
                0, 10, convert_bytes_to_freq(self._memobj.vfob.freq))
        val1b.set_validate_callback(my_validate)
        rs = RadioSetting("vfob.freq", "VFO B Frequency", val1b)
        rs.set_apply_callback(apply_freq, self._memobj.vfob)
        workmode.append(rs)

        options = ["Off", "+", "-"]
        rs = RadioSetting("vfoa.sftd", "VFO A Shift",
                          RadioSettingValueList(
                              options, options[self._memobj.vfoa.sftd]))
        workmode.append(rs)

        rs = RadioSetting("vfob.sftd", "VFO B Shift",
                          RadioSettingValueList(
                              options, options[self._memobj.vfob.sftd]))
        workmode.append(rs)

        def convert_bytes_to_offset(bytes):
            real_offset = 0
            for byte in bytes:
                real_offset = (real_offset * 10) + byte
            return chirp_common.format_freq(real_offset * 10000)

        def apply_offset(setting, obj):
            value = chirp_common.parse_freq(str(setting.value)) / 10000
            for i in range(3, -1, -1):
                obj.offset[i] = value % 10
                value /= 10

        val1a = RadioSettingValueString(
                0, 10, convert_bytes_to_offset(self._memobj.vfoa.offset))
        rs = RadioSetting("vfoa.offset", "VFO A Offset (0.00-69.95)", val1a)
        rs.set_apply_callback(apply_offset, self._memobj.vfoa)
        workmode.append(rs)

        val1b = RadioSettingValueString(
                0, 10, convert_bytes_to_offset(self._memobj.vfob.offset))
        rs = RadioSetting("vfob.offset", "VFO B Offset (0.00-69.95)", val1b)
        rs.set_apply_callback(apply_offset, self._memobj.vfob)
        workmode.append(rs)

        options = ["High", "Low"]
        rs = RadioSetting("vfoa.txpower", "VFO A Power",
                          RadioSettingValueList(
                              options, options[self._memobj.vfoa.txpower]))
        workmode.append(rs)

        rs = RadioSetting("vfob.txpower", "VFO B Power",
                          RadioSettingValueList(
                              options, options[self._memobj.vfob.txpower]))
        workmode.append(rs)

        options = ["Wide", "Narrow"]
        rs = RadioSetting("vfoa.widenarr", "VFO A Bandwidth",
                          RadioSettingValueList(
                              options, options[self._memobj.vfoa.widenarr]))
        workmode.append(rs)

        rs = RadioSetting("vfob.widenarr", "VFO B Bandwidth",
                          RadioSettingValueList(
                              options, options[self._memobj.vfob.widenarr]))
        workmode.append(rs)

        options = ["%s" % x for x in range(1, 16)]
        rs = RadioSetting("vfoa.scode", "VFO A PTT-ID",
                          RadioSettingValueList(
                              options, options[self._memobj.vfoa.scode]))
        workmode.append(rs)

        rs = RadioSetting("vfob.scode", "VFO B PTT-ID",
                          RadioSettingValueList(
                              options, options[self._memobj.vfob.scode]))
        workmode.append(rs)

        rs = RadioSetting("vfoa.step", "VFO A Tuning Step",
                          RadioSettingValueList(
                              STEP_LIST, STEP_LIST[self._memobj.vfoa.step]))
        workmode.append(rs)
        rs = RadioSetting("vfob.step", "VFO B Tuning Step",
                          RadioSettingValueList(
                              STEP_LIST, STEP_LIST[self._memobj.vfob.step]))
        workmode.append(rs)

        fm_preset = RadioSettingGroup("fm_preset", "FM Radio Preset")
        group.append(fm_preset)

        preset = self._memobj.fm_preset / 10.0 + 87
        rs = RadioSetting("fm_preset", "FM Preset(MHz)",
                          RadioSettingValueFloat(87, 107.5, preset, 0.1, 1))
        fm_preset.append(rs)

        dtmf = RadioSettingGroup("dtmf", "DTMF Settings")
        group.append(dtmf)
        dtmfchars = "0123456789 *#ABCD"

        for i in range(0, 15):
            _codeobj = self._memobj.pttid[i].code
            _code = "".join([dtmfchars[x] for x in _codeobj if int(x) < 0x1F])
            val = RadioSettingValueString(0, 5, _code, False)
            val.set_charset(dtmfchars)
            rs = RadioSetting("pttid/%i.code" % i,
                              "PTT ID Code %i" % (i + 1), val)

            def apply_code(setting, obj):
                code = []
                for j in range(0, 5):
                    try:
                        code.append(dtmfchars.index(str(setting.value)[j]))
                    except IndexError:
                        code.append(0xFF)
                obj.code = code
            rs.set_apply_callback(apply_code, self._memobj.pttid[i])
            dtmf.append(rs)

        _codeobj = self._memobj.ani.code
        _code = "".join([dtmfchars[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 5, _code, False)
        val.set_charset(dtmfchars)
        rs = RadioSetting("ani.code", "ANI Code", val)

        def apply_code(setting, obj):
            code = []
            for j in range(0, 5):
                try:
                    code.append(dtmfchars.index(str(setting.value)[j]))
                except IndexError:
                    code.append(0xFF)
            obj.code = code
        rs.set_apply_callback(apply_code, self._memobj.ani)
        dtmf.append(rs)

        options = ["Off", "BOT", "EOT", "Both"]
        rs = RadioSetting("ani.aniid", "ANI ID",
                          RadioSettingValueList(
                              options, options[self._memobj.ani.aniid]))
        dtmf.append(rs)

        _codeobj = self._memobj.ani.alarmcode
        _code = "".join([dtmfchars[x] for x in _codeobj if int(x) < 0x1F])
        val = RadioSettingValueString(0, 5, _code, False)
        val.set_charset(dtmfchars)
        rs = RadioSetting("ani.alarmcode", "Alarm Code", val)

        def apply_code(setting, obj):
            alarmcode = []
            for j in range(5):
                try:
                    alarmcode.append(dtmfchars.index(str(setting.value)[j]))
                except IndexError:
                    alarmcode.append(0xFF)
            obj.alarmcode = alarmcode
        rs.set_apply_callback(apply_code, self._memobj.ani)
        dtmf.append(rs)

        rs = RadioSetting("dtmfst", "DTMF Sidetone",
                          RadioSettingValueList(
                              uv5r.DTMFST_LIST,
                              uv5r.DTMFST_LIST[_settings.dtmfst]))
        dtmf.append(rs)

        rs = RadioSetting("ani.dtmfon", "DTMF Speed (on)",
                          RadioSettingValueList(
                              uv5r.DTMFSPEED_LIST,
                              uv5r.DTMFSPEED_LIST[self._memobj.ani.dtmfon]))
        dtmf.append(rs)

        rs = RadioSetting("ani.dtmfoff", "DTMF Speed (off)",
                          RadioSettingValueList(
                              uv5r.DTMFSPEED_LIST,
                              uv5r.DTMFSPEED_LIST[self._memobj.ani.dtmfoff]))
        dtmf.append(rs)

        return group
コード例 #11
0
ファイル: baofeng_uv3r.py プロジェクト: jz09bed/chirp.hg
    def get_settings(self):
        _settings = self._memobj.settings
        _vfo = self._memobj.vfo
        basic = RadioSettingGroup("basic", "Basic Settings")
        group = RadioSettings(basic)

        rs = RadioSetting("squelch", "Squelch Level",
                          RadioSettingValueInteger(0, 9, _settings.squelch))
        basic.append(rs)

        rs = RadioSetting(
            "backlight", "LCD Back Light",
            RadioSettingValueList(BACKLIGHT_LIST,
                                  BACKLIGHT_LIST[_settings.backlight]))
        basic.append(rs)

        rs = RadioSetting("beep", "Keypad Beep",
                          RadioSettingValueBoolean(_settings.beep))
        basic.append(rs)

        rs = RadioSetting("vox", "VOX Level (0=OFF)",
                          RadioSettingValueInteger(0, 9, _settings.vox))
        basic.append(rs)

        rs = RadioSetting("dw", "Dual Watch",
                          RadioSettingValueBoolean(_settings.dw))
        basic.append(rs)

        rs = RadioSetting(
            "ste", "Squelch Tail Eliminate",
            RadioSettingValueList(STE_LIST, STE_LIST[_settings.ste]))
        basic.append(rs)

        rs = RadioSetting("save", "Battery Saver",
                          RadioSettingValueBoolean(_settings.save))
        basic.append(rs)

        rs = RadioSetting(
            "timeout", "Time Out Timer",
            RadioSettingValueList(TIMEOUT_LIST,
                                  TIMEOUT_LIST[_settings.timeout]))
        basic.append(rs)

        rs = RadioSetting(
            "scanm", "Scan Mode",
            RadioSettingValueList(SCANM_LIST, SCANM_LIST[_settings.scanm]))
        basic.append(rs)

        rs = RadioSetting("relaym", "Repeater Sound Response",
                          RadioSettingValueBoolean(_settings.relaym))
        basic.append(rs)

        rs = RadioSetting("bclo", "Busy Channel Lock Out",
                          RadioSettingValueBoolean(_settings.bclo))
        basic.append(rs)

        rs = RadioSetting("pri", "Priority Channel Scanning",
                          RadioSettingValueBoolean(_settings.pri))
        basic.append(rs)

        rs = RadioSetting(
            "pri_ch", "Priority Channel",
            RadioSettingValueList(PRI_CH_LIST, PRI_CH_LIST[_settings.pri_ch]))
        basic.append(rs)

        rs = RadioSetting(
            "ch_flag", "Display Mode",
            RadioSettingValueList(CH_FLAG_LIST,
                                  CH_FLAG_LIST[_settings.ch_flag]))
        basic.append(rs)

        _limit = int(self._memobj.limits.lower_vhf) / 10
        if _limit < 115 or _limit > 239:
            _limit = 144
        rs = RadioSetting("limits.lower_vhf", "VHF Lower Limit (115-239 MHz)",
                          RadioSettingValueInteger(115, 235, _limit))

        def apply_limit(setting, obj):
            value = int(setting.value) * 10
            obj.lower_vhf = value

        rs.set_apply_callback(apply_limit, self._memobj.limits)
        basic.append(rs)

        _limit = int(self._memobj.limits.upper_vhf) / 10
        if _limit < 115 or _limit > 239:
            _limit = 146
        rs = RadioSetting("limits.upper_vhf", "VHF Upper Limit (115-239 MHz)",
                          RadioSettingValueInteger(115, 235, _limit))

        def apply_limit(setting, obj):
            value = int(setting.value) * 10
            obj.upper_vhf = value

        rs.set_apply_callback(apply_limit, self._memobj.limits)
        basic.append(rs)

        _limit = int(self._memobj.limits.lower_uhf) / 10
        if _limit < 200 or _limit > 529:
            _limit = 420
        rs = RadioSetting("limits.lower_uhf", "UHF Lower Limit (200-529 MHz)",
                          RadioSettingValueInteger(200, 529, _limit))

        def apply_limit(setting, obj):
            value = int(setting.value) * 10
            obj.lower_uhf = value

        rs.set_apply_callback(apply_limit, self._memobj.limits)
        basic.append(rs)

        _limit = int(self._memobj.limits.upper_uhf) / 10
        if _limit < 200 or _limit > 529:
            _limit = 450
        rs = RadioSetting("limits.upper_uhf", "UHF Upper Limit (200-529 MHz)",
                          RadioSettingValueInteger(200, 529, _limit))

        def apply_limit(setting, obj):
            value = int(setting.value) * 10
            obj.upper_uhf = value

        rs.set_apply_callback(apply_limit, self._memobj.limits)
        basic.append(rs)

        vfo_preset = RadioSettingGroup("vfo_preset", "VFO Presets")
        group.append(vfo_preset)

        def convert_bytes_to_freq(bytes):
            real_freq = 0
            real_freq = bytes
            return chirp_common.format_freq(real_freq * 10)

        def apply_vhf_freq(setting, obj):
            value = chirp_common.parse_freq(str(setting.value)) / 10
            obj.vhf.freq = value

        val = RadioSettingValueString(
            0, 10, convert_bytes_to_freq(int(_vfo.vhf.freq)))
        rs = RadioSetting("vfo.vhf.freq",
                          "VHF RX Frequency (115.00000-236.00000)", val)
        rs.set_apply_callback(apply_vhf_freq, _vfo)
        vfo_preset.append(rs)

        rs = RadioSetting(
            "vfo.vhf.duplex", "Shift Direction",
            RadioSettingValueList(DUPLEX_LIST, DUPLEX_LIST[_vfo.vhf.duplex]))
        vfo_preset.append(rs)

        def convert_bytes_to_offset(bytes):
            real_offset = 0
            real_offset = bytes
            return chirp_common.format_freq(real_offset * 10000)

        def apply_vhf_offset(setting, obj):
            value = chirp_common.parse_freq(str(setting.value)) / 10000
            obj.vhf.offset = value

        val = RadioSettingValueString(
            0, 10, convert_bytes_to_offset(int(_vfo.vhf.offset)))
        rs = RadioSetting("vfo.vhf.offset", "Offset (0.00-37.995)", val)
        rs.set_apply_callback(apply_vhf_offset, _vfo)
        vfo_preset.append(rs)

        rs = RadioSetting(
            "vfo.vhf.power", "Power Level",
            RadioSettingValueList(POWER_LIST, POWER_LIST[_vfo.vhf.power]))
        vfo_preset.append(rs)

        rs = RadioSetting(
            "vfo.vhf.bandwidth", "Bandwidth",
            RadioSettingValueList(BANDWIDTH_LIST,
                                  BANDWIDTH_LIST[_vfo.vhf.bandwidth]))
        vfo_preset.append(rs)

        rs = RadioSetting(
            "vfo.vhf.step", "Step",
            RadioSettingValueList(STEP_LIST, STEP_LIST[_vfo.vhf.step]))
        vfo_preset.append(rs)

        def apply_uhf_freq(setting, obj):
            value = chirp_common.parse_freq(str(setting.value)) / 10
            obj.uhf.freq = value

        val = RadioSettingValueString(
            0, 10, convert_bytes_to_freq(int(_vfo.uhf.freq)))
        rs = RadioSetting("vfo.uhf.freq",
                          "UHF RX Frequency (200.00000-529.00000)", val)
        rs.set_apply_callback(apply_uhf_freq, _vfo)
        vfo_preset.append(rs)

        rs = RadioSetting(
            "vfo.uhf.duplex", "Shift Direction",
            RadioSettingValueList(DUPLEX_LIST, DUPLEX_LIST[_vfo.uhf.duplex]))
        vfo_preset.append(rs)

        def apply_uhf_offset(setting, obj):
            value = chirp_common.parse_freq(str(setting.value)) / 10000
            obj.uhf.offset = value

        val = RadioSettingValueString(
            0, 10, convert_bytes_to_offset(int(_vfo.uhf.offset)))
        rs = RadioSetting("vfo.uhf.offset", "Offset (0.00-69.995)", val)
        rs.set_apply_callback(apply_uhf_offset, _vfo)
        vfo_preset.append(rs)

        rs = RadioSetting(
            "vfo.uhf.power", "Power Level",
            RadioSettingValueList(POWER_LIST, POWER_LIST[_vfo.uhf.power]))
        vfo_preset.append(rs)

        rs = RadioSetting(
            "vfo.uhf.bandwidth", "Bandwidth",
            RadioSettingValueList(BANDWIDTH_LIST,
                                  BANDWIDTH_LIST[_vfo.uhf.bandwidth]))
        vfo_preset.append(rs)

        rs = RadioSetting(
            "vfo.uhf.step", "Step",
            RadioSettingValueList(STEP_LIST, STEP_LIST[_vfo.uhf.step]))
        vfo_preset.append(rs)

        fm_preset = RadioSettingGroup("fm_preset", "FM Radio Presets")
        group.append(fm_preset)

        for i in range(0, 16):
            if self._memobj.fm_presets[i] < 0x01AF:
                used = True
                preset = self._memobj.fm_presets[i] / 10.0 + 65
            else:
                used = False
                preset = 65
            rs = RadioSetting("fm_presets_%1i" % i, "FM Preset %i" % (i + 1),
                              RadioSettingValueBoolean(used),
                              RadioSettingValueFloat(65, 108, preset, 0.1, 1))
            fm_preset.append(rs)

        return group