/**
パソコンからgあるいはGで撮影開始。
ppmフォーマットのテキストデータをパソコン側に送る。
受け取りはteraterm等で受け取り、拡張子をppmとする。
カメラ: p13: 緑色 p14:黄色
Vdd=3.3V
画像の大きさは80×60(1/4scale)
*/
#include "mbed.h"
#include "CameraC1098.h"
#include "tjpgd.h"
#include "externs.h"
#define S115200
#define SCALE 2 /* Output scaling 0:1/1, 1:1/2, 2:1/4 or 3:1/8 */
Serial pc(USBTX, USBRX); // tx, rx
JRESULT rc;
JDEC jd; // Decompression object (70 bytes)
/*
* Modules.
*/
#ifdef S115200
CameraC1098 camera(p13, p14, CameraC1098::baud115200);
#else
CameraC1098 camera(p13, p14, CameraC1098::baud57600);
#endif
/**
* A entry point.
*/
int main() {
char x;
// pc.baud(230400);
pc.baud(115200);
const size_t sz_work = 4096;
UINT xs, ys;
DWORD xb;
work = malloc(sz_work);
sync();
while(true)
{
do{
x = pc.getc();
if(x=='R') camera.sendReset(true);
} while(!(x=='g' || x=='G'));
led1=1;
sync();
pc.printf("%c",x); // Acknowledge
led2=1;
jpeg_snapshot_picture();
led3=1;
jd.width=0; jd.height=0;
rc = jd_prepare(&jd, tjd_input, work, sz_work, 0);
xs = jd.width >> SCALE; // Output size
ys = jd.height >> SCALE;
xb = ((DWORD)xs * 3 + 3) & ~3; // Byte width of the frame buffer
rc = jd_decomp(&jd, output_func, SCALE);
led4=1;
pc.printf("P3\n%d %d\n255\n",xs, ys);
for(int i=0 ; i<ys; i++)
{
for(int j=0; j<xs; j++) {
pc.printf("%d %d %d\n", picture[i][j*3],
picture[i][j*3+1],
picture[i][j*3+2] );
}
}
led1=0;
led2=0;
led3=0;
led4=0;
camera.sendReset(0xff);
}
return 0;
}
|