modified i2c registermap, added stubs #featureadd
making progress on i2c input. new functions are stubs at the present progress on #22
This commit is contained in:
parent
539e5d1411
commit
44bd9f0182
3 changed files with 95 additions and 24 deletions
|
|
@ -1,5 +1,3 @@
|
||||||
//#pragma once
|
|
||||||
//#include "pP_function.h"
|
|
||||||
#include "pP_config.h"
|
#include "pP_config.h"
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,23 +5,59 @@
|
||||||
#include "pP_i2c.h"
|
#include "pP_i2c.h"
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
|
|
||||||
|
byte registerMap[regMapSize];
|
||||||
|
byte registerMapTemp[regMapSize - 1];
|
||||||
|
byte receivedCommands[maxBytes];
|
||||||
|
|
||||||
pP_i2c::pP_i2c(){
|
pP_i2c::pP_i2c(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pP_i2c::init() {
|
void pP_i2c::init() {
|
||||||
Wire.begin(pP_i2c_address);
|
Wire.begin(pP_i2c_address);
|
||||||
|
Wire.onRequest(i2cReply);
|
||||||
|
Wire.onReceive(i2cInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pP_i2c::i2cReportStatus() {
|
||||||
|
_i2cResponse = "{"
|
||||||
|
}
|
||||||
|
|
||||||
|
void pP_i2c::i2cReportVersion() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void pP_i2c::i2cReportConfig() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void pP_i2c::i2cReportIdentity() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void pP_i2c::i2cRequestInput() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void pP_i2c::i2cReply() {
|
||||||
|
Wire.send()
|
||||||
}
|
}
|
||||||
|
|
||||||
void pP_i2c::i2cInput(int bytesReceived) {
|
void pP_i2c::i2cInput(int bytesReceived) {
|
||||||
for (int a = 0; a < bytesReceived; a++) {
|
for (int a = 0; a < bytesReceived; a++) {
|
||||||
if (a < maxBytes) {
|
// Check length of message, drops anything longer than [longBytes]
|
||||||
cmdRcvd[a] = Wire.read();
|
if (a <= maxBytes) {
|
||||||
|
cmdRcvd[a] = Wire.receive();
|
||||||
|
}
|
||||||
|
elif (a <= longBytes) {
|
||||||
|
longRcvd[a] = Wire.receive();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
longRcvd[a] = Wire.read();
|
Wire.receive(); //
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check input command corresponds with register map, set 0x00 if not
|
||||||
if (bytesReceived == 1 && (cmdRcvd[0] < regMapSize)) {
|
if (bytesReceived == 1 && (cmdRcvd[0] < regMapSize)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -29,35 +65,65 @@ void pP_i2c::i2cInput(int bytesReceived) {
|
||||||
cmdRcvd[0] = 0x00;
|
cmdRcvd[0] = 0x00;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse commands and apply changes or actions
|
||||||
switch (cmdRcvd[0]) {
|
switch (cmdRcvd[0]) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
followerInt = (long) cmdRcvd[1];
|
i2cReportStatus();
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x01:
|
case 0x01:
|
||||||
compInt = (long) cmdRcvd[1];
|
followerInt = (int) cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x02:
|
case 0x02:
|
||||||
GAIN_FACTOR = (uint8_t) cmdRcvd[1];
|
compInt = (int) cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x03:
|
case 0x03:
|
||||||
Hyst = (uint8_t) cmdRcvd[1];
|
GAIN_FACTOR = (int) cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x04:
|
case 0x04:
|
||||||
LOOP_DUR = (uint8_t) cmdRcvd[1];
|
Hyst = (int) cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x05:
|
case 0x05:
|
||||||
TRG_DUR = (uint8_t) cmdRcvd[1];
|
LOOP_DUR = (int) cmdRcvd[1];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
case 0x06:
|
case 0x06:
|
||||||
|
LOGIC = (int) cmdRcvd[1];
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case 0x07:
|
||||||
|
PZDET = (int) cmdRcvd[1];
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case 0x08:
|
||||||
|
TRG_DUR = (int) cmdRcvd[1];
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case 0x09:
|
||||||
|
DEBUG = (int) cmdRcvd[1];
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case 0x0a:
|
||||||
voltMeterConstant = longRcvd[0]*65536+longRcvd[1]*256+longRcvd[2];
|
voltMeterConstant = longRcvd[0]*65536+longRcvd[1]*256+longRcvd[2];
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
|
case 0x0b:
|
||||||
|
reportVersion();
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case 0x0c:
|
||||||
|
reportConfig();
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case 0x0d:
|
||||||
|
reportIdentity();
|
||||||
|
return;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,24 @@
|
||||||
#define _pP_i2c_h_
|
#define _pP_i2c_h_
|
||||||
#ifdef I2C_INPUT
|
#ifdef I2C_INPUT
|
||||||
|
|
||||||
|
#define status_Offset 0x00 // Status register
|
||||||
#define senseInt_Offset 0x00 // Integer of sense threshold in millivolts
|
#define senseInt_Offset 0x01 // Integer of sense threshold in millivolts
|
||||||
#define compInt_Offset 0x01 // Integer of comparator threshold in millivolts
|
#define compInt_Offset 0x02 // Integer of comparator threshold in millivolts
|
||||||
#define gainFactor_Offset 0x02 // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x
|
#define gainFactor_Offset 0x03 // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x
|
||||||
#define hysteresis_Offset 0x03 // Hysteresis value for ADC measurements
|
#define hysteresis_Offset 0x04 // Hysteresis value for ADC measurements
|
||||||
#define loopDuration_Offset 0x04 // duration of time between ADC checks and other loop functions
|
#define loopDuration_Offset 0x05 // duration of time between ADC checks and other loop functions
|
||||||
#define triggerDuration_Offset 0x05 // duration of the Z-axis pulse sent, in ms
|
#define logicLevel_Offset 0x06
|
||||||
#define voltMeterLong_Offset 0x06 // For fine-tuning the input volt master
|
#define piezoDetect_Offset 0x07
|
||||||
|
#define triggerDuration_Offset 0x08 // duration of the Z-axis pulse sent, in ms
|
||||||
|
#define debugEnable_Offset 0x09
|
||||||
|
#define voltMeterLong_Offset 0x0a // For fine-tuning the input volt master
|
||||||
|
#define versionRegister_Offset 0x0b
|
||||||
|
#define configRegister_Offset 0x0c
|
||||||
|
#define identRegister_Offset 0x0d
|
||||||
|
|
||||||
/*-------------------------Variables------------------------*/
|
/*-------------------------Variables------------------------*/
|
||||||
#define regMapSize 7
|
#define regMapSize 14
|
||||||
uint8_t maxBytes = 2;
|
#define maxBytes 2
|
||||||
#define longBytes 4
|
#define longBytes 4
|
||||||
byte regMap[regMapSize];
|
byte regMap[regMapSize];
|
||||||
byte regMapTemp[regMapSize];
|
byte regMapTemp[regMapSize];
|
||||||
|
|
@ -26,10 +32,11 @@ byte longRcvd[longBytes];
|
||||||
class pP_i2c {
|
class pP_i2c {
|
||||||
public:
|
public:
|
||||||
pP_i2c(uint8_t address=pP_i2c_address);
|
pP_i2c(uint8_t address=pP_i2c_address);
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void i2cInput(int bytesReceived);
|
void i2cInput(int bytesReceived);
|
||||||
|
private:
|
||||||
|
char _i2cResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // I2C_INPUT
|
||||||
#endif
|
#endif // _pP_i2c_h_
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue