Now you can download a copy of these docs so you can use them offline! Download now
HiTechnicCompass.cpp
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #include "HiTechnicCompass.h"
8 #include "DigitalModule.h"
9 #include "I2C.h"
10 #include "NetworkCommunication/UsageReporting.h"
11 #include "WPIErrors.h"
12 #include "LiveWindow/LiveWindow.h"
13 
14 const uint8_t HiTechnicCompass::kAddress;
15 const uint8_t HiTechnicCompass::kManufacturerBaseRegister;
16 const uint8_t HiTechnicCompass::kManufacturerSize;
17 const uint8_t HiTechnicCompass::kSensorTypeBaseRegister;
18 const uint8_t HiTechnicCompass::kSensorTypeSize;
19 const uint8_t HiTechnicCompass::kHeadingRegister;
20 
27  : m_i2c (NULL)
28 {
29  m_table = NULL;
30  DigitalModule *module = DigitalModule::GetInstance(moduleNumber);
31  if (module)
32  {
33  m_i2c = module->GetI2C(kAddress);
34 
35  // Verify Sensor
36  const uint8_t kExpectedManufacturer[] = "HiTechnc";
37  const uint8_t kExpectedSensorType[] = "Compass ";
38  if ( ! m_i2c->VerifySensor(kManufacturerBaseRegister, kManufacturerSize, kExpectedManufacturer) )
39  {
40  wpi_setWPIError(CompassManufacturerError);
41  return;
42  }
43  if ( ! m_i2c->VerifySensor(kSensorTypeBaseRegister, kSensorTypeSize, kExpectedSensorType) )
44  {
45  wpi_setWPIError(CompassTypeError);
46  }
47 
48  nUsageReporting::report(nUsageReporting::kResourceType_HiTechnicCompass, moduleNumber - 1);
49  LiveWindow::GetInstance()->AddSensor("HiTechnicCompass", moduleNumber, 0, this);
50  }
51 }
52 
57 {
58  delete m_i2c;
59  m_i2c = NULL;
60 }
61 
70 {
71  uint16_t heading = 0;
72  if (m_i2c)
73  {
74  m_i2c->Read(kHeadingRegister, sizeof(heading), (uint8_t *)&heading);
75 
76  // Sensor is little endian... swap bytes
77  heading = (heading >> 8) | (heading << 8);
78  }
79  return (float)heading;
80 }
81 
83  if (m_table != NULL) {
84  m_table->PutNumber("Value", GetAngle());
85  }
86 }
87 
89 
90 }
91 
93 
94 }
95 
97  return "HiTechnicCompass";
98 }
99 
101  m_table = subTable;
102  UpdateTable();
103 }
104 
106  return m_table;
107 }
108 
virtual void PutNumber(std::string key, double value)=0
virtual ~HiTechnicCompass()
Definition: ITable.h:26
void InitTable(ITable *subTable)
std::string GetSmartDashboardType()
void AddSensor(const char *subsystem, const char *name, LiveWindowSendable *component)
Definition: LiveWindow.cpp:82
static LiveWindow * GetInstance()
Definition: LiveWindow.cpp:13
bool Read(uint8_t registerAddress, uint8_t count, uint8_t *data)
Definition: I2C.cpp:161
HiTechnicCompass(uint8_t moduleNumber)
static DigitalModule * GetInstance(uint8_t moduleNumber)
bool VerifySensor(uint8_t registerAddress, uint8_t count, const uint8_t *expected)
Definition: I2C.cpp:219
I2C * GetI2C(uint32_t address)

Generated on Sat Apr 26 2014 12:26:45 for WPILibC++ by doxygen 1.8.6