Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Digitalio.cpp
00001 /* 00002 * Digitalio.cpp 00003 * 00004 * Created on: Jul 9, 2018 00005 * Author: Claudio Pinheiro 00006 */ 00007 00008 #include <plc/Digitalio.h> 00009 00010 DigitalIO::DigitalIO() : i2cBus1(p9, p10), 00011 i2cBus2(p28, p27), 00012 PLC_IO(&i2cBus1, 0, 1), 00013 EXT0_IO(&i2cBus2, 0, 1), 00014 EXT1_IO(&i2cBus2, 2, 3), 00015 EXT2_IO(&i2cBus2, 4, 5), 00016 EXT3_IO(&i2cBus2, 6, 7), 00017 pc(USBTX, USBRX) 00018 { 00019 boards[0] = &PLC_IO; 00020 boards[1] = &EXT0_IO; 00021 boards[2] = &EXT1_IO; 00022 boards[3] = &EXT2_IO; 00023 boards[4] = &EXT3_IO; 00024 00025 inputTicker.attach_us(callback(this, &DigitalIO::inputReader), 1000*SAMPLER_PERIOD_MS); 00026 outputTicker.attach_us(callback(this, &DigitalIO::outputWriter), 1000*SAMPLER_PERIOD_MS); 00027 00028 } 00029 00030 DigitalIO::~DigitalIO() { 00031 // TODO Auto-generated destructor stub 00032 } 00033 00034 void DigitalIO::inputReader(void) { 00035 int i; 00036 short buffer = 0; 00037 _mutex.lock(); 00038 for (i = 0; i < 5; i++) { 00039 boards[i]->readWord(&buffer); 00040 ioBuffer[i] = buffer; 00041 } 00042 _mutex.unlock(); 00043 } 00044 00045 void DigitalIO::outputWriter(void) { 00046 int i; 00047 short buffer = 0; 00048 _mutex.lock(); 00049 for (i = 0; i < 5; i++) { 00050 buffer = (short) ioBuffer[5 + i].to_ulong(); 00051 boards[i]->writeWord(buffer); 00052 //inBuffer_[i] = buffer; 00053 } 00054 _mutex.unlock(); 00055 00056 }
Generated on Mon Jul 25 2022 15:13:16 by
1.7.2