//Power value: bool HidnSeek::setPower(uint8_t power) { // 13,9dBm with 0,4,47 for the parameter if (power > 0) _command(PSTR("AT$MT=0,4,47")); else { _command(PSTR("ATZ")); } _serial.println(); char dataRX[5] = ""; int length = 3; int timeout = 50; int bread = 0; long previousMillis = millis(); while((millis()-previousMillis)<timeout) { if(_serial.available()>0) { char c = _serial.read(); if(bread>length) { return(-1); // string received is too long } else { dataRX[bread]=c; } if (c == 'O') bread++; if (c == 'K') break; } } if (strcmp (dataRX,"OK") != 0) return false; else return true; }
//------------------------------------------------------------------------------------------------- inline void_t SmtpClient::login() { //------------------------------------- //RFC /* C: AUTH LOGIN\r\n S: 334 VXNlcm5hbWU6 C: base64_encode(MYLOGIN)\r\n C: base64_encode(MYPASS)\r\n S: 235 Authentication succeeded */ std::tstring_t sRv; //------------------------------------- //[AUTH\r\n] std::ctstring_t authLoginCmd = xT("AUTH LOGIN\r\n"); _command(authLoginCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- //[mylogin\r\n] std::ctstring_t loginCmd = xS2TS( Base64().encode( xTS2S(_user) ) ) + xT("\r\n"); _command(loginCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- //[mypassword\r\n] std::ctstring_t passwordCmd = xS2TS( Base64().encode( xTS2S(_password) ) ) + xT("\r\n"); _command(passwordCmd, xT("\r\n"), /*ref*/sRv); }
void V4LCamera::capture() { struct v4l2_buffer buffer; buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buffer.memory = V4L2_MEMORY_MMAP; int result = 0; while(-1 == (result = _command(VIDIOC_DQBUF, &buffer)) && EAGAIN == errno); if (-1 == result) { printf("Error: Could not capture frame\n"); exit(-1); } unsigned char* yuyv = _buffers[buffer.index]; unsigned char* end = yuyv + buffer.length; float* y = _frameData; for (; yuyv != end; y += 4, yuyv += 4) { y[0] = yuyv[0]; y[1] = 255.0f; y[2] = yuyv[2]; y[3] = 255.0f; } if (-1 == _command(VIDIOC_QBUF, &buffer)) { printf("Error: Could not re-queue buffer\n"); exit(-1); } }
void ICACHE_FLASH_ATTR ssd1306_invert_display(uint8_t id, bool invert) { oled_i2c_ctx *ctx = _ctxs[id]; if (ctx == NULL) return; if (invert) _command(ctx->address, 0xa7); // SSD1306_INVERTDISPLAY else _command(ctx->address, 0xa6); // SSD1306_NORMALDISPLAY }
void SendToAddressTest::testInvalidRequest() { QVariantMap request; QVariant result = _command(request); QVERIFY(!result.toBool()); request.insert("from", "0x0000000000000000000000000000000000000000"); result = _command(request); QVERIFY(!result.toBool()); request.insert("to", "0x0000000000000000000000000000000000000001"); result = _command(request); QVERIFY(!result.toBool()); request.insert("amount", "100000000000000000"); result = _command(request); QVERIFY(!result.toBool()); }
void Timer::scheduledTask() { std::mutex mu; std::unique_lock<std::mutex> lock(mu); _cond.wait_for(lock, milliseconds(_millisecs)); _command(); }
//------------------------------------------------------------------------------------------------- inline void_t SmtpClient::connect() { std::tstring_t sRv; //------------------------------------- //������� ����� _socket.create(Socket::afInet, Socket::tpStream, Socket::ptIp); //------------------------------------- //������ ����� std::tstring_t ip; DnsClient::hostAddrByName(_server, &ip); //------------------------------------- //����������� _socket.connect(ip, _port); //------------------------------------- //[welcome message] sRv = _socket.recvAll(0, xT("\r\n")); xTEST_MSG_EQ(false, _isError(sRv), sRv); //------------------------------------- //[HELO\r\n] std::ctstring_t helloCmd = xT("HELO HOST\r\n"); //std::ctstring_t helloCmd = "HELO\r\n"; _command(helloCmd, xT("\r\n"), /*ref*/sRv); _isConnected = true; }
bool HidnSeek::send(const void* data, uint8_t len) { uint8_t* bytes = (uint8_t*)data; /* if(!isReady()) { return false; } */ // See comment in isReady() _lastSend = millis(); _serial.write((uint8_t)'\0'); _command(PSTR("SFM")); _serial.write(len); for(uint8_t i = 0; i < len; ++i) { _serial.write(bytes[i]); } _serial.write(';'); uint8_t ok = _nextReturn(); if(ok == OK) { _nextReturn(); //SENT return true; } return false; }
ticket_t command(const std::vector<std::string> &args, RedisRequest::ResponseHandler handler, int timeout = 0) { ticket_t ticket = issueTicket(); if(timeout > 0) { timerObj_->setTimer(TIMER_ID_COMMAND_TTL, 1000, true); } struct RedisRequest::requestContext context; context.args = args; context.ticket = ticket; context.handler = handler; context.ttl = timeout > 0 ? timeout : -1; // for preventing from multithread race condition, must insert to map here.. lockRedis_.lock(); mapCallback_.insert(MapCallback_t::value_type(ticket, context)); lockRedis_.unlock(); if(ioService_->isCalledInMountedThread() == false) { deferredCaller_.deferredCall(boost::bind(&RedisRequestImpl::_command, this, ticket, args)); return ticket; } // must lock here (or deadlock may occur by DeferredCaller's mutex..) lockRedis_.lock(); _command(ticket, args); lockRedis_.unlock(); return ticket; }
void SendToAddressTest::testSend() { GethSimulator & geth = _context.getGeth(); _context.getKeyStore().registerAccount("0x0000000000000000000000000000000000000000", "asdasd123"); geth.setBalance("0x0000000000000000000000000000000000000000", BigInt("1000000000000000000")); QString from = "0x0000000000000000000000000000000000000000"; QString to = "0x0000000000000000000000000000000000000001"; QVariantMap request; request.insert("from", from); request.insert("to", to); request.insert("amount", "100000000000000000"); request.insert("password", "asdasd123"); QVariant result = _command(request); QString txid = result.toString(); QVERIFY(geth.getBalance("0x0000000000000000000000000000000000000001") == BigInt("100000000000000000")); QVERIFY(geth.getBalance("0x0000000000000000000000000000000000000000") == BigInt("900000000000000000")); QJsonObject transaction = _context.getDataBase().getTransactions().get(txid.toStdString().c_str()); QCOMPARE(transaction["hash"].toString(), txid); QCOMPARE(transaction["from"].toString(), from); QCOMPARE(transaction["to"].toString(), to); QCOMPARE(transaction["amount"].toString(), QString("100000000000000000")); }
void ICACHE_FLASH_ATTR ssd1306_term(uint8_t id) { oled_i2c_ctx *ctx = _ctxs[id]; if (ctx == NULL) return; _command(ctx->address, 0xae); // SSD_DISPLAYOFF _command(ctx->address, 0x8d); // SSD1306_CHARGEPUMP _command(ctx->address, 0x10); // Charge pump off if (ctx->buffer) free(ctx->buffer); free(ctx); _ctxs[id] = NULL; }
//------------------------------------------------------------------------------------------------- inline void_t SmtpClient::sendRaw ( std::ctstring_t &a_filePath, std::ctstring_t &a_from, std::ctstring_t &a_to ) { // TODO: xTEST_DIFF(xSOCKET_HANDLE_INVALID, _socket, false); xTEST_EQ(a_from.empty(), false); xTEST_EQ(a_to.empty(), false); std::tstring_t sRv; /////////std::ctstring_t helloCmd = "HELO HOST\r\n"; // std::ctstring_t helloCmd = "HELO\r\n"; std::ctstring_t fromCmd = xT("MAIL FROM: <") + a_from + xT(">\r\n"); std::ctstring_t toCmd = xT("RCPT TO: <") + a_to + xT(">\r\n"); std::ctstring_t dataCmd = xT("DATA\r\n"); std::ctstring_t endCmd = xT("\r\n.\r\n"); //////////------------------------------------- //////////[HELO\r\n] ////////////bRv = _bCommand(helloCmd, "\r\n", /*ref*/sRv); ////////////xCHECK_RET(!bRv, false); //------------------------------------- //[MAIL FROM:<*****@*****.**>\r\n] _command(fromCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- //[RCPT TO:<*****@*****.**>\r\n] _command(toCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- //[DATA\r\n] _command(dataCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- std::tstring_t text; File::textRead(a_filePath, &text); //------------------------------------- //[DataText\r\n.\r\n] _command(text + endCmd, xT("\r\n"), /*ref*/sRv); }
int SI7021::getTemperature() { byte tempbytes[2]; _command(TEMP_READ, tempbytes); long tempraw = (long)tempbytes[0] << 8 | tempbytes[1]; if (_checkCRC8(tempraw) != tempbytes[2]){ return 99998; } return ((17572 * tempraw) >> 16) - 4685; }
unsigned int SI7021::getHumidityPercent() { byte humbytes[2]; _command(RH_READ, humbytes); long humraw = (long)humbytes[0] << 8 | humbytes[1]; if (_checkCRC8(humraw) != humbytes[2]){ return 99999; } return ((125 * humraw) >> 16) - 6; }
//------------------------------------------------------------------------------------------------- inline void_t SmtpClient::send( std::ctstring_t &a_text, std::ctstring_t &a_from, std::ctstring_t &a_to ) { // TODO: xTEST_DIFF(xSOCKET_HANDLE_INVALID, _socket); xTEST_EQ(a_from.empty(), false); xTEST_EQ(a_to.empty(), false); std::tstring_t sRv; std::ctstring_t helloCmd = xT("HELO HOST\r\n"); std::ctstring_t fromCmd = xT("MAIL FROM: <") + a_from + xT(">\r\n"); std::ctstring_t toCmd = xT("RCPT TO: <") + a_to + xT(">\r\n"); std::ctstring_t dataCmd = xT("DATA\r\n"); std::ctstring_t endCmd = xT("\r\n.\r\n"); //////------------------------------------- //////[HELO DrWEB\r\n] ////bRv = _bCommand(helloCmd, "\r\n", /*ref*/sRv); ////xCHECK_RET(!bRv, false); //------------------------------------- //[MAIL FROM:<*****@*****.**>\r\n] _command(fromCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- //[RCPT TO:<*****@*****.**>\r\n] _command(toCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- //[DATA\r\n] _command(dataCmd, xT("\r\n"), /*ref*/sRv); //------------------------------------- //�������� ����� _socket.sendAll(a_text, 0); //------------------------------------- //[\r\n.\r\n] _command(endCmd, xT("\r\n"), /*ref*/sRv); }
void SendToAddressTest::testInvalidSource() { QVariantMap request; request.insert("from", "0x0000000000000000000000000000000000000005"); request.insert("to", "0x0000000000000000000000000000000000000001"); request.insert("amount", "100000000000000000"); request.insert("password", "asdasd123"); QVariant result = _command(request); QVERIFY(!result.toBool()); }
void SendToAddressTest::testNotEnoughFunds() { QString from = "0x0000000000000000000000000000000000000000"; QString to = "0x0000000000000000000000000000000000000001"; QVariantMap request; request.insert("from", from); request.insert("to", to); request.insert("amount", "10000000000000000000000000000"); request.insert("password", "asdasd123"); QVariant result = _command(request); QVERIFY(!result.toBool()); }
void DeviceHb627::__update_inputs() throw(string) { static uint8_t result[32]; int input; uint16_t value; _command(3, (uint8_t *)"c09", 17, result); for(input = 0; input < 8; input++) { value = result[(input << 1) + 0] << 8; value |= result[(input << 1) + 1] << 0; _analog_in[input] = (uint16_t)value; } }
int main(int argc, char const *argv[]){ struct a2_state* as = a2_open(); a2_openutil(as); if(argc ==2){ // load file modle _load(as, argv[1]); }else if (argc == 1){ // command modle printf(A2_COM_HEAD); _command(as); }else{ printf("use:\na2 [file]\n"); } a2_close(as); return 0; }
//------------------------------------------------------------------------------------------------- inline void_t SmtpClient::noop() { //------------------------------------- //RFC /* �: NOOP S: +�� */ std::tstring_t sRv; //------------------------------------- //[NOOP\r\n] std::tstring_t noopCmd = xT("NOOP\r\n"); _command(noopCmd, xT("\r\n"), /*ref*/sRv); }
//------------------------------------------------------------------------------------------------- inline void_t SmtpClient::rset() { //------------------------------------- //RFC /* �: RSET S: +OK maildrop has 2 messages (320 octets) */ std::tstring_t sRv; //------------------------------------- //[RSET\r\n] std::tstring_t rsetCmd = xT("RSET\r\n"); _command(rsetCmd, xT("\r\n"), /*ref*/sRv); }
unsigned long HidnSeek::getID() { _serial.write((uint8_t)'\0'); _command(PSTR("SFID;")); //Response is [byte1, byte2, ..., byteN, 'O', 'K'] uint8_t response[8] = {0}; uint8_t i = 0; while(!_serial.available()); while(_serial.peek() != ';' || i<6) { response[i] = _serial.read(); while(!_serial.available()); ++i; } _serial.read(); //';' unsigned long id = 0; for(uint8_t j = 0; j < i-2; ++j) { id = (id << 8) + response[j]; } return id; }
void DeviceMatrixCommon::__update() throw(string) { int yy; int bright; char * current; if(_fd == -1) throw(string("DeviceMatrixCommon::__update: device not open")); __reinit(); bright = _brightness; if(_standout && (_brightness > 0)) { bright = bright + 1; if(bright > 4) bright = 2; } _setbright(bright); _command('H'); // 0x48 cursor home for(yy = 0; yy < height(); yy++) { current = _textbuffer + (yy * width()); if(::write(_fd, current, width()) != width()) throw(string("DeviceMatrixCommon::Update::write")); } usleep(200000); _setbright(_brightness); }
//------------------------------------------------------------------------------------------------- inline void_t SmtpClient::disconnect() { xCHECK_DO(!_isConnected, disconnect()); //------------------------------------- //RFC /* [QUIT\r\n] +�� dewey POP3 server signing off */ std::tstring_t sRv; //------------------------------------- //[QUIT] std::ctstring_t quitCmd = xT("QUIT\r\n"); _command(quitCmd, xT("\r\n"), /*ref*/sRv); _socket.close(); _isConnected = false; }
void glcd_Device::Init(void) { frameBufferMutex = 0; _updateWaiting = 0; pinMode(LCD_POWER, OUTPUT); digitalWrite(LCD_POWER, LOW); pinMode(LCD_BACKLIGHT, OUTPUT); digitalWrite(LCD_BACKLIGHT, HIGH); // set pin directions pinMode(LCD_A0, OUTPUT); pinMode(LCD_RESET, OUTPUT); pinMode(LCD_CS, OUTPUT); // Reset Sequence LCD must not be selected, but in command mode digitalWrite(LCD_A0, LOW); #ifdef LCD_ADAFRUIT digitalWrite(LCD_CS, LOW); #else digitalWrite(LCD_CS, HIGH); #endif digitalWrite(LCD_RESET, LOW); delay(200); digitalWrite(LCD_RESET, HIGH); digitalWrite(LCD_CS, HIGH); // Setup Hardware SPI SPI.begin(LCD_CS); SPI.setBitOrder(LCD_CS, MSBFIRST); SPI.configureDMA(); SPI.registerDMACallback(spiDMADoneCallback); #ifdef LCD_ADAFRUIT // LCD bias select _command(CMD_SET_BIAS_7); #else // LCD bias select _command(CMD_SET_BIAS_9); #endif // ADC select _command(CMD_SET_ADC_REVERSE); // SHL select _command(CMD_SET_COM_NORMAL); #ifndef LCD_ADAFRUIT // Static Off _command(CMD_SET_STATIC_OFF); #endif // Initial display line _command(CMD_SET_DISP_START_LINE); // turn on voltage converter (VC=1, VR=0, VF=0) _command(CMD_SET_POWER_CONTROL | 0x4); // wait for 50% rising delay(50); // turn on voltage regulator (VC=1, VR=1, VF=0) _command(CMD_SET_POWER_CONTROL | 0x6); // wait >=50ms delay(50); // turn on voltage follower (VC=1, VR=1, VF=1) _command(CMD_SET_POWER_CONTROL | 0x7); // wait delay(50); #ifdef LCD_ADAFRUIT _command(CMD_SET_RESISTOR_RATIO | 0x6); #else // set lcd operating voltage (regulator resistor, ref voltage resistor) _command(CMD_SET_RESISTOR_RATIO | 0x7); #endif // Library Initialisation _x = 0; _y = 0; // Power on Display _command(CMD_SET_ALLPTS_NORMAL); _command(CMD_DISPLAY_ON); // st7565_set_brightness(contrast); #ifdef LCD_ADAFRUIT _set_brightness(0x18); #else _set_brightness(0x08); #endif // Ensure display is cleared memset(this->_framebuffer, 0x00, sizeof(_framebuffer)); }
V4LCamera::V4LCamera(const char* devicePath, int width, int height) { struct stat deviceStatus; if (-1 == stat(devicePath, &deviceStatus)) { printf("Error: Could not stat device %s\n", devicePath); exit(-1); } if (!S_ISCHR(deviceStatus.st_mode)) { printf("Error: %s is not a character device\n", devicePath); exit(-1); } _file = open(devicePath, O_RDWR | O_NONBLOCK, 0); if (-1 == _file) { printf("Error: Could not open file %s\n", devicePath); exit(-1); } if (-1 == _command(VIDIOC_QUERYCAP, &_capabilities)) { printf("Error: %s is not a V4L2 device", devicePath); exit(-1); } if (!(_capabilities.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { printf("Error: %s is not a capture device", devicePath); exit(-1); } struct v4l2_cropcap cropCapabilities; cropCapabilities.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (-1 == _command(VIDIOC_CROPCAP, &cropCapabilities)) { struct v4l2_crop cropping; cropping.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; cropping.c = cropCapabilities.defrect; _command(VIDIOC_S_CROP, &cropping); } struct v4l2_format format; format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; format.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; format.fmt.pix.field = V4L2_FIELD_INTERLACED; format.fmt.pix.width = width; format.fmt.pix.height = height; if (-1 == _command(VIDIOC_S_FMT, &format)) { printf("Error: Could not set format\n"); exit(-1); } struct v4l2_input channel; channel.index = 0; if (-1 == _command(VIDIOC_S_INPUT, &channel)) { printf("Error: Could not set channel\n"); exit(-1); } struct v4l2_requestbuffers request; memset(&request, 0, sizeof(request)); request.count = numBuffers; request.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; request.memory = V4L2_MEMORY_MMAP; if (-1 == _command(VIDIOC_REQBUFS, &request)) { printf("Error: Could not request memory mapping\n"); exit(-1); } for (int i = 0; i < numBuffers; ++i) { struct v4l2_buffer buffer; memset(&buffer, 0, sizeof(buffer)); buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buffer.memory = V4L2_MEMORY_MMAP; buffer.index = 0; if (-1 == _command(VIDIOC_QUERYBUF, &buffer)) { printf("Error: Could not get MMAP information for buffer %d\n", i); exit(-1); } _buffers[i] = (unsigned char*)mmap(NULL, buffer.length, PROT_READ | PROT_WRITE, MAP_SHARED, _file, buffer.m.offset); if (MAP_FAILED == _buffers[i]) { printf("Error: MMAP failed for buffer %d\n", i); exit(-1); } memset(&buffer, 0, sizeof(buffer)); buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buffer.memory = V4L2_MEMORY_MMAP; buffer.index = i; if (-1 == _command(VIDIOC_QBUF, &buffer)) { printf("Error: Could not queue buffer\n"); exit(-1); } } int type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (-1 == _command(VIDIOC_STREAMON, &type)) { printf("Error: Could not start streaming\n"); exit(-1); } _frameData = new float[width * height * 2]; }
bool ICACHE_FLASH_ATTR ssd1306_init(uint8_t id) { oled_i2c_ctx *ctx = NULL; if ((id != 0) && (id != 1)) goto oled_init_fail; // free old context (if any) ssd1306_term(id); ctx = zalloc(sizeof(oled_i2c_ctx)); if (ctx == NULL) { dmsg_err_puts("Alloc OLED context failed."); goto oled_init_fail; } if (id == 0) { #if (PANEL0_TYPE != 0) #if (PANEL0_TYPE == SSD1306_128x64) ctx->type = SSD1306_128x64; ctx->buffer = zalloc(1024); // 128 * 64 / 8 ctx->width = 128; ctx->height = 64; #elif (PANEL0_TYPE == SSD1306_128x32) ctx->type = SSD1306_128x32; ctx->buffer = zalloc(512); // 128 * 32 / 8 ctx->width = 128; ctx->height = 32; #else #error "Panel 0 undefined" #endif if (ctx->buffer == NULL) { dmsg_err_puts("Alloc OLED buffer failed."); goto oled_init_fail; } ctx->address = PANEL0_ADDR; #if PANEL0_USE_RST // Panel 0 reset PIN_FUNC_SELECT(PANEL0_RST_MUX, PANEL0_RST_FUNC); GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | PANEL0_RST_BIT); GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, PANEL0_RST_BIT); os_delay_us(10000); GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, PANEL0_RST_BIT); #endif #else dmsg_err_puts("Panel 0 not defined."); goto oled_init_fail; #endif } else if (id == 1) { #if (PANEL1_PANEL_TYPE != 0) #if (PANEL1_PANEL_TYPE ==SSD1306_128x64) ctx->type = SSD1306_128x64; ctx->buffer = zalloc(1024); // 128 * 64 / 8 ctx->width = 128; ctx->height = 64; #elif (PANEL1_PANEL_TYPE == SSD1306_128x32) ctx->type = SSD1306_128x32; ctx->buffer = zalloc(512); // 128 * 32 / 8 ctx->width = 128; ctx->height = 32; #else #error "Unknown Panel 1 type" #endif if (ctx->buffer == NULL) { dmsg_err_puts("Alloc OLED buffer failed."); goto oled_init_fail; } ctx->address = PANEL1_ADDR; #if PANEL1_USE_RST // Panel 1 reset PIN_FUNC_SELECT(PANEL1_RST_MUX, PANEL1_RST_FUNC); GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | PANEL1_RST_BIT); GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, PANEL1_RST_BIT); os_delay_us(10000); GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, PANEL1_RST_BIT); #endif #else dmsg_err_puts("Panel 1 not defined."); goto oled_init_fail; #endif } // Panel initialization // Try send I2C address check if the panel is connected i2c_start(); if (!i2c_write(ctx->address)) { i2c_stop(); dmsg_err_puts("OLED I2C bus not responding."); goto oled_init_fail; } i2c_stop(); // Now we assume all sending will be successful if (ctx->type == SSD1306_128x64) { _command(ctx->address, 0xae); // SSD1306_DISPLAYOFF _command(ctx->address, 0xd5); // SSD1306_SETDISPLAYCLOCKDIV _command(ctx->address, 0x80); // Suggested value 0x80 _command(ctx->address, 0xa8); // SSD1306_SETMULTIPLEX _command(ctx->address, 0x3f); // 1/64 _command(ctx->address, 0xd3); // SSD1306_SETDISPLAYOFFSET _command(ctx->address, 0x00); // 0 no offset _command(ctx->address, 0x40); // SSD1306_SETSTARTLINE line #0 _command(ctx->address, 0x20); // SSD1306_MEMORYMODE _command(ctx->address, 0x00); // 0x0 act like ks0108 _command(ctx->address, 0xa1); // SSD1306_SEGREMAP | 1 _command(ctx->address, 0xc8); // SSD1306_COMSCANDEC _command(ctx->address, 0xda); // SSD1306_SETCOMPINS _command(ctx->address, 0x12); _command(ctx->address, 0x81); // SSD1306_SETCONTRAST _command(ctx->address, 0xcf); _command(ctx->address, 0xd9); // SSD1306_SETPRECHARGE _command(ctx->address, 0xf1); _command(ctx->address, 0xdb); // SSD1306_SETVCOMDETECT _command(ctx->address, 0x30); _command(ctx->address, 0x8d); // SSD1306_CHARGEPUMP _command(ctx->address, 0x14); // Charge pump on _command(ctx->address, 0x2e); // SSD1306_DEACTIVATE_SCROLL _command(ctx->address, 0xa4); // SSD1306_DISPLAYALLON_RESUME _command(ctx->address, 0xa6); // SSD1306_NORMALDISPLAY } else if (ctx->type == SSD1306_128x32) { _command(ctx->address, 0xae); // SSD1306_DISPLAYOFF _command(ctx->address, 0xd5); // SSD1306_SETDISPLAYCLOCKDIV _command(ctx->address, 0x80); // Suggested value 0x80 _command(ctx->address, 0xa8); // SSD1306_SETMULTIPLEX _command(ctx->address, 0x1f); // 1/32 _command(ctx->address, 0xd3); // SSD1306_SETDISPLAYOFFSET _command(ctx->address, 0x00); // 0 no offset _command(ctx->address, 0x40); // SSD1306_SETSTARTLINE line #0 _command(ctx->address, 0x8d); // SSD1306_CHARGEPUMP _command(ctx->address, 0x14); // Charge pump on _command(ctx->address, 0x20); // SSD1306_MEMORYMODE _command(ctx->address, 0x00); // 0x0 act like ks0108 _command(ctx->address, 0xa1); // SSD1306_SEGREMAP | 1 _command(ctx->address, 0xc8); // SSD1306_COMSCANDEC _command(ctx->address, 0xda); // SSD1306_SETCOMPINS _command(ctx->address, 0x02); _command(ctx->address, 0x81); // SSD1306_SETCONTRAST _command(ctx->address, 0x2f); _command(ctx->address, 0xd9); // SSD1306_SETPRECHARGE _command(ctx->address, 0xf1); _command(ctx->address, 0xdb); // SSD1306_SETVCOMDETECT _command(ctx->address, 0x40); _command(ctx->address, 0x2e); // SSD1306_DEACTIVATE_SCROLL _command(ctx->address, 0xa4); // SSD1306_DISPLAYALLON_RESUME _command(ctx->address, 0xa6); // SSD1306_NORMALDISPLAY } // Save context ctx->id = id; _ctxs[id] = ctx; ssd1306_clear(id); ssd1306_refresh(id, true); _command(ctx->address, 0xaf); // SSD1306_DISPLAYON return true; oled_init_fail: if (ctx && ctx->buffer) free(ctx->buffer); if (ctx) free(ctx); return false; }
unsigned int SI7021::getHumidityBasisPoints() { byte humbytes[2]; _command(RH_READ, humbytes); long humraw = (long)humbytes[0] << 8 | humbytes[1]; return ((12500 * humraw) >> 16) - 600; }
void ICACHE_FLASH_ATTR ssd1306_refresh(uint8_t id, bool force) { oled_i2c_ctx *ctx = _ctxs[id]; uint8_t i,j; uint16_t k; uint8_t page_start, page_end; if (ctx == NULL) return; if (force) { if (ctx->type == SSD1306_128x64) { _command(ctx->address, 0x21); // SSD1306_COLUMNADDR _command(ctx->address, 0); // column start _command(ctx->address, 127); // column end _command(ctx->address, 0x22); // SSD1306_PAGEADDR _command(ctx->address, 0); // page start _command(ctx->address, 7); // page end (8 pages for 64 rows OLED) for (k = 0; k < 1024; k++) { i2c_start(); i2c_write(ctx->address); i2c_write(0x40); for (j = 0; j < 16; ++j) { i2c_write(ctx->buffer[k]); ++k; } --k; i2c_stop(); } } else if (ctx->type == SSD1306_128x32) { _command(ctx->address, 0x21); // SSD1306_COLUMNADDR _command(ctx->address, 0); // column start _command(ctx->address, 127); // column end _command(ctx->address, 0x22); // SSD1306_PAGEADDR _command(ctx->address, 0); // page start _command(ctx->address, 3); // page end (4 pages for 32 rows OLED) for (k = 0; k < 512; k++) { i2c_start(); i2c_write(ctx->address); i2c_write(0x40); for (j = 0; j < 16; ++j) { i2c_write(ctx->buffer[k]); ++k; } --k; i2c_stop(); } } } else { if ((ctx->refresh_top <= ctx->refresh_bottom) && (ctx->refresh_left <= ctx->refresh_right)) { page_start = ctx->refresh_top / 8; page_end = ctx->refresh_bottom / 8; _command(ctx->address, 0x21); // SSD1306_COLUMNADDR _command(ctx->address, ctx->refresh_left); // column start _command(ctx->address, ctx->refresh_right); // column end _command(ctx->address, 0x22); // SSD1306_PAGEADDR _command(ctx->address, page_start); // page start _command(ctx->address, page_end); // page end k = 0; for (i = page_start; i <= page_end; ++i) { for (j = ctx->refresh_left; j <= ctx->refresh_right; ++j) { if (k == 0) { i2c_start(); i2c_write(ctx->address); i2c_write(0x40); } i2c_write(ctx->buffer[i * ctx->width + j]); ++k; if (k == 16) { i2c_stop(); k = 0; } } } if (k != 0) // for last batch if stop was not sent i2c_stop(); } } // reset dirty area ctx->refresh_top = 255; ctx->refresh_left = 255; ctx->refresh_right = 0; ctx->refresh_bottom = 0; }
void glcd_Device::_set_brightness(uint8_t val) { _command(CMD_SET_VOLUME_FIRST); _command(CMD_SET_VOLUME_SECOND | (val & 0x3f)); }