Shundo Kishi / Mbed 2 deprecated Hobby_Humanoid_controlor

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

Committer:
syundo0730
Date:
Wed Feb 27 12:32:44 2013 +0000
Revision:
16:e65c192b7ecf
Parent:
14:522bb06f0f0d
Child:
17:60de3bfdc70b
ROBO-ONE 22th version

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 16:e65c192b7ecf 15 char SCI::getheader()
syundo0730 16:e65c192b7ecf 16 {
syundo0730 16:e65c192b7ecf 17 char comm = getc_nowait();
syundo0730 16:e65c192b7ecf 18 if (comm != 0x00) {
syundo0730 16:e65c192b7ecf 19 serial->putc(comm);
syundo0730 16:e65c192b7ecf 20 }
syundo0730 16:e65c192b7ecf 21 return comm;
syundo0730 16:e65c192b7ecf 22 }
syundo0730 16:e65c192b7ecf 23
syundo0730 13:711f74b2fa33 24 int SCI::getid()
syundo0730 12:6cd135bf03bd 25 {
syundo0730 13:711f74b2fa33 26 int id = 255;
syundo0730 16:e65c192b7ecf 27 stringstream sstr;
syundo0730 16:e65c192b7ecf 28 sstr << getc_wait();
syundo0730 16:e65c192b7ecf 29 sstr >> id;
syundo0730 16:e65c192b7ecf 30 serial->printf("id = %d \r\n", id);
syundo0730 16:e65c192b7ecf 31 return id;
syundo0730 16:e65c192b7ecf 32 }
syundo0730 16:e65c192b7ecf 33
syundo0730 16:e65c192b7ecf 34 uint16_t SCI::getservoval()
syundo0730 16:e65c192b7ecf 35 {
syundo0730 16:e65c192b7ecf 36 uint16_t val = 1500;
syundo0730 16:e65c192b7ecf 37 stringstream sstr;
syundo0730 16:e65c192b7ecf 38 while (!serial->readable());
syundo0730 16:e65c192b7ecf 39 for (int i = 0; i < 4; ++i) {
syundo0730 13:711f74b2fa33 40 sstr << getc_wait();
syundo0730 12:6cd135bf03bd 41 }
syundo0730 16:e65c192b7ecf 42 sstr >> val;
syundo0730 16:e65c192b7ecf 43 serial->printf("val:%d", val);
syundo0730 16:e65c192b7ecf 44 serial->printf("\r\n");
syundo0730 16:e65c192b7ecf 45 return val;
syundo0730 12:6cd135bf03bd 46 }
syundo0730 12:6cd135bf03bd 47
syundo0730 12:6cd135bf03bd 48 char SCI::getc_wait()
syundo0730 12:6cd135bf03bd 49 {
syundo0730 16:e65c192b7ecf 50 while (!serial->readable());
syundo0730 13:711f74b2fa33 51 char val = serial->getc();
syundo0730 13:711f74b2fa33 52 return val;
syundo0730 12:6cd135bf03bd 53 }
syundo0730 12:6cd135bf03bd 54
syundo0730 12:6cd135bf03bd 55 char SCI::getc_nowait()
syundo0730 12:6cd135bf03bd 56 {
syundo0730 12:6cd135bf03bd 57 uint8_t buf = 0;
syundo0730 12:6cd135bf03bd 58 if (serial->readable()) {
syundo0730 12:6cd135bf03bd 59 buf = serial->getc();
syundo0730 12:6cd135bf03bd 60 }
syundo0730 12:6cd135bf03bd 61 return buf;
syundo0730 12:6cd135bf03bd 62 }
syundo0730 12:6cd135bf03bd 63
syundo0730 13:711f74b2fa33 64 void SCI::printf(char* str)
syundo0730 13:711f74b2fa33 65 {
syundo0730 13:711f74b2fa33 66 serial->printf(str);
syundo0730 13:711f74b2fa33 67 }
syundo0730 13:711f74b2fa33 68
syundo0730 16:e65c192b7ecf 69 /*uint16_t SCI::readint()
syundo0730 12:6cd135bf03bd 70 {
syundo0730 16:e65c192b7ecf 71 uint8_t buff[2];
syundo0730 16:e65c192b7ecf 72 buff[0] = getc_wait();
syundo0730 16:e65c192b7ecf 73 buff[1] = getc_wait();
syundo0730 12:6cd135bf03bd 74 uint16_t val;
syundo0730 12:6cd135bf03bd 75 val = (uint16_t)(buff[1] << 8) | (uint16_t)buff[0];
syundo0730 12:6cd135bf03bd 76 return val;
syundo0730 16:e65c192b7ecf 77 }*/
syundo0730 12:6cd135bf03bd 78
syundo0730 16:e65c192b7ecf 79 /*void sendint(uint16_t val)
syundo0730 12:6cd135bf03bd 80 {
syundo0730 12:6cd135bf03bd 81 uint8_t buff[16];
syundo0730 12:6cd135bf03bd 82 buff[0] = (uint8_t)(val & 0x00FF);
syundo0730 12:6cd135bf03bd 83 buff[1] = (uint8_t)(val >> 8);
syundo0730 12:6cd135bf03bd 84 pc.putc(buff[0]);
syundo0730 12:6cd135bf03bd 85 pc.putc(buff[1]);
syundo0730 12:6cd135bf03bd 86 }*/