private static void Dot(bool state)
        {
            CWSensorItem.InputType type = CWSensorItem.InputType.Dot;
            if (reverse_paddles)
            {
                type = CWSensorItem.InputType.Dash;
            }

            CWSensorItem item = new CWSensorItem(type, state);

            CWKeyer.SensorEnqueue(item);
        }
        private static void Dash(bool state)
        {
            if (ignore_dash)
            {
                return;
            }

            CWSensorItem.InputType type = CWSensorItem.InputType.Dash;
            if (reverse_paddles)
            {
                type = CWSensorItem.InputType.Dot;
            }

            CWSensorItem item = new CWSensorItem(type, state);

            CWKeyer.SensorEnqueue(item);
        }
Example #3
0
        void SerialPinChanged(object source, SerialPinChangedEventArgs e)
        {
            if (!use_for_keyptt && !use_for_paddles)
            {
                return;
            }

            if (use_for_keyptt)
            {
                switch (e.EventType)
                {
                case SerialPinChange.DsrChanged:
                    bool b = commPort.DsrHolding;

                    if (ptt_on_dtr)
                    {
                        CWPTTItem item = new CWPTTItem(b, CWSensorItem.GetCurrentTime());
                        CWKeyer.PTTEnqueue(item);
                    }

                    if (key_on_dtr)
                    {
                        CWSensorItem item = new CWSensorItem(CWSensorItem.InputType.StraightKey, b);
                        CWKeyer.SensorEnqueue(item);
                    }
                    break;

                case SerialPinChange.CtsChanged:
                    b = commPort.CtsHolding;

                    if (ptt_on_rts)
                    {
                        CWPTTItem item = new CWPTTItem(b, CWSensorItem.GetCurrentTime());
                        CWKeyer.PTTEnqueue(item);
                    }

                    if (key_on_rts)
                    {
                        CWSensorItem item = new CWSensorItem(CWSensorItem.InputType.StraightKey, b);
                        CWKeyer.SensorEnqueue(item);
                    }
                    break;
                }
            }
            else if (use_for_paddles)
            {
                switch (e.EventType)
                {
                case SerialPinChange.DsrChanged:
                    CWSensorItem.InputType type = CWSensorItem.InputType.Dot;
                    if (reverse_paddles)
                    {
                        type = CWSensorItem.InputType.Dash;
                    }
                    CWSensorItem item = new CWSensorItem(type, commPort.DsrHolding);
                    CWKeyer.SensorEnqueue(item);
                    break;

                case SerialPinChange.CtsChanged:
                    type = CWSensorItem.InputType.Dash;
                    if (reverse_paddles)
                    {
                        type = CWSensorItem.InputType.Dot;
                    }
                    item = new CWSensorItem(type, commPort.CtsHolding);
                    CWKeyer.SensorEnqueue(item);
                    break;
                }
            }
        }
Example #4
0
        void SerialPinChanged(object source, SerialPinChangedEventArgs e)
		{
            if (!use_for_keyptt && !use_for_paddles) return;

            if (use_for_keyptt)
            {
                switch (e.EventType)
                {
                    case SerialPinChange.DsrChanged:
                        bool b = commPort.DsrHolding;

                        if (ptt_on_dtr)
                        {
                            CWPTTItem item = new CWPTTItem(b, CWSensorItem.GetCurrentTime());
                            CWKeyer.PTTEnqueue(item);
                        }

                        if (key_on_dtr)
                        {
                            CWSensorItem item = new CWSensorItem(CWSensorItem.InputType.StraightKey, b);
                            CWKeyer.SensorEnqueue(item);
                        }
                        break;
                    case SerialPinChange.CtsChanged:
                        b = commPort.CtsHolding;

                        if (ptt_on_rts)
                        {
                            CWPTTItem item = new CWPTTItem(b, CWSensorItem.GetCurrentTime());
                            CWKeyer.PTTEnqueue(item);
                        }

                        if (key_on_rts)
                        {
                            CWSensorItem item = new CWSensorItem(CWSensorItem.InputType.StraightKey, b);
                            CWKeyer.SensorEnqueue(item);
                        }
                        break;
                }
            }
            else if (use_for_paddles)
            {
                switch (e.EventType)
                {
                    case SerialPinChange.DsrChanged:
                        CWSensorItem.InputType type = CWSensorItem.InputType.Dot;
                        if (reverse_paddles) type = CWSensorItem.InputType.Dash;
                        CWSensorItem item = new CWSensorItem(type, commPort.DsrHolding);
                        CWKeyer.SensorEnqueue(item);
                        break;
                    case SerialPinChange.CtsChanged:
                        type = CWSensorItem.InputType.Dash;
                        if (reverse_paddles) type = CWSensorItem.InputType.Dot;
                        item = new CWSensorItem(type, commPort.CtsHolding);
                        CWKeyer.SensorEnqueue(item);
                        break;
                }
            }
		}	
