private void btnMusic_Click(object sender, EventArgs e)
        {
            sound_effect_stop_request = new ThreadStopRequest();
            oSoundEffect = new Music(mut_uFR, sound_effect_stop_request);
            oSoundThread = new Thread(new ThreadStart(oSoundEffect.run));
            oSoundThread.Start();

            btnSoundEffect1.Enabled    = false;
            btnSoundEffect2.Enabled    = false;
            btnMusic.Enabled           = false;
            btnStopSoundEffect.Enabled = true;
        }
        private void btnStopSoundEffect_Click(object sender, EventArgs e)
        {
            sound_effect_stop_request.stopRequest();
            oSoundThread.Join();
            oSoundThread = null;
            sound_effect_stop_request = null;
            oSoundEffect = null;

            btnSoundEffect1.Enabled    = true;
            btnSoundEffect2.Enabled    = true;
            btnMusic.Enabled           = true;
            btnStopSoundEffect.Enabled = false;
        }
        private void btnEffect2_Click(object sender, EventArgs e)
        {
            effect_stop_request = new ThreadStopRequest();
            oEffect             = new Effect2(mut_uFR, effect_stop_request);
            oThread             = new Thread(new ThreadStart(oEffect.run));
            oThread.Start();

            btnSetDisplayColor.Enabled = false;
            btnClearDisplay.Enabled    = false;
            btnEffect1.Enabled         = false;
            btnEffect2.Enabled         = false;
            btnStopEffect.Enabled      = true;
        }
        private void btnClose_Click(object sender, EventArgs e)
        {
            DL_STATUS status;

            if (btnStopEffect.Enabled)
            {
                effect_stop_request.stopRequest();
                oThread.Join();
                oThread             = null;
                oEffect             = null;
                effect_stop_request = null;
            }

            if (btnStopSoundEffect.Enabled)
            {
                sound_effect_stop_request.stopRequest();
                oSoundThread.Join();
                oSoundThread = null;
                sound_effect_stop_request = null;
                oSoundEffect = null;
            }

            SetDisplayColor(0);

            mut_uFR.WaitOne();
            status = uFCoder.ReaderClose();
            mut_uFR.ReleaseMutex();

            if (status == DL_STATUS.UFR_OK)
            {
                statusReader.Text          = "Reader not connected";
                tbDeviceType.Text          = "";
                tbDeviceSerialNr.Text      = "";
                btnClose.Enabled           = false;
                btnCardIdEx.Enabled        = false;
                btnSetDisplayColor.Enabled = false;
                btnClearDisplay.Enabled    = false;
                btnEffect1.Enabled         = false;
                btnEffect2.Enabled         = false;
                btnStopEffect.Enabled      = false;
                btnSoundEffect1.Enabled    = false;
                btnSoundEffect2.Enabled    = false;
                btnStopSoundEffect.Enabled = false;
                btnMusic.Enabled           = false;
                btnOpen.Enabled            = true;
                btnLedIntensity.Enabled    = false;
            }
        }
        private void btnStopEffect_Click(object sender, EventArgs e)
        {
            effect_stop_request.stopRequest();
            oThread.Join();
            oThread             = null;
            effect_stop_request = null;
            oEffect             = null;

            btnSetDisplayColor.Enabled = true;
            btnClearDisplay.Enabled    = true;
            btnEffect1.Enabled         = true;
            btnEffect2.Enabled         = true;
            btnStopEffect.Enabled      = false;

            SetDisplayColor(0);
        }
        public Effect2(Mutex mut, ThreadStopRequest request)
            : base(mut, request)
        {
            //data = new byte[DisplayConsts.DISPLAY_BUFFER_LEN];
            data = Enumerable.Repeat((byte)0, DisplayConsts.DISPLAY_BUFFER_LEN).ToArray();

            // red component setup:
            data[1]  = 40;
            data[4]  = 30;
            data[7]  = 20;
            data[10] = 10;
            data[13] = 4;

            // blue component setup:
            data[23] = 2;
            data[26] = 10;
            data[29] = 20;
            data[32] = 30;
            data[35] = 45;
        }
        public Music(Mutex mut, ThreadStopRequest request)
            : base(mut, request)
        {
            music_cnt = 0;

            // tones duration goes to parent data:
            data = new byte[] { 200, 200, 200, 200, 0,
                                200, 200, 200, 200, 0,
                                200, 200, 200, 200,
                                200, 200, 200, 200,
                                125, 125, 125, 125, 150, 200, 25,
                                125, 125, 125, 125, 150, 200, 25,
                                200, 250, 200, 100,
                                200, 250, 200 };

            music = new short[] { SoundConsts.C2, SoundConsts.D2, SoundConsts.E2, SoundConsts.C2, 0,
                                  SoundConsts.C2, SoundConsts.D2, SoundConsts.E2, SoundConsts.C2, 0,
                                  SoundConsts.E2, SoundConsts.F2, SoundConsts.G2, 0,
                                  SoundConsts.E2, SoundConsts.F2, SoundConsts.G2, 0,
                                  SoundConsts.G2, SoundConsts.A2, SoundConsts.G2, SoundConsts.F2, SoundConsts.E2, SoundConsts.C2, 0,
                                  SoundConsts.G2, SoundConsts.A2, SoundConsts.G2, SoundConsts.F2, SoundConsts.E2, SoundConsts.C2, 0,
                                  SoundConsts.C2, SoundConsts.G2, SoundConsts.C2, 0,
                                  SoundConsts.C2, SoundConsts.G2, SoundConsts.C2 };
        }
        public Effect1(Mutex mut, ThreadStopRequest request)
            : base(mut, request)
        {
            int  i, byte_cnt = 0;
            byte green, red, blue;

            data = new byte[DisplayConsts.DISPLAY_BUFFER_LEN];
            //data = Enumerable.Repeat((byte)0, DisplayConsts.DISPLAY_BUFFER_LEN).ToArray();

            green = 2;
            red   = 10;
            blue  = 3;

            for (i = 0; i < DisplayConsts.DISPLAY_LEDS; i++)
            {
                data[byte_cnt++] = green;
                data[byte_cnt++] = red;
                data[byte_cnt++] = blue;

                red   += 1;
                green += 2;
                blue  += 3;
            }
        }
 public SoundEffect2(Mutex mut, ThreadStopRequest request)
     : base(mut, request)
 {
     effect_cnt       = 0;
     effect_direction = true;
 }
 public SoundEffect1(Mutex mut, ThreadStopRequest request)
     : base(mut, request)
 {
     toggle_effect = false;
 }
 public Effect(Mutex mut, ThreadStopRequest request)
 {
     uFR_mutex    = mut;
     stop_request = request;
 }