void WaveIO::RiffwaveWriter::infoWrite(const Streaminfo& info) { RiffwaveFormat format; format.tag=RIFFWAVE_FORMAT_EXTENSIBLE; format.channel_count=info.channel_count; format.sample_rate=info.sample_rate; format.data_rate=format.sample_rate*format.channel_count*sizeof(sample_t); format.size_block=format.channel_count*sizeof(sample_t); format.bit_depth=8*sizeof(sample_t); format.size_extension=22; format.bits_valid=format.bit_depth; format.channel_mask=info.channel_mask; format.format_guid=RIFFWAVE_GUID_IEEEFLOAT; channel_count=info.channel_count; if(!chunkIDWrite("fmt ")) {throw Herbs::ExceptionMissing(___FILE__,__LINE__);} if(!chunkSizeWrite(sizeof(format))) {throw Herbs::ExceptionMissing(___FILE__,__LINE__);} if(dataWrite(&format,sizeof(format))!=sizeof(format)) {throw Herbs::ExceptionMissing(___FILE__,__LINE__);} RiffwaveFact fact; fact.sample_length=0xffffffff; if(!chunkIDWrite("fact")) {throw Herbs::ExceptionMissing(___FILE__,__LINE__);} if(!chunkSizeWrite(sizeof(fact))) {throw Herbs::ExceptionMissing(___FILE__,__LINE__);} if(dataWrite(&fact,sizeof(fact))!=sizeof(fact)) {throw Herbs::ExceptionMissing(___FILE__,__LINE__);} chunkIDWrite("data"); chunkSizeWrite(0xffffffff); }
void WR_8_Byte(const unsigned char *data, unsigned char mode) { INIT_WR_DATA; if (mode) { // D_PORT = data[0]; // WR_DATA; // D_PORT = data[1]; // WR_DATA; // D_PORT = data[2]; // WR_DATA; // D_PORT = data[3]; // WR_DATA; // D_PORT = data[4]; // WR_DATA; // D_PORT = data[5]; // WR_DATA; // D_PORT = data[6]; // WR_DATA; // D_PORT = data[7]; // WR_DATA; for (byte i = 0; i < 8; i++) { dataWrite(data[i]); WR_DATA; } } else { // D_PORT = ~data[0]; // WR_DATA; // D_PORT = ~data[1]; // WR_DATA; // D_PORT = ~data[2]; // WR_DATA; // D_PORT = ~data[3]; // WR_DATA; // D_PORT = ~data[4]; // WR_DATA; // D_PORT = ~data[5]; // WR_DATA; // D_PORT = ~data[6]; // WR_DATA; // D_PORT = ~data[7]; // WR_DATA; for (byte i = 0; i < 8; i++) { dataWrite(~data[i]); WR_DATA; } } DATA_FIN; }
void wr_byte_cmd2(unsigned char data1, unsigned char data2) { INIT_WR_CMD; // D_PORT = data1; dataWrite(data1); WR_CMD; // D_PORT = data2; dataWrite(data2); WR_CMD; CMD_FIN; }
void wr_byte_data(unsigned char data) { INIT_WR_DATA; // D_PORT = data; dataWrite(data); WR_DATA; DATA_FIN; }
void wr_byte_cmd(unsigned char data) { INIT_WR_CMD; // D_PORT = data; dataWrite(data); WR_CMD; CMD_FIN; }
void Adafruit_GP9002::begin(void) { // set pin directions pinMode(_dc, OUTPUT); pinMode(_cs, OUTPUT); if (! hwSPI) { pinMode(_mosi, OUTPUT); pinMode(_miso, INPUT); pinMode(_sclk, OUTPUT); clkport = portOutputRegister(digitalPinToPort(_sclk)); clkpinmask = digitalPinToBitMask(_sclk); mosiport = portOutputRegister(digitalPinToPort(_mosi)); mosipinmask = digitalPinToBitMask(_mosi); misopin = portInputRegister(digitalPinToPort(_miso)); misopinmask = digitalPinToBitMask(_miso); } else { SPI.begin(); SPI.setClockDivider(SPI_CLOCK_DIV4); SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE0); } csport = portOutputRegister(digitalPinToPort(_cs)); cspinmask = digitalPinToBitMask(_cs); dcport = portOutputRegister(digitalPinToPort(_dc)); dcpinmask = digitalPinToBitMask(_dc); command(GP9002_DISPLAY); dataWrite(GP9002_DISPLAY_MONOCHROME); command(GP9002_LOWERADDR1); dataWrite(0x0); command(GP9002_HIGHERADDR1); dataWrite(0x0); command(GP9002_LOWERADDR2); dataWrite(0x0); command(GP9002_HIGHERADDR2); dataWrite(0x4); command(GP9002_OR); command(GP9002_CLEARSCREEN); command(GP9002_DISPLAY1ON); // hold the address so we can read and then write command(GP9002_ADDRHELD); }
void set_char_at(char c, int line_num, int x) { uint8_t orig_cursor=cursor_pos; //move cursor cursorTo(line_num, x); //write dataWrite(c); //restore cursor commandWrite(CMD_DDADDR(orig_cursor)); cursor_pos=orig_cursor; }
// updated high speed drawing! void Adafruit_GP9002::drawFastVLine(int16_t x, int16_t orig_y, int16_t h, uint16_t color) { if ((x < 0) || (x >= width()) || (orig_y >= height())) return; //if ((orig_y+h) >= height()) // h = height() - orig_y -1; //drawLine(x, orig_y, x, orig_y+h, color); return; while (h) { if ((h >= 8) && ((orig_y) % 8 == 0)) break; drawPixel(x, orig_y, color); orig_y++; h--; } if (h >= 8) { // calculate addr uint16_t addr = 0; addr = x*8; uint16_t y = orig_y+h-8; y = 63 - y; addr += y/8; Serial.println(addr, HEX); command(GP9002_ADDRINCR); command(GP9002_ADDRL); dataWrite(addr & 0xFF); command(GP9002_ADDRH); dataWrite(addr >> 8); command(GP9002_DATAWRITE); while (h >= 8) { // draw 8 pixels at once! if (color) dataWrite(0xFF); else dataWrite(0x00); h -= 8; orig_y += 8; } }
void WR_Bytes(const unsigned char *data, unsigned char mode, unsigned char num) { INIT_WR_DATA; if (mode) { for (byte i = 0; i < num; i++) { // D_PORT = data[i]; dataWrite(data[i]); WR_DATA; } } else { for (byte i = 0; i < num; i++) { // D_PORT = ~data[i]; dataWrite(~data[i]); WR_DATA; } } DATA_FIN; }
/* * function to redirect stdout to lcd by FDEV_SETUP_STREAM() macro * Sends a character to the LCD display. * '\n' clears the display after the *next* character * '\r' sets the cursor address to begin of 2nd line */ int lcd_putchar(char c, FILE *unused) { static char nl_seen; if (nl_seen && c != '\n') { // first character after newline, clear display and home cursor. clear(); nl_seen = 0; } if (c == '\n') { nl_seen = 1; } else if (c != '\r') { dataWrite(c); } else { commandWrite(CMD_DDADDR(64)); } return 0; }
bool ComediChan::dioWrite(int bit) { double v = bit ? m_rangeMax : m_rangeMin; return dataWrite(v); }
size_t WaveIO::RiffwaveWriter::write(const sample_t* samples,size_t length) { auto ret=dataWrite(samples,length*sizeof(sample_t)); length_written+=ret; return ret; }
String FTPServer::run() { if (client.connected()) { String clientIP = String(remoteIp = client.remoteIP()); dbg("-------------------------------------------------------------", ""); dbg("FTPino", "Client connected: " + clientIP); #if - 1 != BUZZER_PIN Buzzer::beepTwice(); #endif digitalWrite(D7, HIGH); String clientResponse, parseInfo; isFTPinoClient = false; if (timeoutSec > 0) aliveTimer = millis() + timeoutSec * 1000; else aliveTimer = -1; while (client.connected()) { switch (state) { case TEftpState_Init: server->println("220 Welcome to FTPino FTP Server."); break; case TEftpState_User: server->println("331 Password required for user " + parseInfo + "."); break; case TEftpState_AuthOk: server->println("230 User successfuly logged in."); break; case TEftpState_AuthFail: client.stop(); break; case TEftpState_CurrentDir: server->println("257 \"/\" is current directory."); break; case TEftpState_System: server->println("215 UNIX emulated by FTPino."); break; case TEftpState_Features: server->println("211 Extensions supported SIZE MDTM XCRC."); break; case TEftpState_Type: server->println("200 Type set to BINARY."); break; case TEftpState_RestartAt: server->println("350 Restarting at " + parseInfo + ". !!! Not implemented"); break; case TEftpState_Store: writeFile(parseInfo, fh); break; case TEftpState_DeleteDir: if (fh->deleteTarget(parseInfo, true) < 0) server->println("550 Can't delete Directory."); else server->println("250 Directory " + parseInfo + " was deleted."); break; case TEftpState_DeleteFile: if (fh->deleteTarget(parseInfo, false) < 0) server->println("550 Can't delete File."); else server->println("250 File " + parseInfo + " was deleted."); break; case TEftpState_MakeDir: if (fh->makeDir(parseInfo) < 0) server->println("550 Can't create directory."); else server->println("257 Directory created : " + parseInfo + "."); break; case TEftpState_Append: writeFile(parseInfo, fh, true); break; case TEftpState_Client: if (parseInfo.startsWith("FTPino")) isFTPinoClient = true; break; case TEftpState_RenameFrom: fh->renameFrom(parseInfo); server->println("350 Directory exists, ready for destination name"); break; case TEftpState_RenameTo: fh->renameTo(parseInfo); server->println("250 Directory renamed successfully"); break; case TEftpState_List: dataWrite(fh->getDirList()); break; // implementing LIST verb as described at : // https://files.stairways.com/other/ftp-list-specs-info.txt case TEftpState_RetrieveFile: readFile(parseInfo); break; case TEftpState_Quit: server->println("221 Bye."); client.stop(); dclient.stop(); break; case TEftpState_ParentDir: fh->changeToParentDir(); server->println("250 Going one level up."); break; case TEftpState_Port: { transferMode = TEftpTransferMode_Active; dclient.connect(remoteIp, activeDataPortHi << 8 | activeDataPortLo); server->println("200 Port command successful."); break; } case TEftpState_Passive: { auto ip = WiFi.localIP(); char buffer[1024]; sprintf(buffer, "(%d,%d,%d,%d," + String(passiveDataPortHi) + "," + String(passiveDataPortLo) + ")", ip[0], ip[1], ip[2], ip[3]); server->println("227 Entering Passive Mode " + String(buffer)); waitForClientDataConnection(); transferMode = TEftpTransferMode_Passive; break; } case TEftpState_ChangeDir: { if (fh->changeDir(parseInfo) < 0) server->println("550 Can't change directory to " + parseInfo + "."); else server->println("250 \"/" + parseInfo + "\" is current directory."); break; } } if (client.connected()) { // if client not disconnected by the logic above do { delay(100); // allow the client to read response clientResponse = dataRead(); auto newState = parseCommand(clientResponse, parseInfo); if (newState != state) state = newState; if ((clientResponse.length() > 0) && (TEftpState_Unknown == state)) server->println("502 Command not implemented: " + parseInfo + "."); if ((-1 != aliveTimer) && (static_cast<int64_t>(millis()) - static_cast<int64_t>(aliveTimer)) > 0) server->println("530 Timeout, disconnecting control socket."), state = TEftpState_Quit; // timeout } while (TEftpState_Unknown == state); } } state = TEftpState_Init; dbg("FTPino", "Client disconnected: " + clientIP); fh->flush(); #if - 1 != BUZZER_PIN Buzzer::beepOnce(); #endif totalConnections++; } else { client = server->available(); digitalWrite(D7, LOW); state = TEftpState_Init; } return ""; }
// for compatibility with other LCD libs void LCDdogmSPI::print(char value) { dataWrite(value); }