/// <summary> /// Gets the current sensor reading from the device. /// </summary> /// <returns>Returns an ISensorReading instance that /// indicates current temperature and whether or not /// the thresholds have been exceeded.</returns> public Task <IDeviceSensorReading> ReadSensor() { // *** // *** Initialize a value to hold the device temperature // *** in Celsius // *** DeviceSensorReading returnValue = new DeviceSensorReading(); // *** // *** The register/command for reading ambient temperature // *** from the device is 0x05 // *** byte[] readBuffer = this.ReadFromRegister(Mcp9808Register.AmbientTemperature); // *** // *** Calculate the temperature value // *** returnValue.Temperature = RegisterConverter.ToFloat(readBuffer); // *** // *** Check the flags // *** returnValue.IsCritical = (readBuffer[0] & 0x80) == 0x80; returnValue.IsAboveUpperThreshold = (readBuffer[0] & 0x40) == 0x40; returnValue.IsBelowLowerThreshold = (readBuffer[0] & 0x20) == 0x20; // *** // *** Return the value // *** return(Task <IDeviceSensorReading> .FromResult((IDeviceSensorReading)returnValue)); }
public async Task <bool> SetHeaterStatus(HeaterStatus heaterStatus) { bool returnValue = false; // *** // *** Get the current register // *** byte register = await this.GetRegister(); // *** // *** Set the bit // *** register = RegisterConverter.SetBit(register, REGISTER_BIT_HEATER, heaterStatus == HeaterStatus.On); // *** // *** Write the register // *** await this.WriteRegister(register); // *** // *** Check the register // *** returnValue = (await this.GetHeaterStatus()) == heaterStatus; return(returnValue); }
public async Task <bool> SetResolution(Resolution resolution) { bool returnValue = false; // *** // *** Get the current register // *** byte register = await this.GetRegister(); // *** // *** Set the bits // *** register = RegisterConverter.SetBit(register, REGISTER_BIT_RESOLUTION_HIGH, resolution == Resolution.Rh10Temp13 || resolution == Resolution.Rh11Temp11); register = RegisterConverter.SetBit(register, REGISTER_BIT_RESOLUTION_LOW, resolution == Resolution.Rh8Temp12 || resolution == Resolution.Rh11Temp11); // *** // *** Write the register // *** await this.WriteRegister(register); // *** // *** Check the register // *** returnValue = (await this.GetResolution()) == resolution; return(returnValue); }
public async Task <Resolution> GetResolution() { Resolution returnValue = Resolution.Rh12Temp14; // *** // *** Get the current register // *** byte register = await this.GetRegister(); if (RegisterConverter.BitIsLow(register, REGISTER_BIT_RESOLUTION_HIGH) && RegisterConverter.BitIsLow(register, REGISTER_BIT_RESOLUTION_LOW)) { returnValue = Resolution.Rh12Temp14; } else if (RegisterConverter.BitIsLow(register, REGISTER_BIT_RESOLUTION_HIGH) && RegisterConverter.BitIsHigh(register, REGISTER_BIT_RESOLUTION_LOW)) { returnValue = Resolution.Rh8Temp12; } else if (RegisterConverter.BitIsHigh(register, REGISTER_BIT_RESOLUTION_HIGH) && RegisterConverter.BitIsLow(register, REGISTER_BIT_RESOLUTION_LOW)) { returnValue = Resolution.Rh10Temp13; } else if (RegisterConverter.BitIsHigh(register, REGISTER_BIT_RESOLUTION_HIGH) && RegisterConverter.BitIsHigh(register, REGISTER_BIT_RESOLUTION_LOW)) { returnValue = Resolution.Rh11Temp11; } return(returnValue); }
public ActionResult ParticipentRegister([Bind("Email,Firstname,Lastname,Password")] ParticipantRegisterViewModel participantRegisterobj) { BachelorBackEnd.participants currentParticipants = RegisterConverter.ParticipantobjFromViewToDto(participantRegisterobj); DataAcess = new DalParticipant(); DataAcess.SaveRegisterDto(currentParticipants); try { return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
/// <summary> /// Sets the value of a configuration bit at the given /// index. /// </summary> /// <param name="bitIndex">Specifies the configuration /// bit index from 0 to 15.</param> /// <param name="value">The value of the bit to set.</param> public virtual void SetConfigurationBit(int bitIndex, bool value) { // *** // *** Read the current configuration // *** byte[] config = this.ReadFromRegister(Mcp9808Register.Configuration); // *** // *** Set the selected bit // *** config[bitIndex > 7 ? 0 : 1] = RegisterConverter.SetBit(config[bitIndex > 7 ? 0 : 1], bitIndex % 8, value); // *** // *** Write the configuration back to the register // *** this.WriteToRegister(Mcp9808Register.Configuration, config[0], config[1]); }
public async Task <BatteryStatus> GetBatteryStatus() { BatteryStatus returnValue = BatteryStatus.Unknown; // *** // *** Get the current register // *** byte register = await this.GetRegister(); if (RegisterConverter.BitIsHigh(register, REGISTER_BIT_BATTERY)) { returnValue = BatteryStatus.Low; } else { returnValue = BatteryStatus.Good; } return(returnValue); }
public async Task <HeaterStatus> GetHeaterStatus() { HeaterStatus returnValue = HeaterStatus.Off; // *** // *** Get the current register // *** byte register = await this.GetRegister(); if (RegisterConverter.BitIsHigh(register, REGISTER_BIT_HEATER)) { returnValue = HeaterStatus.On; } else { returnValue = HeaterStatus.Off; } return(returnValue); }
/// <summary> /// Gets the value of the configuration bit at /// the given index. /// </summary> /// <param name="bitIndex">Specifies the configuration /// bit index from 0 to 15.</param> /// <returns>Returns true if the bit is High and false /// if the bit is low.</returns> public virtual bool GetConfigurationBit(int bitIndex) { byte[] buffer = this.ReadFromRegister(Mcp9808Register.Configuration); return(RegisterConverter.BitIsHigh(buffer[bitIndex > 7 ? 0 : 1], bitIndex)); }
private byte[] GetDataBytes(IRegisterMessage message, out IReadOnlyCollection <IRegisterGroup> composedGroups) { byte gByte; bool withValues = false; switch (message.Type) { case MessageType.Request: gByte = MilliGanjubusInfo.GRequest; break; case MessageType.Response: gByte = (byte)(MilliGanjubusInfo.GReply << 4); withValues = true; break; default: throw new NandakaBaseException("Undefined message type"); } bool isRange = RegisterConverter.IsRange(message.RegisterGroups, _info); switch (message.OperationType) { case OperationType.Read: if (isRange) { gByte |= MilliGanjubusInfo.FReadRange; } else { gByte |= MilliGanjubusInfo.FReadSeries; } break; case OperationType.Write: if (isRange) { gByte |= MilliGanjubusInfo.FWriteRange; } else { gByte |= MilliGanjubusInfo.FWriteSeries; } // By default assume that this is read operation. Otherwise invert variable. withValues = !withValues; break; default: throw new NandakaBaseException("Undefined operation type"); } byte[] dataHeader = { gByte }; if (isRange) { return(RegisterConverter.ComposeDataAsRange(message.RegisterGroups, _info, dataHeader, withValues, out composedGroups)); } return(RegisterConverter.ComposeDataAsSeries(message.RegisterGroups, _info, dataHeader, withValues, out composedGroups)); }