/* Set individual chip pin port as IN/OUT
	Parameters
	pin:0...7/15
	mode:0(out), 1(in)
*/
void gpio_MCP23SXX::gpioPinMode(uint8_t pin, bool mode)
{
	if (pin < _ports){//0...7/15
		mode == INPUT ? _gpioDirection |= (1 << pin) :_gpioDirection &= ~(1 << pin);
		_sendData(MCP23XXX_IODIR[_regIndex],_gpioDirection);
	}
}
/**
 * Goto (0,0 is first line, first column)
 */
void SkaarhojEADOGMDisplay::gotoRowCol(uint8_t row, uint8_t col) {
    _DDRAMaddr = (row << (_boardType==1?3:4)) + col;

//	Serial << row << " - " << col << " => " << _DDRAMaddr << "\n";

    switch(_boardType)	{
    case 1:
        _DDRAMaddr%=8;
        break;
    case 2:
        _DDRAMaddr%=32;
        break;
    case 3:
        _DDRAMaddr%=48;
        break;
    }

//	 Serial << _DDRAMaddr << "\n";
    if (_boardType==2 && _DDRAMaddr >= 16)	{
        _DDRAMaddr+=24;
    }

    _sendData(false);
    _selectDisplay(_index, true);
    shiftOut(_dataPin, _clockPin, MSBFIRST, B10000000 | (_DDRAMaddr & B1111111));
    /*	for(uint8_t a=0;a<8;a++)	{
    		digitalWrite(_dataPin, (B10000000 | (_DDRAMaddr & B1111111)) & (B1<<(7-a)));
    		digitalWrite(_clockPin, HIGH);
    //		delayMicroseconds(1500);
    		digitalWrite(_clockPin, LOW);
    	}
      */
    _selectDisplay(_index,false);
    delayMicroseconds(30);
}
/**
 * Clear display
 */
void SkaarhojEADOGMDisplay::clearDisplay(void) {
    _DDRAMaddr = 0;

    _sendData(false);
    _selectDisplay(_index, true);
    shiftOut(_dataPin, _clockPin, MSBFIRST, 0x01);
    _selectDisplay(_index,false);
}
/*

	GPIO at 8bit uses only the first 8 bit!
*/
void gpio_MCP23SXX::gpioPortDefValues(uint16_t data)
{
	if (data == HIGH){//TODO
		data = 0xFFFF;
	} else if (data == LOW){
		data = 0x0000;
	}
	data = data & _gpioDirection;//only pins with IN, OUT ignored
	_sendData(MCP23XXX_DEFVAL[_regIndex],data);
}
/*
	NOTE:
	writing GPIO actually = OLAT, in a pin is conf as input
	it will goes as high impedance
	GPIO at 8bit uses only the first 8 bit!
*/
void gpio_MCP23SXX::gpioPortLatches(uint16_t data)
{
	if (data == HIGH){//TODO
		data = 0xFFFF;
	} else if (data == LOW){
		data = 0x0000;
	}
	data = data & ~_gpioDirection;//only pins with OUT, IN ignored
	_sendData(MCP23XXX_OLAT[_regIndex],data);
}
/* Set ALL or individual chip pin port inverted reading
	Parameters
	mode:16 bit data or HIGH or LOW
	If bit is 1, the correspondant polarity of the pin will invert
	GPIO at 8bit uses only the first 8 bit!
*/
void gpio_MCP23SXX::gpioPortInvert(uint16_t data)
{
	if (data == HIGH){
		data = 0xFFFF;
	} else if (data == LOW){
		data = 0x0000;
	}
	//TODO: IN and OUT?
	_sendData(MCP23XXX_IPOL[_regIndex], data);
}
/**
 * Contrast
 */
