Skip to content

Commit

Permalink
Modify the low power mode to adapt to the new version of GUI software
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-ard authored and ArduCAM committed Dec 1, 2023
1 parent 700673d commit c2370c4
Show file tree
Hide file tree
Showing 25 changed files with 1,432 additions and 1,291 deletions.
352 changes: 183 additions & 169 deletions examples/ArduinoDue/full_featured/ArducamLink.cpp

Large diffs are not rendered by default.

68 changes: 34 additions & 34 deletions examples/ArduinoDue/full_featured/ArducamLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,54 @@
#include "Arducam_Mega.h"
#include "stdint.h"

#define RESET_CAMERA 0XFF
#define SET_PICTURE_RESOLUTION 0X01
#define SET_VIDEO_RESOLUTION 0X02
#define SET_BRIGHTNESS 0X03
#define SET_CONTRAST 0X04
#define SET_SATURATION 0X05
#define SET_EV 0X06
#define SET_WHITEBALANCE 0X07
#define SET_SPECIAL_EFFECTS 0X08
#define SET_FOCUS_CONTROL 0X09
#define SET_EXPOSUREANDGAIN_CONTROL 0X0A
// #define SET_GAIN_CONTROL 0X0B
#define SET_WHILEBALANCE_CONTROL 0X0C
#define SET_MANUAL_GAIN 0X0D
#define SET_MANUAL_EXPOSURE 0X0E
#define GET_CAMERA_INFO 0X0F
#define TAKE_PICTURE 0X10
#define SET_SHARPNESS 0X11
#define DEBUG_WRITE_REGISTER 0X12
#define STOP_STREAM 0X21
#define GET_FRM_VER_INFO 0X30
#define GET_SDK_VER_INFO 0X40
#define SET_IMAGE_QUALITY 0X50

#define SET_PICTURE_RESOLUTION 0X01
#define SET_VIDEO_RESOLUTION 0X02
#define SET_BRIGHTNESS 0X03
#define SET_CONTRAST 0X04
#define SET_SATURATION 0X05
#define SET_EV 0X06
#define SET_WHITEBALANCE 0X07
#define SET_SPECIAL_EFFECTS 0X08
#define SET_FOCUS_CONTROL 0X09
#define SET_EXPOSURE_CONTROL 0X0A
#define SET_GAIN_CONTROL 0X0B
#define SET_WHILEBALANCE_CONTROL 0X0C
#define SET_MANUAL_GAIN 0X0D
#define SET_MANUAL_EXPOSURE 0X0E
#define GET_CAMERA_INFO 0X0F
#define TAKE_PICTURE 0X10
#define SET_SHARPNESS 0X11
#define DEBUG_WRITE_REGISTER 0X12
#define STOP_STREAM 0X21
#define GET_FRM_VER_INFO 0X30
#define GET_SDK_VER_INFO 0X40
#define READ_IMAGE_LENGTH 255
#define READ_IMAGE_LENGTH 255

class ArducamLink
{
private:
/* data */
public:
public:
uint8_t uartCommandProcessing(Arducam_Mega*, uint8_t*);

public:
ArducamLink();
~ArducamLink();
void arducamUartBegin(uint32_t);
uint8_t uartCommandProcessing(Arducam_Mega*,uint8_t*);
void reportCameraInfo(Arducam_Mega*);
void reportVerInfo(Arducam_Mega* myCamera);
void reportSdkVerInfo(Arducam_Mega* myCamera);
void cameraGetPicture(Arducam_Mega*);
void arducamFlush(void);
void send_data_pack(char cmd_type, char* msg);

public:
void printf(char* buff);
void arducamUartWrite(uint8_t);
void arducamUartWriteBuff(uint8_t*,uint8_t);
void arducamUartWriteBuff(uint8_t*, uint16_t);
uint32_t arducamUartAvailable(void);
uint8_t arducamUartRead(void);
void arducamFlush(void);
};







#endif /*__ARDUCAMLINK_H*/
12 changes: 12 additions & 0 deletions examples/ArduinoDue/full_featured/ArducamUart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __ARDUCAM_SLOT_H
#define __ARDUCAM_SLOT_H
#include <Arduino.h>