Example #5
0
        private static int InCallback(int hMidiIn, int wMsg, int dwInstance, int dwParam1, int dwParam2)
        {
            //log.AddLine("Midi.InCallback("+hMidiIn.ToString("X")+", "+wMsg.ToString("X")+", "+dwInstance.ToString("X")+", "+dwParam1.ToString("X")+", "+dwParam2.ToString("X")+")");
#if (TIMING)
            lock (in_lock_obj)
            {
                if (wMsg == Midi.MIM_DATA &&
                    (Command)((byte)dwParam1) == Command.NoteOn &&
                    (Note)(byte)(dwParam1 >> 8) == Note.Dot)
                {
                    FWCMidi.SendSetMessage(Opcode.RDAL_OP_WRITE_GPIO, 0x01, 0);
                    FWCMidi.SendSetMessage(Opcode.RDAL_OP_WRITE_GPIO, 0x00, 0);
                }
            }
#else
            lock (in_lock_obj)
            {
                switch (wMsg)
                {
                case Midi.MIM_DATA:
                    Command cmd   = (Command)((byte)dwParam1);
                    byte    byte1 = (byte)(dwParam1 >> 8);
                    byte    byte2 = (byte)(dwParam1 >> 16);

                    switch (cmd)
                    {
                    case Command.NoteOn:
                        switch ((Note)byte1)
                        {
                        case Note.Dot:
                            //console.Keyer.FWCDot = true;
                            CWSensorItem.InputType type = CWSensorItem.InputType.Dot;
                            if (reverse_paddles)
                            {
                                type = CWSensorItem.InputType.Dash;
                            }

                            CWSensorItem item = new CWSensorItem(type, true);
                            CWKeyer.SensorEnqueue(item);
                            break;

                        case Note.Dash:
                            //console.Keyer.FWCDash = true;
                            type = CWSensorItem.InputType.Dash;
                            if (reverse_paddles)
                            {
                                type = CWSensorItem.InputType.Dot;
                            }

                            item = new CWSensorItem(type, true);
                            CWKeyer.SensorEnqueue(item);
                            break;

                        case Note.MicDown:
                            if (console == null)
                            {
                                return(1);
                            }
                            console.MicDown = true;
                            break;

                        case Note.MicUp:
                            if (console == null)
                            {
                                return(1);
                            }
                            console.MicUp = true;
                            break;

                        case Note.MicFast:
                            if (console == null)
                            {
                                return(1);
                            }
                            console.MicFast = !console.MicFast;
                            break;
                        }
                        break;

                    case Command.NoteOff:
                        switch ((Note)byte1)
                        {
                        case Note.Dot:
                            //console.Keyer.FWCDot = false;
                            CWSensorItem.InputType type = CWSensorItem.InputType.Dot;
                            if (reverse_paddles)
                            {
                                type = CWSensorItem.InputType.Dash;
                            }

                            CWSensorItem item = new CWSensorItem(type, false);
                            CWKeyer.SensorEnqueue(item);
                            break;

                        case Note.Dash:
                            //console.Keyer.FWCDash = false;
                            type = CWSensorItem.InputType.Dash;
                            if (reverse_paddles)
                            {
                                type = CWSensorItem.InputType.Dot;
                            }

                            item = new CWSensorItem(type, false);
                            CWKeyer.SensorEnqueue(item);
                            break;

                        case Note.MicDown:
                            if (console == null)
                            {
                                return(1);
                            }
                            console.MicDown = false;
                            break;

                        case Note.MicUp:
                            if (console == null)
                            {
                                return(1);
                            }
                            console.MicUp = false;
                            break;

                        case Note.MicFast:
                            break;
                        }
                        break;

                    case Command.Controller:
                        switch ((Controller)byte1)
                        {
                        case Controller.HoldPedal:
                            if (console == null)
                            {
                                return(1);
                            }
                            console.FWCMicPTT = (byte2 > 63);
                            break;

                        case Controller.Hold2Pedal:
                            if (console == null)
                            {
                                return(1);
                            }
                            console.FWCRCAPTT = (byte2 > 63);
                            break;
                        }
                        break;

                    case Command.Aftertouch0:
                    case Command.Aftertouch1:
                        int id   = (ushort)((((byte)cmd - (byte)Command.Aftertouch0) << 2) + (byte1 >> 5));
                        int data = (int)(((byte1 & 0x1F) << 7) + byte2);
                        if (midi_in_table.ContainsKey(id))
                        {
                            midi_in_table.Remove(id);
                        }
                        midi_in_table.Add(id, data);
                        break;
                    }
                    break;

                case Midi.MIM_LONGDATA:
                    if (!resetting && midi_in_handle != 0)                            // in case device closes, don't send anymore buffers
                    {
                        int result = Midi.AddSysExBuffer(midi_in_handle);
                        if (result != 0)
                        {
                            StringBuilder error_text = new StringBuilder(64);
                            Midi.MidiInGetErrorText(result, error_text, 64);
                            Debug.WriteLine("AddSysExBuffer Error: " + error_text);
                        }
                    }

                    IntPtr          headerPtr = new IntPtr(dwParam1);
                    Midi.MidiHeader header    = (Midi.MidiHeader)Marshal.PtrToStructure(headerPtr, typeof(Midi.MidiHeader));
                    byte[]          temp      = new byte[header.bytesRecorded];
                    for (int i = 0; i < header.bytesRecorded; i++)
                    {
                        temp[i] = Marshal.ReadByte(header.data, i);
                    }

                    if (temp.Length > 5)
                    {
                        byte[] temp2 = new byte[temp.Length - 5];
                        for (int i = 0; i < temp.Length - 5; i++)
                        {
                            temp2[i] = temp[i + 4];
                        }

                        byte[] buf = new byte[temp2.Length / 2];
                        DecodeBytes(buf, temp2);
                        if (midi_in_table.ContainsKey(BitConverter.ToUInt16(buf, 0)))
                        {
                            midi_in_table.Remove(BitConverter.ToUInt16(buf, 0));
                        }
                        midi_in_table.Add(BitConverter.ToUInt16(buf, 0), buf);
                    }

                    /*for(int i=0; i<header.bytesRecorded; i++)
                     *      Debug.Write(buf[i].ToString("X")+" ");
                     * Debug.WriteLine("");*/

                    if (midi_in_handle != 0)
                    {
                        Midi.ReleaseBuffer(midi_in_handle, headerPtr);
                    }
                    break;
                }
            }
#endif
            return(0);
        }
