Shundo Kishi / Mbed 2 deprecated Hobby_Humanoid_controlor

Dependencies:   Adafruit-PWM-Servo-Driver MPU6050 RS300 mbed

Committer:
syundo0730
Date:
Sun Feb 03 21:22:21 2013 +0000
Revision:
13:711f74b2fa33
Parent:
12:6cd135bf03bd
Child:
14:522bb06f0f0d
play motion by signal from serial port

Who changed what in which revision?

UserRevisionLine numberNew contents of line
syundo0730 12:6cd135bf03bd 1 #include "mbed.h"
syundo0730 12:6cd135bf03bd 2 #include "SCI.h"
syundo0730 13:711f74b2fa33 3 #include <sstream>
syundo0730 12:6cd135bf03bd 4
syundo0730 12:6cd135bf03bd 5 SCI::SCI(PinName tx, PinName rx)
syundo0730 12:6cd135bf03bd 6 {
syundo0730 12:6cd135bf03bd 7 serial = new Serial(tx, rx);
syundo0730 12:6cd135bf03bd 8 }
syundo0730 12:6cd135bf03bd 9
syundo0730 12:6cd135bf03bd 10 SCI::~SCI()
syundo0730 12:6cd135bf03bd 11 {
syundo0730 12:6cd135bf03bd 12 delete serial;
syundo0730 12:6cd135bf03bd 13 }
syundo0730 12:6cd135bf03bd 14
syundo0730 13:711f74b2fa33 15 int SCI::getid()
syundo0730 12:6cd135bf03bd 16 {
syundo0730 13:711f74b2fa33 17 char comm;
syundo0730 13:711f74b2fa33 18 int id = 255;
syundo0730 12:6cd135bf03bd 19 comm = getc_nowait();
syundo0730 12:6cd135bf03bd 20 if (comm == 'A') {
syundo0730 12:6cd135bf03bd 21 serial->putc(comm);
syundo0730 13:711f74b2fa33 22 stringstream sstr;
syundo0730 13:711f74b2fa33 23 sstr << getc_wait();
syundo0730 13:711f74b2fa33 24 sstr >> id;
syundo0730 13:711f74b2fa33 25 serial->printf("id = %d \r\n", id);
syundo0730 12:6cd135bf03bd 26 }
syundo0730 12:6cd135bf03bd 27 return id;
syundo0730 12:6cd135bf03bd 28 }
syundo0730 12:6cd135bf03bd 29
syundo0730 12:6cd135bf03bd 30 char SCI::getc_wait()
syundo0730 12:6cd135bf03bd 31 {
syundo0730 12:6cd135bf03bd 32 while (!serial->readable()) {
syundo0730 13:711f74b2fa33 33 //serial->printf("waiting..");
syundo0730 12:6cd135bf03bd 34 }
syundo0730 13:711f74b2fa33 35 char val = serial->getc();
syundo0730 13:711f74b2fa33 36 return val;
syundo0730 12:6cd135bf03bd 37 }
syundo0730 12:6cd135bf03bd 38
syundo0730 12:6cd135bf03bd 39 char SCI::getc_nowait()
syundo0730 12:6cd135bf03bd 40 {
syundo0730 12:6cd135bf03bd 41 uint8_t buf = 0;
syundo0730 12:6cd135bf03bd 42 if (serial->readable()) {
syundo0730 12:6cd135bf03bd 43 buf = serial->getc();
syundo0730 12:6cd135bf03bd 44 }
syundo0730 12:6cd135bf03bd 45 return buf;
syundo0730 12:6cd135bf03bd 46 }
syundo0730 12:6cd135bf03bd 47
syundo0730 13:711f74b2fa33 48 void SCI::printf(char* str)
syundo0730 13:711f74b2fa33 49 {
syundo0730 13:711f74b2fa33 50 serial->printf(str);
syundo0730 13:711f74b2fa33 51 }
syundo0730 13:711f74b2fa33 52
syundo0730 12:6cd135bf03bd 53 /*uint16_t readint(void)
syundo0730 12:6cd135bf03bd 54 {
syundo0730 12:6cd135bf03bd 55 uint8_t buff[16];
syundo0730 12:6cd135bf03bd 56 buff[0] = pc->getc();
syundo0730 12:6cd135bf03bd 57 buff[1] = pc->getc();
syundo0730 12:6cd135bf03bd 58 uint16_t val;
syundo0730 12:6cd135bf03bd 59 val = (uint16_t)(buff[1] << 8) | (uint16_t)buff[0];
syundo0730 12:6cd135bf03bd 60 return val;
syundo0730 12:6cd135bf03bd 61 }
syundo0730 12:6cd135bf03bd 62
syundo0730 12:6cd135bf03bd 63 void sendint(uint16_t val)
syundo0730 12:6cd135bf03bd 64 {
syundo0730 12:6cd135bf03bd 65 uint8_t buff[16];
syundo0730 12:6cd135bf03bd 66 buff[0] = (uint8_t)(val & 0x00FF);
syundo0730 12:6cd135bf03bd 67 buff[1] = (uint8_t)(val >> 8);
syundo0730 12:6cd135bf03bd 68 pc.putc(buff[0]);
syundo0730 12:6cd135bf03bd 69 pc.putc(buff[1]);
syundo0730 12:6cd135bf03bd 70 }*/