#define SerialBegin(baudRate) Serial.begin(baudRate)
#define SerialWrite(ch) Serial.write(ch)
#define SerialWriteBuff(buf, len) Serial.write(buf, len)
#define SerialPrintf(str) Serial.print(str)
#define SerialAvailable() Serial.available()
#define SerialRead() Serial.read()
#define delayUs(us) delayMicroseconds(us)
#endif
189 changes: 68 additions & 121 deletions examples/ArduinoDue/full_featured/full_featured.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,142 +6,89 @@
// This demo was made for ArduCAM Spi Camera.
// It needs to be used in combination with PC software.
// It can test ArduCAM Spi Camerafunctions
#include "Arducam_Mega.h"
// #include "Platform.h"
#include "ArducamLink.h"

#include "Arducam_Mega.h"
const int CS = 7;
Arducam_Mega myCAM(CS);
ArducamLink myUart;
uint8_t temp = 0xff;
uint8_t sendFlag = TRUE;
uint8_t commandBuff[20] = { 0 };
uint8_t commandLength = 0;
uint8_t temp = 0xff;
uint8_t sendFlag = TRUE;
uint8_t commandBuff[20] = {0};
uint8_t commandLength = 0;
uint32_t readImageLength = 0;
uint8_t jpegHeadFlag = 0;
uint8_t readBuffer(uint8_t* imagebuf, uint8_t length) {
CamStatus state;
uint16_t gainValue = 0;
uint32_t exposureValue = 0;
uint32_t exposureLen1 = 0;
uint32_t exposureLen2 = 0;
uint32_t exposureLen3 = 0;
if (myUart.arducamUartAvailable()) {
temp = myUart.arducamUartRead();
arducamDelayMs(1);
if (temp == 0x55) {
while (myUart.arducamUartAvailable()) {
commandBuff[commandLength] = myUart.arducamUartRead();
if (commandBuff[commandLength] == 0xAA) {
break;
}
commandLength++;
}
if (commandBuff[0] == 0x21) {
uint8_t jpegHeadFlag = 0;
uint8_t readBuffer(uint8_t* imagebuf, uint8_t length)
{
if (imagebuf[0] == 0xff && imagebuf[1] == 0xd8) {
jpegHeadFlag = 1;
readImageLength = 0;
myUart.arducamUartWrite(0xff);
myUart.arducamUartWrite(0xAA);
myUart.arducamUartWrite(0x01);

myUart.arducamUartWrite((uint8_t)(myCAM.getTotalLength() & 0xff));
myUart.arducamUartWrite((uint8_t)((myCAM.getTotalLength() >> 8) & 0xff));
myUart.arducamUartWrite((uint8_t)((myCAM.getTotalLength() >> 16) & 0xff));
myUart.arducamUartWrite((uint8_t)((myCAM.getTotalLength() >> 24) & 0xff));
myUart.arducamUartWrite(((CAM_IMAGE_PIX_FMT_JPG & 0x0f) << 4) | 0x01);
}
if (jpegHeadFlag == 1) {
readImageLength += length;
for (uint8_t i = 0; i < length; i++) {
myUart.arducamUartWrite(imagebuf[i]);
}
}
if (readImageLength == myCAM.getTotalLength()) {
jpegHeadFlag = 0;
myUart.arducamUartWrite(0x55);
myUart.arducamUartWrite(0xff);
myUart.arducamUartWrite(0xBB);
return FALSE;
}
switch (commandBuff[0]) {
case SET_BRIGHTNESS: //Set brightness
myCAM.setBrightness((CAM_BRIGHTNESS_LEVEL)commandBuff[1]);
break;
case SET_CONTRAST: //Set Contrast
myCAM.setContrast((CAM_CONTRAST_LEVEL)commandBuff[1]);
break;
case SET_SATURATION: //Set saturation
myCAM.setSaturation((CAM_STAURATION_LEVEL)commandBuff[1]);
break;
case SET_EV: //Set EV
myCAM.setEV((CAM_EV_LEVEL)commandBuff[1]);
break;
case SET_WHITEBALANCE: //Set White balance
myCAM.setAutoWhiteBalanceMode((CAM_WHITE_BALANCE)commandBuff[1]);
break;
case SET_SPECIAL_EFFECTS: //Set Special effects
myCAM.setColorEffect((CAM_COLOR_FX)commandBuff[1]);
break;
case SET_FOCUS_CONTROL: //Focus Control
myCAM.setAutoFocus(commandBuff[1]);
if (commandBuff[1] == 0) {
myCAM.setAutoFocus(0x02);
}
break;
case SET_EXPOSURE_CONTROL: //exposure control
myCAM.setAutoExposure(commandBuff[1] & 0x01);
break;
case SET_GAIN_CONTROL: //Gain control
myCAM.setAutoISOSensitive(commandBuff[1] & 0x01);
break;
case SET_WHILEBALANCE_CONTROL: //while balance control
myCAM.setAutoWhiteBalance(commandBuff[1] & 0x01);
break;
case SET_SHARPNESS:
myCAM.setSharpness((CAM_SHARPNESS_LEVEL)commandBuff[1]);
break;
case SET_MANUAL_GAIN: //manual gain control
gainValue = (commandBuff[1] << 8) | commandBuff[2];
myCAM.setISOSensitivity(gainValue);
break;
case SET_MANUAL_EXPOSURE: //manual exposure control
exposureLen1 = commandBuff[1];
exposureLen2 = commandBuff[2];
exposureLen3 = commandBuff[3];
exposureValue = (exposureLen1 << 16) | (exposureLen2 << 8) | exposureLen3;
myCAM.setAbsoluteExposure(exposureValue);
break;
}
commandLength = 0;
}
}
if (imagebuf[0] == 0xff && imagebuf[1] == 0xd8) {
jpegHeadFlag = 1;
myUart.arducamUartWrite(0x55);
myUart.arducamUartWrite(0xAA);
myUart.arducamUartWrite(CAM_IMAGE_PIX_FMT_JPG);
myUart.arducamUartWrite((uint8_t)(myCAM.getTotalLength() & 0xff));
myUart.arducamUartWrite((uint8_t)((myCAM.getTotalLength() >> 8) & 0xff));
myUart.arducamUartWrite((uint8_t)((myCAM.getTotalLength() >> 16) & 0xff));
myUart.arducamUartWrite((uint8_t)((myCAM.getTotalLength() >> 24) & 0xff));
}
if (jpegHeadFlag == 1) {
readImageLength += length;
for (uint8_t i = 0; i < length; i++) {
myUart.arducamUartWrite(imagebuf[i]);
}
}
if (readImageLength == myCAM.getTotalLength()) {
return sendFlag;
}

void stop_preivew()
{
readImageLength = 0;
jpegHeadFlag = 0;
myUart.arducamUartWrite(0x55);
jpegHeadFlag = 0;
uint32_t len = 9;

myUart.arducamUartWrite(0xff);
myUart.arducamUartWrite(0xBB);
myUart.arducamUartWrite(0xff);
myUart.arducamUartWrite(0xAA);
myUart.arducamUartWrite(0x06);
myUart.arducamUartWriteBuff((uint8_t*)&len, 4);
myUart.printf("streamoff");
myUart.arducamUartWrite(0xff);
myUart.arducamUartWrite(0xBB);
}
return sendFlag;
}

void setup() {
myUart.arducamUartBegin(115200);
myCAM.begin();
myCAM.registerCallBack(readBuffer, 200);
void setup()
{
myUart.arducamUartBegin(115200);
myUart.send_data_pack(7, "Hello Arduino Due!");
myCAM.begin();
myUart.send_data_pack(8, "Mega start!");
myCAM.registerCallBack(readBuffer, 200, stop_preivew);
}

void loop() {
if (myUart.arducamUartAvailable()) {
temp = myUart.arducamUartRead();
arducamDelayMs(5);
if (temp == 0x55) {
while (myUart.arducamUartAvailable()) {
commandBuff[commandLength] = myUart.arducamUartRead();
if (commandBuff[commandLength] == 0xAA) {
break;
void loop()
{
if (myUart.arducamUartAvailable()) {
temp = myUart.arducamUartRead();
delay(5);
if (temp == 0x55) {
while (myUart.arducamUartAvailable()) {
commandBuff[commandLength] = myUart.arducamUartRead();
if (commandBuff[commandLength] == 0xAA) {
break;
}
commandLength++;
}
myUart.arducamFlush();
myUart.uartCommandProcessing(&myCAM, commandBuff);
commandLength = 0;
}
commandLength++;
}
myUart.arducamFlush();
myUart.uartCommandProcessing(&myCAM, commandBuff);
commandLength = 0;
}
}
myCAM.captureThread();
}
Loading

0 comments on commit c2370c4

Please sign in to comment.