Example #6
0
		public static void Notify(uint bmp)
		{
#if(TIMING)
            //GPIOWrite(bmp & 0x01);
            if ((bmp & 0x01) != 0)
            {
                GPIOWrite(1);
                GPIOWrite(0);
            }
#else
            if (console == null) return;

			bool temp = (bmp & 0x01) != 0; // dot

            if((bmp & 0x01) != (last_bmp & 0x01))
            {
                CWSensorItem.InputType type = CWSensorItem.InputType.Dot;
                if (reverse_paddles) type = CWSensorItem.InputType.Dash;

                CWSensorItem item = new CWSensorItem(type, temp);
                CWKeyer.SensorEnqueue(item);
            }
 
			temp = (bmp & 0x02) != 0; // dash

            if (!ignore_dash && ((bmp & 0x02) != (last_bmp & 0x02)))
            {
                CWSensorItem.InputType type = CWSensorItem.InputType.Dash;
                if (reverse_paddles) type = CWSensorItem.InputType.Dot;

                CWSensorItem item = new CWSensorItem(type, temp);
                CWKeyer.SensorEnqueue(item);
            }

			temp = (bmp & 0x04) != 0; // RCA PTT
			if(temp != console.FWCRCAPTT) console.FWCRCAPTT = temp;
 
			temp = (bmp & 0x08) != 0;
			if(temp != console.FWCMicPTT) console.FWCMicPTT = temp;
 
			temp = (bmp & 0x10) != 0;
			if(temp != console.MicDown) console.MicDown = temp;

			temp = (bmp & 0x20) != 0;
			if(temp != console.MicUp) console.MicUp = temp;

			if((bmp & 0x40) != 0) console.MicFast = !console.MicFast;

            last_bmp = bmp;
#endif
        }
