Skip to content

Commit 70c3d04

Browse files
facchinmpennam
authored andcommitted
Camera: don't bail out on first i2c device found
1 parent 0f5443a commit 70c3d04

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

libraries/Camera/src/camera.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -408,21 +408,22 @@ int Camera::reset()
408408
return 0;
409409
}
410410

411-
int Camera::probeSensor()
411+
ScanResults<uint8_t> Camera::i2cScan()
412412
{
413413
uint8_t addr;
414+
ScanResults<uint8_t> res;
414415

415416
for (addr=1; addr<127; addr++) {
416417
CameraWire.beginTransmission(addr);
417418
if (CameraWire.endTransmission() == 0) {
418-
break;
419+
res.push(addr);
419420
}
420421
}
421422
if (_debug) {
422423
_debug->print("Sensor address: 0x");
423424
_debug->println(addr, HEX);
424425
}
425-
return addr;
426+
return res;
426427
}
427428

428429
bool Camera::begin(int32_t resolution, int32_t pixformat, int32_t framerate)
@@ -445,10 +446,13 @@ bool Camera::begin(int32_t resolution, int32_t pixformat, int32_t framerate)
445446
}
446447

447448
if (this->sensor->init() != 0) {
449+
if (_debug) {
450+
_debug->print("Sensor init failed");
451+
}
448452
return false;
449453
}
450454

451-
if (probeSensor() != this->sensor->getID()) {
455+
if (i2cScan() != this->sensor->getID()) {
452456
if (_debug) {
453457
_debug->print("Detected SensorID: 0x");
454458
_debug->println(this->sensor->getID(), HEX);

libraries/Camera/src/camera.h

+22-1
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,35 @@ class ImageSensor {
8888
}
8989
};
9090

91+
template <typename T> class ScanResults {
92+
public:
93+
bool operator==(T toBeFound) {
94+
for (int i = 0; i < howMany; i++) {
95+
if (toBeFound == data[i]) {
96+
return true;
97+
}
98+
}
99+
return false;
100+
}
101+
bool operator!=(T toBeFound) {
102+
return !(*this == toBeFound);
103+
}
104+
void push(T obj) {
105+
data[howMany++] = obj;
106+
}
107+
private:
108+
T data[20];
109+
int howMany = 0;
110+
};
111+
91112
class Camera {
92113
private:
93114
int32_t pixformat;
94115
int32_t resolution;
95116
int32_t framerate;
96117
ImageSensor *sensor;
97118
int reset();
98-
int probeSensor();
119+
ScanResults<uint8_t> i2cScan();
99120
Stream *_debug;
100121
arduino::MbedI2C *_i2c;
101122
FrameBuffer *_framebuffer;

0 commit comments

Comments
 (0)