dd
Dependencies: BufferedSerial FastAnalogIn FastPWM mbed SHT75
Diff: commandt.cpp
- Revision:
- 0:9bfc4aea91e2
- Child:
- 1:5c42ec7f1aeb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commandt.cpp Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,116 @@ +/* + * commandt.cpp + * + * Created on: 2016. 2. 19. + * Author: sbh9428 + */ + +#include "commandt.h" + +command_t::command_t() { + // TODO Auto-generated constructor stub + +} + +command_t::command_t(BufferedSerial* _pc, control_t* _control) +{ + count=0; + control=_control; + pc=_pc; + pc->baud(115200); +} + +command_t::~command_t() { + // TODO Auto-generated destructor stub +} + +void command_t::clear_data() +{ + for(int i=0;i<10;i++) + { + data[i]=0; + } +} +void command_t::parse() +{ + switch(data[0]) + { + case 's': + switch(data[1]) + { + case 'm': + control->set_mode(data[2]-'0'); + break; + case 'p': + control->control_PWM(asci_to_bin(data+2)); + printf("set WPM duty ratio %f\n", asci_to_bin(data+2)); + break; + case 't': + + break; + } + break; + case 'g': + + break; + dafault: + pc->printf("command error"); + } + pc->printf("\n"); +} + +void command_t::get_data() +{ + data [count]=pc->getc(); + + if(data [count]=='f') + parse(); + else + count++; + + if(count>9) + { + count=0; + pc->printf("command error\n"); + } +} + +void command_t::refreshPWM() +{ + printf("temperature is %f\n", control->get_temp()); + +} + +double command_t::asci_to_bin(int *start) +{ + double _data=0; + int current=0; + + double nth=1; //�ڸ��� + int mode=0; + int sign=1; + + if(*start=='-') + { + current++; + sign=-1; + } + while(*(start+current)!='f'&&*(start+current)!='.') + { + _data*=10; + _data+=*(start+current)-'0'; + + current++; + } + if(*(start+current)=='.') + { + current++; + while(*(start+current)!='f') + { + nth/=10; + _data+=nth*(*(start+current)-'0'); + current++; + } + } + return sign*_data; +} \ No newline at end of file