Example #7
0
        public static void Notify(uint bmp)
        {
#if (TIMING)
            //GPIOWrite(bmp & 0x01);
            if ((bmp & 0x01) != 0)
            {
                GPIOWrite(1);
                GPIOWrite(0);
            }
#else
            if (console == null)
            {
                return;
            }

            //Debug.WriteLine("FWCNotify: "+bmp.ToString("X"));
            bool temp = (bmp & 0x01) != 0;             // dot

            /*if (temp)
             * {
             *  console.sp.RtsEnable = true;
             *  //Thread.Sleep(10);
             *  //console.sp.RtsEnable = false;
             * }*/

            //if(temp != console.Keyer.FWCDot) console.Keyer.FWCDot = temp;
            if ((bmp & 0x01) != (last_bmp & 0x01))
            {
                CWSensorItem.InputType type = CWSensorItem.InputType.Dot;
                if (reverse_paddles)
                {
                    type = CWSensorItem.InputType.Dash;
                }

                CWSensorItem item = new CWSensorItem(type, temp);
                CWKeyer.SensorEnqueue(item);
            }

            /*if (temp && !console.MOX && console.PowerOn)
             * {
             *  if(console.CheckForTXCW())
             *      Audio.MOX = true;
             * }*/

            temp = (bmp & 0x02) != 0;             // dash

            /*if (temp)
             * {
             *  console.sp.RtsEnable = true;
             *  //Thread.Sleep(10);
             *  //console.sp.RtsEnable = false;
             * }*/
            //if (!ignore_dash && temp != console.Keyer.FWCDash) console.Keyer.FWCDash = temp;
            if (!ignore_dash && ((bmp & 0x02) != (last_bmp & 0x02)))
            {
                CWSensorItem.InputType type = CWSensorItem.InputType.Dash;
                if (reverse_paddles)
                {
                    type = CWSensorItem.InputType.Dot;
                }

                CWSensorItem item = new CWSensorItem(type, temp);
                CWKeyer.SensorEnqueue(item);
            }

            /*if (!ignore_dash && temp && !console.MOX && console.PowerOn)
             * {
             *  if (console.CheckForTXCW())
             *  Audio.MOX = true;
             * }*/

            temp = (bmp & 0x04) != 0;             // RCA PTT
            if (temp != console.FWCRCAPTT)
            {
                console.FWCRCAPTT = temp;
            }

            temp = (bmp & 0x08) != 0;
            if (temp != console.FWCMicPTT)
            {
                console.FWCMicPTT = temp;
            }

            temp = (bmp & 0x10) != 0;
            if (temp != console.MicDown)
            {
                console.MicDown = temp;
            }

            temp = (bmp & 0x20) != 0;
            if (temp != console.MicUp)
            {
                console.MicUp = temp;
            }

            if ((bmp & 0x40) != 0)
            {
                console.MicFast = !console.MicFast;
            }

            last_bmp = bmp;
#endif
        }
Example #8
0
		private void setkey(bool state)
		{
			//console.Keyer.MemoryKey = state;
            if (setkey_memory != state)
            {
                CWSensorItem item = new CWSensorItem(CWSensorItem.InputType.StraightKey, state);
                CWKeyer.SensorEnqueue(item);

                if (state) keyLed.BackColor = System.Drawing.Color.Yellow;
                else keyLed.BackColor = System.Drawing.Color.Black;

                setkey_memory = state;
            }
		}
