001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.wpilibj.simulation; 006 007import edu.wpi.first.hal.SimDouble; 008import edu.wpi.first.wpilibj.ADXL345_I2C; 009import edu.wpi.first.wpilibj.ADXL345_SPI; 010import java.util.Objects; 011 012public class ADXL345Sim { 013 protected SimDouble m_simX; 014 protected SimDouble m_simY; 015 protected SimDouble m_simZ; 016 017 /** 018 * Constructor. 019 * 020 * @param device The device to simulate 021 */ 022 public ADXL345Sim(ADXL345_SPI device) { 023 SimDeviceSim simDevice = new SimDeviceSim("Accel:ADXL345_SPI" + "[" + device.getPort() + "]"); 024 initSim(simDevice); 025 } 026 027 /** 028 * Constructor. 029 * 030 * @param device The device to simulate 031 */ 032 public ADXL345Sim(ADXL345_I2C device) { 033 SimDeviceSim simDevice = 034 new SimDeviceSim( 035 "Accel:ADXL345_I2C" + "[" + device.getPort() + "," + device.getDeviceAddress() + "]"); 036 initSim(simDevice); 037 } 038 039 private void initSim(SimDeviceSim simDevice) { 040 Objects.requireNonNull(simDevice); 041 042 m_simX = simDevice.getDouble("x"); 043 m_simY = simDevice.getDouble("y"); 044 m_simZ = simDevice.getDouble("z"); 045 046 Objects.requireNonNull(m_simX); 047 Objects.requireNonNull(m_simY); 048 Objects.requireNonNull(m_simZ); 049 } 050 051 public void setX(double x) { 052 m_simX.set(x); 053 } 054 055 public void setY(double y) { 056 m_simY.set(y); 057 } 058 059 public void setZ(double z) { 060 m_simZ.set(z); 061 } 062}