Esempio n. 1
0
        /// <summary>
        /// Gets BrailleIO_DeviceButtonStates flag int for the released keys.
        /// </summary>
        /// <param name="raw">The raw data set containing a key [UP_KEYS].</param>
        /// <returns>combined BrailleIO_DeviceButtonStates</returns>
        private BrailleIO_DeviceButtonStates getButtonUpStates(OrderedDictionary raw)
        {
            BrailleIO_DeviceButtonStates b = BrailleIO_DeviceButtonStates.None;

            try
            {
                if (raw.Contains(UP_KEYS) && raw[UP_KEYS] is HyperBraille.HBBrailleDis.BrailleDisKeyboard)
                {
                    HyperBraille.HBBrailleDis.BrailleDisKeyboard allDownKey = (HyperBraille.HBBrailleDis.BrailleDisKeyboard)raw[UP_KEYS];
                    var buttons = BraillDisButtonInterpreter.toSingleBrailleKeyEventList(allDownKey.AllKeys);

                    switch (type)
                    {
                    case "1":
                        b = getBasicButtonUpStates(buttons);
                        break;

                    default:
                        b = getNewButtonUpStates(buttons);
                        break;
                    }
                }
            }
            catch { }
            return(b);
        }
        /// <summary>
        /// Created the object to talk with the stiftplatte.
        /// </summary>
        /// <param name="config">the configurationManager to be used. Can be null, but it should not.</param>
        /// <exception cref="System.IO.IOException">Exception occurs if no stiftplatte is connected</exception>
        public BrailleDisNet(Object config)
        {
            _config = config;
            // initialize array for current matrix state
            this.m_matrix = new byte[2 * BrailleDisConsts.MODULE_COUNT];

            this.m_boolMatrix     = new bool[BrailleDisConsts.NUMBER_OF_PIN_ROWS, BrailleDisConsts.NUMBER_OF_PIN_COLUMNS];
            this.m_tempBoolMatrix = new bool[BrailleDisConsts.NUMBER_OF_PIN_ROWS, BrailleDisConsts.NUMBER_OF_PIN_COLUMNS];

            for (int i = 0; i < 2 * BrailleDisConsts.MODULE_COUNT; i++)
            {
                this.m_matrix[i] = BrailleDisConsts.BYTE_LOWER_ALL_PINS;
            }

            // initialize array for setting all pins
            this.m_matrix_set_all = new byte[2 * BrailleDisConsts.MODULE_COUNT];
            for (int i = 0; i < 2 * BrailleDisConsts.MODULE_COUNT; i++)
            {
                this.m_matrix_set_all[i] = BrailleDisConsts.BYTE_SET_ALL_PINS;
            }

            // initialize array for lowering all pins
            this.m_matrix_lower_all = new byte[2 * BrailleDisConsts.MODULE_COUNT];
            for (int i = 0; i < 2 * BrailleDisConsts.MODULE_COUNT; i++)
            {
                this.m_matrix_lower_all[i] = BrailleDisConsts.BYTE_LOWER_ALL_PINS;
            }

            // init keyboard state
            this.m_keyboard_state = new BrailleDisKeyboard(0);

            // initialize device
            bool initializationResult = this.Initialize();

            /*if (!initializationResult)
             * {
             *  String exceptionMessage = "Initialization of BrailleDis Device failed.";
             *  throw new System.IO.IOException(exceptionMessage);
             * }*/
        }