Example #9
0
		private static int InCallback(int hMidiIn, int wMsg, int dwInstance, int dwParam1, int dwParam2)
        {
            //log.AddLine("Midi.InCallback("+hMidiIn.ToString("X")+", "+wMsg.ToString("X")+", "+dwInstance.ToString("X")+", "+dwParam1.ToString("X")+", "+dwParam2.ToString("X")+")");
#if(TIMING)
            lock (in_lock_obj)
            {
                if (wMsg == Midi.MIM_DATA && 
                    (Command)((byte)dwParam1) == Command.NoteOn && 
                    (Note)(byte)(dwParam1>>8) == Note.Dot)
                {
                    FWCMidi.SendSetMessage(FWC.Opcode.RDAL_OP_WRITE_GPIO, 0x01, 0);
                    FWCMidi.SendSetMessage(FWC.Opcode.RDAL_OP_WRITE_GPIO, 0x00, 0);
                }
            }
#else
			lock(in_lock_obj)
			{
				switch(wMsg)
				{
					case Midi.MIM_DATA:                        
						Command cmd = (Command)((byte)dwParam1);
						byte byte1 = (byte)(dwParam1>>8);
						byte byte2 = (byte)(dwParam1>>16);

						switch(cmd)
						{
							case Command.NoteOn:
								switch((Note)byte1)
								{
									case Note.Dot:
										//console.Keyer.FWCDot = true;
                                        CWSensorItem.InputType type = CWSensorItem.InputType.Dot;
                                        if (reverse_paddles) type = CWSensorItem.InputType.Dash;

                                        CWSensorItem item = new CWSensorItem(type, true);
                                        CWKeyer.SensorEnqueue(item);
										break;
									case Note.Dash:
										//console.Keyer.FWCDash = true;
                                        type = CWSensorItem.InputType.Dash;
                                        if (reverse_paddles) type = CWSensorItem.InputType.Dot;

                                        item = new CWSensorItem(type, true);
                                        CWKeyer.SensorEnqueue(item);
										break;
									case Note.MicDown:
                                        if (console == null) return 1;
										console.MicDown = true;
										break;
									case Note.MicUp:
                                        if (console == null) return 1;
										console.MicUp = true;
										break;
									case Note.MicFast:
                                        if (console == null) return 1;
										console.MicFast = !console.MicFast;
										break;
								}
								break;
							case Command.NoteOff:
								switch((Note)byte1)
								{
									case Note.Dot:
										//console.Keyer.FWCDot = false;							
                                        CWSensorItem.InputType type = CWSensorItem.InputType.Dot;
                                        if (reverse_paddles) type = CWSensorItem.InputType.Dash;

                                        CWSensorItem item = new CWSensorItem(type, false);
                                        CWKeyer.SensorEnqueue(item);
										break;
									case Note.Dash:
										//console.Keyer.FWCDash = false;
                                        type = CWSensorItem.InputType.Dash;
                                        if (reverse_paddles) type = CWSensorItem.InputType.Dot;

                                        item = new CWSensorItem(type, false);
                                        CWKeyer.SensorEnqueue(item);
										break;
									case Note.MicDown:
                                        if (console == null) return 1;
										console.MicDown = false;
										break;
									case Note.MicUp:
                                        if (console == null) return 1;
										console.MicUp = false;
										break;
									case Note.MicFast:
										break;
								}
								break;
							case Command.Controller:
								switch((Controller)byte1)
								{
									case Controller.HoldPedal:
                                        if (console == null) return 1;
										console.FWCMicPTT = (byte2 > 63);
										break;
									case Controller.Hold2Pedal:
                                        if (console == null) return 1;
										console.FWCRCAPTT = (byte2 > 63);
										break;
								}
								break;
							case Command.Aftertouch0:
							case Command.Aftertouch1:
								int id = (ushort)((((byte)cmd-(byte)Command.Aftertouch0)<<2)+(byte1>>5));
								int data = (int)(((byte1&0x1F)<<7)+byte2);
								if(midi_in_table.ContainsKey(id))
									midi_in_table.Remove(id);
								midi_in_table.Add(id, data);
								break;
						}							
						break;
					case Midi.MIM_LONGDATA:
						if(!resetting && midi_in_handle != 0) // in case device closes, don't send anymore buffers
						{
							int result = Midi.AddSysExBuffer(midi_in_handle);
							if(result != 0) 
							{
								StringBuilder error_text = new StringBuilder(64);
								Midi.MidiInGetErrorText(result, error_text, 64);
								Debug.WriteLine("AddSysExBuffer Error: "+error_text);
							}
						}

						IntPtr headerPtr = new IntPtr(dwParam1);
						Midi.MidiHeader header = (Midi.MidiHeader)Marshal.PtrToStructure(headerPtr, typeof(Midi.MidiHeader));
						byte[] temp = new byte[header.bytesRecorded];
						for(int i=0; i<header.bytesRecorded; i++)
							temp[i] = Marshal.ReadByte(header.data, i);

						if(temp.Length > 5)
						{
							byte[] temp2 = new byte[temp.Length-5];
							for(int i=0; i<temp.Length-5; i++)
								temp2[i] = temp[i+4];
					
							byte[] buf = new byte[temp2.Length/2];
							DecodeBytes(buf, temp2);
							if(midi_in_table.ContainsKey(BitConverter.ToUInt16(buf, 0)))
								midi_in_table.Remove(BitConverter.ToUInt16(buf, 0));
							midi_in_table.Add(BitConverter.ToUInt16(buf, 0), buf);
						}

						/*for(int i=0; i<header.bytesRecorded; i++)
							Debug.Write(buf[i].ToString("X")+" ");
						Debug.WriteLine("");*/

						if(midi_in_handle != 0)
							Midi.ReleaseBuffer(midi_in_handle, headerPtr);
						break;
				}
			}
#endif			
			return 0;
		}