Skip to content

Commit 1a81ab0

Browse files
committed
it works but not ack
1 parent 1a93c2d commit 1a81ab0

5 files changed

Lines changed: 29 additions & 31 deletions

File tree

src/PelcoBus.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <SoftwareSerial.h>
1616

1717
#include "Arduino.h"
18-
#include "constants.h"
18+
1919
#include "PelcoBus.h"
2020

2121
/*!
@@ -30,10 +30,6 @@
3030
*
3131
*/
3232

33-
PelcoBus::PelcoBus() {
34-
return;
35-
}
36-
3733
PelcoBus::PelcoBus(uint8_t txPin, uint8_t rxPin, uint8_t readEnPin) {
3834
txPin_ = txPin;
3935
rxPin_ = rxPin;
@@ -161,6 +157,10 @@ bool PelcoBus::command(uint8_t address, bool disableACK , uint8_t command, uint1
161157

162158
(*SerialCamBus).write(messToCamera, sizeof(messToCamera)); // Write to the camera
163159

160+
161+
///////////////////////////////////
162+
163+
164164
if ((!disableACK) && (!disableACK)) { // Check the response of the camera only if it isn't a request or the camera does not support return
165165
int timeout = 10000; // 10 millissecond wait
166166

src/PelcoBus.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,20 @@ class PelcoBus{
5656
int searchIndex(byte look_array[], byte value, size_t size);
5757
int searchIndexPROGMEM(const byte look_array[], byte value);
5858

59-
60-
protected:
61-
PelcoBus::PelcoBus();
62-
6359
uint16_t txPin_;
6460
uint16_t rxPin_;
6561
uint16_t rePin_;
6662

67-
bool log_messages_;
68-
char log_buffer[100];
69-
70-
bool command(uint8_t address, bool disableACK , uint8_t command, uint16_t data1 = 0x00, uint8_t data2 = 0x00);
71-
uint16_t request(uint8_t address, uint8_t request, int timeout = 1000);
63+
64+
bool log_messages_;
65+
char log_buffer[100];
7266

7367
public:
68+
7469
PelcoBus(uint8_t txPin, uint8_t rxPin, uint8_t readEnPin = NOT_A_PIN);
75-
70+
71+
bool command(uint8_t address, bool disableACK , uint8_t command, uint16_t data1 = 0x00, uint8_t data2 = 0x00);
72+
uint16_t request(uint8_t address, uint8_t request, int timeout = 1000);
7673

7774
void begin(uint32_t config, bool log_messages = false);
7875

src/PelcoCam.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
#include <SoftwareSerial.h>
1414

1515
#include "Arduino.h"
16-
#include "constants.h"
1716

17+
#include "constants.h"
1818
#include "PelcoCam.h"
1919

20+
2021
// Only serves as a wrapper for the PelcoBus class
2122

22-
PelcoCam::PelcoCam(uint8_t address, bool disable_ack): PelcoBus(PelcoBus::rxPin_, PelcoBus::txPin_, PelcoBus::rePin_){
23+
PelcoCam::PelcoCam(PelcoBus *bus, uint8_t address, bool disable_ack = false){
24+
bus_ = bus; //Get the address (pointer) of the PelcoBus class
2325
address_ = address;
2426
disable_ack_ = disable_ack;
2527
}
@@ -34,17 +36,12 @@ bool PelcoCam::available() { // Returns true if there's a ACK
3436
}
3537
return false;
3638
}
37-
return PelcoBus::command(address_, disable_ack_, DUMMY);
39+
return bus_->command(address_, disable_ack_, DUMMY);
3840

3941
}
4042

41-
bool PelcoCam::send_command(uint8_t command, uint16_t data1 = 0x00, uint8_t data2 = 0x00) {
42-
Serial.print("ah");
43-
Serial.print(log_buffer);
44-
delay(1000);
45-
Serial.println("bbbb");
46-
bool test = PelcoBus::command(address_, disable_ack_, command, data1, data2);
47-
return test;
43+
bool PelcoCam::send_command(uint8_t command=STOP, uint16_t data1 = 0x00, uint8_t data2 = 0x00) {
44+
return bus_->command(address_, disable_ack_, command, data1, data2);
4845
}
4946

5047
uint16_t PelcoCam::send_request(uint8_t request, uint16_t timeout = 1000) {
@@ -58,5 +55,5 @@ uint16_t PelcoCam::send_request(uint8_t request, uint16_t timeout = 1000) {
5855
return 0;
5956
}
6057

61-
return PelcoBus::request(address_, request, timeout);
58+
return bus_->request(address_, request, timeout);
6259
}

src/PelcoCam.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@
1313
#include <SoftwareSerial.h>
1414

1515
#include "Arduino.h"
16-
#include "constants.h"
17-
16+
1817
#include "PelcoBus.h"
1918

20-
class PelcoCam: public PelcoBus{
19+
20+
class PelcoCam{
2121
private:
2222
uint8_t address_;
2323
bool disable_ack_;
24+
PelcoBus *bus_;
25+
26+
bool log_messages_;
27+
char log_buffer[100];
28+
2429

2530
public:
26-
PelcoCam(uint8_t address, bool disable_ack = false);
31+
PelcoCam(PelcoBus *bus, uint8_t address, bool disable_ack = false);
2732

2833
bool available();
2934

src/Pelco_And_Arduino.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@
2424

2525

2626

27-
2827
#endif

0 commit comments

Comments
 (0)