Esempio n. 3
0
        // read draw touch input data and evaluate it with the threshold
        private void ReadTouchInput(out int timeToWait)
        {
            // lock (synchLock) //  the lock is now in the MetecBD.dll
            {
                changedModules.Clear();
                activeModules.Clear();

                byte[] m_readBuffer = new byte[BrailleDisConsts.TOTAL_INPUT_LENGTH + 192]; // inkl. padding for too long blocks

                int readResult = 0;
                int timestamp;
                try
                {
                    //System.Threading.Thread.BeginCriticalRegion();
                    readResult = BrdReadData(this.UsedDevice.DeviceNumber, m_readBuffer.Length, m_readBuffer);
                    timestamp  = Environment.TickCount;

                    //timeToWait ist die Variable, die von ReadTouchinput zurückgeliefert wird
                    //Zeit in ms bis zum nchsten Scan des Touch-Inputs
                    //Dies hilft der Synchronisation mit der Hardware.
                    timeToWait = m_readBuffer[BrailleDisConsts.TIME_WAIT_BYTE];

                    if (readResult != BrailleDisConsts.TOTAL_INPUT_LENGTH)
                    {
                        this.fireErrorOccurredEvent(ErrorType.USB_PAKET_DEFECTIVE);
                        timeToWait = BrailleDisConsts.TIME_TOUCH_SCAN_INTERVAL;
                        Close();
                        return;
                    }
                }
                finally
                {
                    //System.Threading.Thread.EndCriticalRegion();
                }

                // new paket?
                if (m_lastPaketNumber == m_readBuffer[BrailleDisConsts.TIME_PAKET_BYTE])
                {
                    return;
                }

                //#if DEBUG
                if (m_lastPaketNumber != null)
                {
                    byte thatShouldBeThePaketNumber = (byte)(m_lastPaketNumber + 1);
                    if (thatShouldBeThePaketNumber != m_readBuffer[BrailleDisConsts.TIME_PAKET_BYTE])
                    {
                        //System.Diagnostics.Debug.WriteLine("Lost a Paket... oldPaketnr=" + m_lastPaketNumber.ToString() + " " +
                        // thatShouldBeThePaketNumber.ToString() + " newpaketnr=" +
                        // m_readBuffer[BrailleDisConsts.TIME_PAKET_BYTE].ToString());
                        this.fireErrorOccurredEvent(ErrorType.USB_PAKET_LOST);
                    }
                }
                //#endif

                m_lastPaketNumber = m_readBuffer[BrailleDisConsts.TIME_PAKET_BYTE];

                #region touch input handling

                int row;
                int column;
                int differenceCapacity;
                int generation = 0;

                if (m_readBuffer[BrailleDisConsts.INPUT_TYPE] == BrailleDisConsts.OLD_BRAILLEDIS)
                { // first generation of BrailleDis with 720 sensors
                    // todo: if you wish to treat the old BrailleDis withh 1440 sensors
                    // then set generation to 2 instead of 1
                    generation = 1;
                    foreach (var damagedTouches in m_damagedTouches)
                    { // duplicate because of duplication of sensors
                        int pos = damagedTouches.X + damagedTouches.Y * BrailleDisConsts.NUMBER_OF_MODULE_COLUMNS * 2;
                        if (pos >= BrailleDisConsts.TOUCH_ARRAY_SIZE)
                        {
                            continue;
                        }
                        m_readBuffer[BrailleDisConsts.FIRST_TOCH_BYTE + pos] = 0;
                        pos += 60; // second occurence of sensor
                        if (pos >= BrailleDisConsts.TOUCH_ARRAY_SIZE)
                        {
                            continue;
                        }
                        m_readBuffer[BrailleDisConsts.FIRST_TOCH_BYTE + pos] = 0;
                    }
                }
                else
                {
                    // todo: if you wish to treat the new BrailleDis withh 720 sensors
                    // then set generation to 1 instead of 2
                    generation = 2;
                    foreach (var damagedTouches in m_damagedTouches)
                    {
                        int pos = damagedTouches.X + damagedTouches.Y * BrailleDisConsts.NUMBER_OF_MODULE_COLUMNS;
                        if (pos >= BrailleDisConsts.TOUCH_ARRAY_SIZE)
                        {
                            continue;
                        }
                        m_readBuffer[BrailleDisConsts.FIRST_TOCH_BYTE + pos] = 0;
                    }
                }

                var d = this.UsedDevice;
                int[,] differenceCapacityArray = new int[DeviceTypeInformation.NumberOfSensorRows, DeviceTypeInformation.NumberOfModuleColumns];
                for (int i = 0; i < BrailleDisConsts.TOUCH_ARRAY_SIZE; i++)
                {
                    row    = i / BrailleDisConsts.NUMBER_OF_MODULE_COLUMNS;
                    column = i - row * BrailleDisConsts.NUMBER_OF_MODULE_COLUMNS;
                    // for the old BrailleDis you should only treat 720 sensors
                    if (generation == 1)
                    {
                        if ((row & 1) == 1) // second sensor on a module
                        {
                            i += 59;        // do not process this sensor line
                            continue;
                        }
                        row /= 2; // correct number
                    }
                    // evaluate input regarding threshold
                    differenceCapacity = this.m_reference_touch_input[row, column]
                                         - m_readBuffer[BrailleDisConsts.FIRST_TOCH_BYTE + i];

                    var reallyLastDifCap = m_lastValues[row, column];
                    if (d != null)
                    {
                        differenceCapacity = d.Glaetten(reallyLastDifCap, differenceCapacity);
                    }
                    this.m_lastValues[row, column] = differenceCapacity;

                    //Werte mit zu kleinem Wert komplett ausblenden
                    if (differenceCapacity < this.m_touch_threshold)
                    {
                        differenceCapacity = 0;
                    }

                    differenceCapacityArray[row, column] = differenceCapacity;
                }

                if (d != null)
                {
                    d.Filter(differenceCapacityArray, m_touch_threshold);
                }
                for (row = 0; row < differenceCapacityArray.GetLength(0); row++)
                {
                    for (column = 0; column < differenceCapacityArray.GetLength(1); column++)
                    {
                        differenceCapacity = differenceCapacityArray[row, column];

                        //Änderungen in changedModules speichern
                        if (differenceCapacity != this.m_touch_input[row, column])
                        {
                            changedModules.Add(new BrailleDisModuleState(row, column, this.m_touch_input[row, column],
                                                                         differenceCapacity, generation));
                            this.m_touch_input[row, column] = differenceCapacity;
                        }
                        //ActiceModules-Array füllen
                        if (this.m_touch_input[row, column] != 0)
                        {
                            activeModules.Add(new BrailleDisModuleState(row, column, -1, this.m_touch_input[row, column], generation));
                        }
                    }
                }

                #endregion

                #region key input handling

                // the oldest keyklick is the last keyklick; therefore go down
                for (int k = BrailleDisConsts.KEYBOARD_LAST_POS;
                     k >= BrailleDisConsts.KEYBOARD_START;
                     k -= BrailleDisConsts.KEYBOARD_LENGTH)
                {
                    BrailleDisKeyboard newKeyboardState = new BrailleDisKeyboard(m_readBuffer, k, m_keyfilter);

                    // raise keyboard event, if necesary
                    if (m_keyboard_state.AllKeys != newKeyboardState.AllKeys)
                    {
                        UInt64 pressed  = ~m_keyboard_state.AllKeys & newKeyboardState.AllKeys;
                        UInt64 released = m_keyboard_state.AllKeys & ~newKeyboardState.AllKeys;
                        this.fireKeyStateChangedEvent(new BrailleDisKeyboard(pressed),
                                                      new BrailleDisKeyboard(released),
                                                      newKeyboardState, timestamp);
                    }
                    this.m_keyboard_state.AllKeys = newKeyboardState.AllKeys;
                } // end for k

                #endregion

                #region raise 50ms events
                if (changedModules.Count > 0)
                {
                    this.fireTouchValuesChangedEvent(changedModules.ToArray(), activeModules.ToArray(), timestamp);
                }
                this.fireInputChangedEvent((changedModules.Count > 0), (int[, ]) this.m_touch_input.Clone(), this.m_keyboard_state,
                                           timestamp);
                #endregion

                #region Jitter-Korrektur
                int timeForPC = Environment.TickCount - timestamp;
                timestamp -= timeForPC;
                #endregion
            }
        }
 // gibt nur die row und column und den wert der geänderten module zurück
 private void fireKeyStateChangedEvent(BrailleDisKeyboard pressedKeys, BrailleDisKeyboard releasedKeys,
                                       BrailleDisKeyboard keyboardState, int timestamptickcount)
 {
     fireEventInFireEventThread(callType.keystatechanged,
                                keyStateChangedEvent, pressedKeys, releasedKeys, keyboardState, timestamptickcount);
 }
 private void fireInputChangedEvent(bool touchInputAvailable, int[,] valueMatrix, BrailleDisKeyboard keyboardState, int timestamptickcount)
 {
     fireEventInFireEventThread(callType.inputchanged,
                                inputChangedEvent, touchInputAvailable, valueMatrix, keyboardState, timestamptickcount);
 }