Minecraft extension
Dependencies: NySDFileSystem libMiMic mbed-rtos mbed registers
Fork of MiMicSimpleHttpd by
What is this?
This application works as a converter of the electronic circuit and Redstone circuit.
Getting started
http://nyatla.jp/mimic/wp/?p=617
Diff: main.cpp
- Revision:
- 6:5909618469f8
- Parent:
- 5:00daa91538bc
- Child:
- 7:7720763e8918
diff -r 00daa91538bc -r 5909618469f8 main.cpp --- a/main.cpp Thu May 16 16:07:17 2013 +0000 +++ b/main.cpp Fri May 17 05:54:52 2013 +0000 @@ -7,36 +7,62 @@ class RedIoPin: public InOut { private: - int _v; + bool _v_pin; + bool _v_rs; public: RedIoPin(char pin):InOut(pin,0) { //pull down this->mode(1);//pull down - this->_v=0; + //read from pin + this->setDirection(true); this->write(0); + this->setDirection(false); + //initialize pin and rs + this->_v_pin=this->read()!=0; + this->_v_rs=false; } /** * set RedStoneValue RedStone value + * @param v + * red stone value * @return - * red stone value. + * current pin value */ bool setRedValue(int v) { - //read real pin status,direction=in + //update red stone pattern + this->_v_rs=(v!=0); + + //check pin value + this->setDirection(true); + this->write(0); this->setDirection(false); - if(this->read()!=0) - { //real pin==1:out=1,in=0 - this->_v=1; - this->write(0); + this->_v_pin=(this->read()!=0); + + //mix two values + if(this->_v_pin){ + // set pin to Lv=H,dir=in + if(this->_v_rs){ + //pin==1 && rs==1 + this->setDirection(true); + this->write(1); + }else{ + //pin==1 && rs==0 + this->write(0); + } }else{ - //real pin==0: direction=out,out=redstone value - this->setDirection(true); - int vt=v!=0?1:0; - this->write(vt); - this->_v=vt; + if(this->_v_rs){ + //pin==0 && rs==1 + this->setDirection(true); + this->write(1); + }else{ + //pin==0 && rs==0 + this->write(0); + } } - return this->_v; + //actual pin value + return this->_v_pin; } }; class RedIo @@ -61,7 +87,7 @@ unsigned int ret=0; for(int i=0;i<30;i++){ ret=ret<<1; - ret=ret | (this->io[29-i]->setRedValue((v>>(29-i))&0x00000001)?1:0); + ret=ret | ((this->io[29-i]->setRedValue((v>>(29-i))&0x00000001))?1:0); } return ret; }