Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryDaniel53 authored Oct 7, 2024
1 parent 623e105 commit 431db07
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 50 deletions.
15 changes: 8 additions & 7 deletions CamParser.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

//sensorCAM parser.cpp version 3.01 Aug 2024
//sensorCAM parser.cpp version 3.03 Sep 2024
#include "CamParser.h"
#include "FSH.h"
#include "IO_EXSensorCAM.h"
Expand Down Expand Up @@ -48,17 +48,18 @@ bool CamParser::parseN(Print * stream, byte paramCount, int16_t p[]) {
}
if (EXSensorCAM::CAMBaseVpin==0) return false; // no cam defined

if((p[0] == ve) || (p[0] == ver) || (p[0] == 'V')) camop='^';

// send UPPER case to sensorCAM to flag binary data from a DCCEX-CS parser
switch(paramCount) {
case 1: //<N ver> produces '^'
case 1: //<N ver> produces '^'
if((p[0] == ve) || (p[0] == ver) || (p[0] == 'V')) camop='^';
if (STRCHR_P((const char *)F("EFGMQRVW^"),camop) == nullptr) return false;
if (camop=='F') camop=']'; //<NF> for Reset/Finish webCAM.
if (camop=='Q') param3=10; //<NQ> for activation state of all 10 banks of sensors
break; // Coded as ']' else conflicts with <Nf %%>
if (camop=='F') camop=']'; //<NF> for Reset/Finish webCAM.
break; // F Coded as ']' else conflicts with <Nf %%>

case 2: //<N camop p1>
if (STRCHR_P((const char *)F("ABFILMNOPQRSTUV^"),camop)==nullptr) return false;
if (STRCHR_P((const char *)F("ABFILMNOPQRSTUV"),camop)==nullptr) return false;
param1=p[1];
break;

Expand All @@ -74,7 +75,7 @@ bool CamParser::parseN(Print * stream, byte paramCount, int16_t p[]) {
param3 = p[2];
break;

case 4: //<N a id row col>
case 4: //<N a id row col>
if (camop!='A') return false; //must start with 'a'
if (p[3]>316 || p[3]<0) return false;
if (p[2]>236 || p[2]<0) return false;
Expand Down
48 changes: 25 additions & 23 deletions IO_EXSensorCAM.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/
#define driverVer 304
#define driverVer 305
// v305 less debug & alpha ordered switch
// v304 static oldb0; t(##[,%%];
// v303 zipped with CS 5.2.76 and uploaded to repo (with debug)
// v302 SEND=StringFormatter::send; remove Sp(); + 'q'; memcpy( .8) -> .7);
// v302 SEND=StringFormatter::send, remove Sp(), add 'q', memcpy( .8) -> .7);
// v301 improved 'f','p'&'q' code and driver version calc. Correct bsNo calc. for 'a'
// v300 stripped & revised without expander functionality. Needs sensorCAM.h v300 AND CamParser.cpp
// v222 uses '@'for EXIORDD read. handles <NB $> and <NN $ ##>
Expand Down Expand Up @@ -222,17 +223,18 @@ int ioESP32(uint8_t i2cAddr,uint8_t *rBuf,int inbytes,uint8_t *outBuff,int outby
//rBuf contains packet of up to 32 bytes usually with (ascii) cmd header in rBuf[0]
//sensorCmd command header byte from CAM (in rBuf[0]?)
int processIncomingPkt(uint8_t *rBuf,uint8_t sensorCmd) {
static uint8_t oldb0; //for debug only
//static uint8_t oldb0; //for debug only
int k;
int b;
char str[] = "11111111";
// if (sensorCmd <= '~') DIAG(F("processIncomingPkt %c %d %d %d"),rBuf[0],rBuf[1],rBuf[2],rBuf[3]);
switch (sensorCmd){
case '`': //response to request for digitalInputStates[] table '@'=>'`'
memcpy(_digitalInputStates, rBuf+1, digitalBytesNeeded);
if ( _digitalInputStates[0]!=oldb0) { oldb0=_digitalInputStates[0]; //debug
// if ( _digitalInputStates[0]!=oldb0) { oldb0=_digitalInputStates[0]; //debug
// for (k=0;k<5;k++) {Serial.print(" ");Serial.print(_digitalInputStates[k],HEX);}
}break;
// }
break;

case EXIORDY: //some commands give back acknowledgement only
break;
Expand All @@ -241,11 +243,22 @@ static uint8_t oldb0; //for debug only
DIAG(F("CAM cmd error 0xFE 0x%x"),rBuf[1]);
break;

case '~': //information from '^' version request <N ve[r]>
case '~': //information from '^' version request <N v[er]>
DIAG(F("EX-SensorCAM device found, I2C:%s,CAM Version v%d.%d.%d vpins %u-%u"),
_I2CAddress.toString(), rBuf[1]/10, rBuf[1]%10, rBuf[2],(int) _firstVpin, (int) _firstVpin +_nPins-1);
DIAG(F("IO_EXSensorCAM driver v0.%d.%d vpin: %d "), driverVer/100,driverVer%100,_firstVpin);
break;

case 'f':
DIAG(F("(f %%%%) frame header 'f' for bsNo %d/%d - showing Quarter sample (1 row) only"), rBuf[1]/8,rBuf[1]%8);
SEND(&USB_SERIAL,F("<n row: %d Ref bytes: "),rBuf[2]);
for(k=3;k<15;k++)
SEND(&USB_SERIAL,F("%x%x%s"), rBuf[k]>>4, rBuf[k]&15, k%3==2 ? " " : " ");
Serial.print(" latest grab: ");
for(k=16;k<28;k++)
SEND(&USB_SERIAL,F("%x%x%s"), rBuf[k]>>4, rBuf[k]&15, (k%3==0) ? " " : " ");
Serial.print(" n>\n");
break;

case 'i': //information from i%%
k=256*rBuf[5]+rBuf[4];
Expand All @@ -255,30 +268,14 @@ static uint8_t oldb0; //for debug only

case 'm':
DIAG(F("(m$[,##]) Min/max: $ frames min2flip (trip) %d, maxSensors 0%o, minSensors 0%o, nLED %d,"
" threshold %d, TWOIMAGE_MAXBS 0%o"),rBuf[1],rBuf[3],rBuf[2],rBuf[4],rBuf[5],rBuf[6]);
" threshold %d, TWOIMAGE_MAXBS 0%o"),rBuf[1],rBuf[3],rBuf[2],rBuf[4],rBuf[5],rBuf[6]);
break;

case 'n':
DIAG(F("(n$[,##]) Nominate: $ nLED %d, ## minSensors 0%o (maxSensors 0%o threshold %d)")
,rBuf[4],rBuf[2],rBuf[3],rBuf[5]);
break;

case 'q':
for (int i =0; i<8; i++) str[i] = ((rBuf[2] << i) & 0x80 ? '1' : '0');
DIAG(F("(q $) Query bank %c ENABLED sensors(S%c7-%c0): %s "), rBuf[1], rBuf[1], rBuf[1], str);
break;

case 'f':
DIAG(F("(f %%%%) frame header 'f' for bsNo %d/%d - showing Quarter sample (1 row) only"), rBuf[1]/8,rBuf[1]%8);
SEND(&USB_SERIAL,F("<n row: %d Ref bytes: "),rBuf[2]);
for(k=3;k<15;k++)
SEND(&USB_SERIAL,F("%x%x%s"), rBuf[k]>>4, rBuf[k]&15, k%3==2 ? " " : " ");
Serial.print(" latest grab: ");
for(k=16;k<28;k++)
SEND(&USB_SERIAL,F("%x%x%s"), rBuf[k]>>4, rBuf[k]&15, (k%3==0) ? " " : " ");
Serial.print(" n>\n");
break;

case 'p':
b=rBuf[1]-2;
if(b<4) { Serial.print("<n (p%%) Bank empty n>\n"); break; }
Expand All @@ -288,6 +285,11 @@ static uint8_t oldb0; //for debug only
Serial.print(" n>\n");
break;

case 'q':
for (int i =0; i<8; i++) str[i] = ((rBuf[2] << i) & 0x80 ? '1' : '0');
DIAG(F("(q $) Query bank %c ENABLED sensors(S%c7-%c0): %s "), rBuf[1], rBuf[1], rBuf[1], str);
break;

case 't': //threshold etc. from t## //bad pkt if 't' FF's
if(rBuf[1]==0xFF) {Serial.println("<n bad CAM 't' packet: 74 FF n>");_savedCmd[2] +=1; return 0;}
SEND(&USB_SERIAL,F("<n (t[##[,%%%%]]) Threshold:%d sensor S00:-%d"),rBuf[1],min(rBuf[2]&0x7F,99));
Expand Down
32 changes: 12 additions & 20 deletions myHal.cpp_example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
// Include devices you need.
#include "IODevice.h"
//#include "IO_HALDisplay.h" // Auxiliary display devices (LCD/OLED)
//#include "IO_HCSR04.h" // Ultrasonic range sensor
//#include "IO_VL53L0X.h" // Laser time-of-flight sensor
//#include "IO_DFPlayer.h" // MP3 sound player
//#include "IO_HCSR04.h" // Ultrasonic range sensor
//#include "IO_VL53L0X.h" // Laser time-of-flight sensor
//#include "IO_DFPlayer.h" // MP3 sound player
//#include "IO_TouchKeypad.h // Touch keypad with 16 keys
//#include "IO_EXTurntable.h" // Turntable-EX turntable controller
//#include "IO_EXFastClock.h" // FastClock driver
//#include "IO_EXTurntable.h" // Turntable-EX turntable controller
//#include "IO_EXFastClock.h" // FastClock driver
//#include "IO_PCA9555.h" // 16-bit I/O expander (NXP & Texas Instruments).
//#include "IO_I2CDFPlayer.h" // DFPlayer over I2C
#include "IO_EXSensorCAM.h" // sensorCAM driver
Expand All @@ -36,7 +36,7 @@

void halSetup() {

I2CManager.setClock(100000);
// I2CManager.setClock(100000); //to set i2c bus clock rate

//=======================================================================
// The following directives define auxiliary display devices.
Expand Down Expand Up @@ -306,14 +306,7 @@ void halSetup() {
// Note that the I2C address is defined in the EX-IOExpander code, and 0x65 is the default.
// The example is for an Arduino Nano.



//EXIOExpander::create(800, 18, 0x65);







//=======================================================================
Expand Down Expand Up @@ -342,7 +335,7 @@ void halSetup() {


// EXFastClock::create(0x55);

//=======================================================================
// The following directive defines an ESP32-CAM instance.
//=======================================================================
Expand All @@ -353,12 +346,11 @@ void halSetup() {
// #define SENSORCAM_VPIN0 #00 in config.h if not using 700.
// Number of VPINs=pin count (must not exceed 80)
// I2C address=an available I2C address (default 0x11)
// #define ESP32CAP 0x13 in config.h to raise allowable ESP32 range of addresses
// Note that the I2C address (0x11) is the default in the sensorCAM code
//
// EXSensorCAM::create(700, 80, 0x11);
EXSensorCAM::create(700, 80, 0x11); //preference is now to use HAL(700 80 0x11) in myAutomation.h
//EXSensorCAM::create(600, 80, 0x12); //alternate or second CAM device address creation
}
// EXSensorCAM::create(700, 80, 0x11); //preference is now to use HAL(700 80 0x11) in myAutomation.h

//EXSensorCAM::create(600, 80, 0x12); //alternate or second CAM device address creation
//preference is now to use HAL(EXSensorCAM 700 80 0x11) in myAutomation.h rather than :create
}

#endif

0 comments on commit 431db07

Please sign in to comment.