遥菜 井野 / Mbed 2 deprecated camera

Dependencies:   TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers camera.cpp Source File

camera.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003   
00004 TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7
00005 
00006  
00007 Serial pc(USBTX, USBRX); // tx, rx
00008 Serial device(p9, p10);  // tx, rx
00009 
00010 char buf[] = "hello";
00011 char reset[] = {0x56, 0x00, 0x26, 0x00};
00012 int i_buf = 0;
00013 int i_reset = 0;
00014 
00015 void pc_rx () {
00016     char c = pc.getc();
00017     device.putc(c);
00018     lcd.putc(c);
00019 }
00020  
00021 void dev_rx () {
00022     char c = device.getc();
00023     pc.putc(c);
00024     lcd.putc(c);
00025 }
00026  
00027 void pc_tx () {
00028     pc.putc(buf[i_buf]);
00029     i_buf++;
00030     if (i_buf >= sizeof buf) {
00031        pc.attach(NULL, Serial::TxIrq);
00032     }
00033 }
00034  
00035 void device_tx () {
00036     device.putc(reset[i_reset]);
00037     i_reset++;
00038     lcd.putc('-');
00039     if (i_reset >= sizeof(reset)) {
00040        device.attach(NULL, Serial::TxIrq);
00041     }
00042 }
00043 
00044 int main() {
00045     device.baud(38400);
00046     //pc.baud(9600);
00047 
00048     pc.attach(pc_rx, Serial::RxIrq);
00049     //pc.attach(pc_tx, Serial::TxIrq);
00050 
00051     device.attach(dev_rx, Serial::RxIrq);
00052     device.attach(device_tx, Serial::TxIrq);
00053     
00054     //lcd.putc('m');
00055     //pc.putc('m');
00056     device.putc('!');
00057     pc.readable();
00058     device.readable();
00059     wait(2.0);
00060     lcd.printf("OK!\n");
00061     while(1);
00062 }