Пример #1
0
 /// <summary>
 ///     Reset the sensor.
 /// </summary>
 public void Reset()
 {
     Standby = true;
     _mag3110.WriteRegister((byte)Registers.Control1, 0x00);
     _mag3110.WriteRegister((byte)Registers.Control2, 0x80);
     _mag3110.WriteRegisters((byte)Registers.XOffsetMSB, new byte[] { 0, 0, 0, 0, 0, 0 });
 }
Пример #2
0
 /// <summary>
 ///     Reset the sensor.
 /// </summary>
 public void Reset()
 {
     Standby = true;
     i2cPeripheral.WriteRegister((byte)Registers.Control1, 0x00);
     i2cPeripheral.WriteRegister((byte)Registers.Control2, 0x80);
     i2cPeripheral.WriteRegisters((byte)Registers.XOffsetMSB, new byte[] { 0, 0, 0, 0, 0, 0 });
 }
Пример #3
0
        protected void Initialize()
        {
            byte[] buffers = new byte[10];

            // IO Direction
            buffers[0] = 0xFF; //all input `11111111`

            // set all the other registers to zeros (we skip the last one, output latch)
            for (int i = 1; i < 10; i++)
            {
                buffers[i] = 0x00; //all zero'd out `00000000`
            }

            // the chip will automatically write all registers sequentially.
            _i2cPeripheral.WriteRegisters(_IODirectionRegister, buffers);

            // save our state
            _iodir = buffers[0];
            _gpio  = 0x00;
            _olat  = 0x00;
            _gppu  = 0x00;
        }
Пример #4
0
        /// <summary>
        ///     Set one of the two alarms on the DS323x module.
        /// </summary>
        /// <param name="alarm">Define the alarm to be set.</param>
        /// <param name="time">Date and time for the alarm.</param>
        /// <param name="type">Type of alarm to set.</param>
        public void SetAlarm(Alarm alarm, DateTime time, AlarmType type)
        {
            byte[] data     = null;
            var    register = Registers.Alarm1Seconds;
            var    element  = 0;

            if (alarm == Alarm.Alarm1Raised)
            {
                data    = new byte[5];
                element = 1;
                data[0] = Converters.ByteToBCD((byte)(time.Second & 0xff));
            }
            else
            {
                data     = new byte[4];
                register = Registers.Alarm2Minutes;
            }
            data[element++] = Converters.ByteToBCD((byte)(time.Minute & 0xff));
            data[element++] = Converters.ByteToBCD((byte)(time.Hour & 0xff));
            if ((type == AlarmType.WhenDayHoursMinutesMatch) || (type == AlarmType.WhenDayHoursMinutesSecondsMatch))
            {
                data[element] = (byte)(DayOfWeekToByte(time.DayOfWeek) | 0x40);
            }
            else
            {
                data[element] = Converters.ByteToBCD((byte)(time.Day & 0xff));
            }
            switch (type)
            {
            //
            //  Alarm 1 interrupts.
            //
            case AlarmType.OncePerSecond:
                data[0] |= 0x80;
                data[1] |= 0x80;
                data[2] |= 0x80;
                data[3] |= 0x80;
                break;

            case AlarmType.WhenSecondsMatch:
                data[1] |= 0x80;
                data[2] |= 0x80;
                data[3] |= 0x80;
                break;

            case AlarmType.WhenMinutesSecondsMatch:
                data[2] |= 0x80;
                data[3] |= 0x80;
                break;

            case AlarmType.WhenHoursMinutesSecondsMatch:
                data[3] |= 0x80;
                break;

            case AlarmType.WhenDateHoursMinutesSecondsMatch:
                break;

            case AlarmType.WhenDayHoursMinutesSecondsMatch:
                data[3] |= 0x40;
                break;

            //
            //  Alarm 2 interupts.
            //
            case AlarmType.OncePerMinute:
                data[0] |= 0x80;
                data[1] |= 0x80;
                data[2] |= 0x80;
                break;

            case AlarmType.WhenMinutesMatch:
                data[1] |= 0x80;
                data[2] |= 0x80;
                break;

            case AlarmType.WhenHoursMinutesMatch:
                data[2] |= 0x80;
                break;

            case AlarmType.WhenDateHoursMinutesMatch:
                break;

            case AlarmType.WhenDayHoursMinutesMatch:
                data[2] |= 0x40;
                break;
            }
            _ds323x.WriteRegisters(register, data);
            //
            //  Turn the relevant alarm on.
            //
            var controlRegister = ControlRegister;
            var bits            = (byte)ControlRegisterBits.A1IE;

            if (alarm == Alarm.Alarm2Raised)
            {
                bits = (byte)ControlRegisterBits.A2IE;
            }
            controlRegister |= (byte)ControlRegisterBits.INTCON;
            controlRegister |= bits;
            ControlRegister  = controlRegister;
        }
Пример #5
0
 public void UpdateDisplay()
 {
     i2cPeripheral.WriteRegisters(0x0, displayBuffer);
 }