void SkaarhojEADOGMDisplay::contrast(uint8_t contrast) {
    _sendData(false);
    _selectDisplay(_index, true);

//	Serial.println(_boardType!=1);
    shiftOut(_dataPin, _clockPin, MSBFIRST, _boardType!=1 ? 0x39 : 0x31);
    shiftOut(_dataPin, _clockPin, MSBFIRST, 0x70 | (contrast & 0xF));
    shiftOut(_dataPin, _clockPin, MSBFIRST, _boardType!=1 ? 0x38 : 0x30);

    _selectDisplay(_index,false);
}
/* Set ALL ports or individually as High or Low
	Parameters
	value:16 bit data or HIGH or LOW
	NOTE:
	writing GPIO actually = OLAT, in a pin is conf as input
	it will goes as high impedance
	GPIO at 8bit uses only the first 8 bit!
*/
void gpio_MCP23SXX::gpioPort(uint16_t value)
{
	if (value == HIGH){
		value = 0xFFFF;
	} else if (value == LOW){
		value = 0x0000;
	}
	_gpioState = value & ~_gpioDirection;//only pins with OUT, IN ignored
	//_gpioState = value;
	_sendData(MCP23XXX_GPIO[_regIndex],_gpioState);
}
void Controler::_createSorter()
{
  int dad_writes[2];
  int son_writes[2];
  pid_t control_pid;

  control_pid = getpid();

  if( pipe(dad_writes) == -1 || pipe(son_writes) == -1  )
    qFatal("pipe, in Controler::_createSorter");

  _writeChannel = dad_writes[1];
  _readChannel = son_writes[0];

  //make list of numbers available for Sorter
  _sendData();

  switch( _sorter_pid = fork() )
    {
    case -1:
      qFatal("fork, in Controler::_createSorter");

    case 0:

      ::close(dad_writes[1]);
      ::close(son_writes[0]);

      setpgid(_sorter_pid, control_pid);

      if(
	 execl(_execName->toAscii(), _execName->toAscii(),
	       "-p",
	       "sorter",
	       "--control",
	       SortUtility::itos(control_pid).c_str(),
	       "--write-channel",
	       SortUtility::itos(son_writes[1]).c_str(),
	       "--read-channel",
	       SortUtility::itos(dad_writes[0]).c_str(),
	       NULL
	       ) == -1 )
	qFatal("execl, in Controler::_createSorter");

    default:
      ::close(dad_writes[0]);
      ::close(son_writes[1]);

    }

  qDebug() << "write Channnels --- Control (" << control_pid << "): " << dad_writes[1] << ", Sorter (" << _sorter_pid <<"): " << son_writes[1] << "\n";
  qDebug() << "read Channnels --- Control (" << control_pid << "): " << son_writes[0] << ", Sorter (" << _sorter_pid <<"): " << dad_writes[0] << "\n";

  _updateStatus("Sorter view created" );
}
Beispiel #10
0
/* Set ALL or individual chip pin port in pullUp
	Parameters
	mode:16 bit data or HIGH or LOW
	Pullup works when pin are IN or OUT
	GPIO at 8bit uses only the first 8 bit!
*/
void gpio_MCP23SXX::gpioPortPullup(uint16_t data)
{
	if (data == HIGH){
		_gpioState = 0xFFFF;
	} else if (data == LOW){
		_gpioState = 0x0000;
	} else {
		_gpioState = data;
	}
	_sendData(MCP23XXX_GPPU[_regIndex], _gpioState);
}
Beispiel #11
0
/* Set ALL or individual chip pin port as IN/OUT
	Parameters
	mode:16 bit data or INPUT or OUTPUT
	GPIO at 8bit uses only the first 8 bit!
*/
void gpio_MCP23SXX::gpioPinMode(uint16_t mode)
{
	if (mode == INPUT){
		_gpioDirection = 0xFFFF;
	} else if (mode == OUTPUT){
		_gpioDirection = 0x0000;
		_gpioState = 0x0000;
	} else {
		_gpioDirection = mode;
	}
	_sendData(MCP23XXX_IODIR[_regIndex],_gpioDirection);
}
Beispiel #12
0
//---------------------
uint8_t _sendFile(void)
{
  if ((ftpfile == NULL) || (file_fd == FILE_NOT_OPENED)) {
    ftp_log("[FTP dta] Send file not opened\r\n");
    file_status = -1;
    return 1;
  }
  if (recvDataBuf == NULL) {
    ftp_log("[FTP dta] Buffer error\r\n");
    file_status = -2;
    return 1;
  }
  if (file_status >= file_size) return 1;

  uint16_t len = 1020;
  int rdlen;
  if (max_recv_datalen < len) len = max_recv_datalen-4;
  rdlen = SPIFFS_read(&fs, (spiffs_file)file_fd, (char*)recvDataBuf, len);
  if (rdlen > 0) {
    if (!_sendData(recvDataBuf, rdlen)) {
      ftp_log("[FTP dta] Error sending data\r\n");
      file_status = -3;
      return 1;
    }
    else {
      file_status += rdlen;
      ftp_log("\r[FTP dta] %.*f %%", 1, (float)(((float)file_status/(float)file_size)*100.0));
      if (file_status >= file_size) return 1;
      else return 0;
    }
  }
  else if (rdlen <= 0) {
    ftp_log("[FTP dta] Error reading from file (%d)\r\n", rdlen);
    file_status = -4;
    return 1;
  }
  else return 1;
}
Beispiel #13
0
//-----------------------
uint8_t _sendString(void)
{
  if (sendDataBuf == NULL) {
    ftp_log("[FTP dta] Buffer error\r\n");
    file_status = -2;
    return 1;
  }
  if (file_status >= file_size) return 1;

  int len = 1020;
  if ((file_size - file_status) < len) len = file_size - file_status;
  
  if (!_sendData(sendDataBuf+file_status, len)) {
    ftp_log("[FTP dta] Error sending data\r\n");
    file_status = -3;
    return 1;
  }
  else {
    file_status += len;
    ftp_log("\r[FTP dta] %.*f %%", 1, (float)(((float)file_status/(float)file_size)*100.0));
    if (file_status >= file_size) return 1;
    else return 0;
  }
}
bool QtCesterConnection::copyFileToDevice(const QString &localSource, const QString &deviceDest, bool failIfExists)
{
    debugOutput( qPrintable(QString::fromLatin1("Copy File: %1 -> %2").arg(localSource).arg(deviceDest)),0);
    QFile localFile(localSource);
    QFileInfo info(localSource);
    if (!localFile.exists() || !localFile.open(QIODevice::ReadOnly)) {
        qDebug() << "Could not open File!";
        return false;
    }

    QTcpSocket* socket = 0;
    if (!_initCommand(socket, COMMAND_CREATE_FILE)) {
        END_ERROR(socket, "Could not initialized command");
    }

    CreateFileOptions option;
    strcpy(option.fileName, qPrintable(deviceDest));
#ifdef Q_OS_WIN
    // Copy FileTime for update verification
    FILETIME creationTime, accessTime, writeTime;
    HANDLE localHandle = CreateFile(localSource.utf16(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
    if (localHandle != INVALID_HANDLE_VALUE) {
        if (GetFileTime(localHandle, &creationTime, &accessTime, &writeTime)) {
            LocalFileTimeToFileTime(&writeTime, &writeTime);
            option.fileTime = writeTime;
        }
        CloseHandle(localHandle);
    }
    DWORD attributes = GetFileAttributes(localSource.utf16());
    if (attributes != -1 )
        option.fileAttributes = attributes;
#endif
    option.fileSize = info.size();
    option.overwriteExisting = !failIfExists;

    if (!_sendData(socket, (char*) &option, sizeof(option))) {
        END_ERROR(socket, "Could not send options...");
    }

    if (!_checkResult(socket)) {
        END_ERROR(socket, "Server did not accept configuration");
    }

    int bytesWritten = 0;
    const int bufferSize = 1024;
    QByteArray data;
    while (bytesWritten < option.fileSize) {
        data = localFile.read(bufferSize);
        bytesWritten += data.size();
#ifdef Q_OS_WIN
        wprintf( L"%s -> %s (%d / %d) %d %%\r", localSource.utf16() , deviceDest.utf16(),
                 bytesWritten , option.fileSize, (100*bytesWritten)/option.fileSize );
#endif
        if (!_sendData(socket, data.constData(), data.size())) {
            END_ERROR(socket, "Error during file transfer");
        }
        if (!_checkResult(socket)) {
            END_ERROR(socket, "Got some strange result");
        }
    }
#ifdef Q_OS_WIN
    wprintf( L"\n"); // We should jump to next line...
#endif
    if (bytesWritten != option.fileSize) {
        END_ERROR(socket, "Did not send sufficient data");
    }
    _freeSocket(socket);
    return true;
}
/**
 * Initialization
 * Address is 0-7 : How address jumpers are set; index is which display on the board (each display has it's own object), starting from 0; boardType depends whether the display is DOGM081 (1), DOGM162 (2) or DOGM163 (3)
 */
void SkaarhojEADOGMDisplay::begin(uint8_t address, uint8_t index, uint8_t boardType) {
    // NOTE: Wire.h should definitely be initialized at this point! (Wire.begin())

    _boardAddress = 88 | (address & B111);	// 0-7
    _boardType = boardType;	// 1=DOGM81, 2=DOGM162, 3=DOGM163
    _index = index;	// which display on the board (0-3)

    // Set SPI pins up:
    _clockPin = 48;
    _dataPin = 49;
    pinMode(_clockPin, OUTPUT);
    pinMode(_dataPin, OUTPUT);

    _chipLowerByte = 255;
    _chipUpperByte = 255;

    _selectDisplay(_index,false);
    _sendData(false);

    _selectDisplay(_index, true);
    switch(_boardType)	{
    case 1:
        // Init sequence for a DOG081, 5V:
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x31);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x1C);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x51);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x6A);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x74);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x30);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x0C);     // Normally 0x0F, but here disabled cursor.
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x01);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x06);
        break;
    case 2:
        // Init sequence for a DOG162:
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x39);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x1C);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x52);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x69);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x74);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x38);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x0C);     // Normally 0x0F, but here disabled cursor.
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x01);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x06);
        break;
    case 3:
        // Init sequence for a DOG163:
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x39);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x1D);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x50);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x6C);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x78);   	// 7C
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x38);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x0C);     // Normally 0x0F, but here disabled cursor.
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x01);
        shiftOut(_dataPin, _clockPin, MSBFIRST, 0x06);
        break;
    }
    _selectDisplay(_index,false);

    clearDisplay();
}
Beispiel #16
0
/* Set ALL ports as High or Low by using separate banks.
	Parameters
	bankA:8 bit data for port A
	bankB:8 bit data for port B
	NOTE:
	writing GPIO actually = OLAT, in a pin is conf as input
	it will goes as high impedance
	GPIO at 8bit uses only bankA!
*/
void gpio_MCP23SXX::gpioPort(uint8_t bankA, uint8_t bankB)
{
	_gpioState = (bankB << 8) | bankA;
	_gpioState = _gpioState & ~_gpioDirection;//only pins with OUT, IN ignored
	_sendData(MCP23XXX_GPIO[_regIndex],_gpioState);
}
Beispiel #17
0
/* Send internal _gpioState register to chip
	Parameters
	none
	NOTE:
	writing GPIO actually = OLAT, in a pin is conf as input
	it will goes as high impedance
*/
void gpio_MCP23SXX::gpioPortUpdate(void)
{
	_sendData(MCP23XXX_GPIO[_regIndex],_gpioState);
}
/**
 * Cursor
 */
void SkaarhojEADOGMDisplay::cursor(bool enable) {
    _sendData(false);
    _selectDisplay(_index, true);
    shiftOut(_dataPin, _clockPin, MSBFIRST, enable ? 0x0F : 0x0C);
    _selectDisplay(_index,false);
}
Beispiel #19
0
/* Set individual chip pin port generate interrupts
	Parameters
	mode:16 bit data corresponding individual pins, 0 no int, 1 int
	GPIO at 8bit uses only the first 8 bit!
*/
void gpio_MCP23SXX::gpioPortInterrupts(uint16_t data)
{
	data = data & _gpioDirection;//only pins with IN, OUT ignored
	_sendData(MCP23XXX_GPINTEN[_regIndex], data);
}
Beispiel #20
0
/*
	This works only for inputs!
	GPIO at 8bit uses only the first 8 bit!
*/
void gpio_MCP23SXX::gpioPortIntControl(uint16_t data)
{
	data = data & _gpioDirection;//only pins with IN, OUT ignored
	_sendData(MCP23XXX_INTCON[_regIndex], data);
}