예제 #1
0
    public static void InitCM(int nFactor, ChannelMask channelsStim, ChannelMask channelsLowFreq, int groupFrequency, int mainFrequency, int maxPulseGroup = 1)
    {
        // save config
        lastConfig                 = new channelListConfig();
        lastConfig.nFactor         = nFactor;
        lastConfig.channelsStim    = channelsStim;
        lastConfig.channelsLowFreq = channelsLowFreq;
        lastConfig.groupFrequency  = groupFrequency;
        lastConfig.mainFrequency   = mainFrequency;
        lastConfig.maxPulseGroup   = maxPulseGroup;

        int groupTime = ChannelList.HerzToGroupTime(groupFrequency);
        //groupTime needs to be at least max (#channels,#lowFreq)  * 1.5
        int minGroupTime = (int)Mathf.Ceil(
            Mathf.Max(channelsStim.getActiveChannels().Count
                      , channelsLowFreq.getActiveChannels().Count)
            * 1.5f
            );

        groupTime = Mathf.Max(groupTime, minGroupTime);

        int mainTime = ChannelList.HerzToMainTime(mainFrequency);
        //mainTime needs to be at least pusleGroupSize * groupTime + 1.5ms
        int minMainTime = (int)Mathf.Ceil(maxPulseGroup * groupTime + 1.5f);

        mainTime = Mathf.Max(mainTime, minMainTime);

        //Debug.Log(mainTime + "|" +  groupTime);

        byte[] cmd = ChannelList.GetInitCommand(nFactor, channelsStim.toInt(), channelsLowFreq.toInt(), groupTime, mainTime);
        RehaStimInterface.sendMessage(cmd);
        //ChannelList.activeChannels = channelsStim;
        //ChannelList.activeChannelsLowFreq = channelsLowFreq;
        currentConfig = new SortedDictionary <int, UpdateInfo>();
        //init config
        foreach (var channel in channelsStim.getActiveChannels())
        {
            currentConfig.Add(channel, new UpdateInfo(UpdateInfo.MODE_SINGLE, 0, 0));
        }
        isRunning = true;
    }