void Color::applySettings(ResourceDescriptor settings) { std::vector<std::string> values = split(settings.getValue(), ','); if (values.size() == 3 || values.size() == 4) { setRed(std::stoi(values[0])); setGreen(std::stoi(values[1])); setBlue(std::stoi(values[2])); } if (values.size() == 4) { setAlpha(std::stoi(values[2])); } ResourceDescriptor sub = settings.getSubResource("Red"); if (isNotEmpty(sub.getValue())) { setRed(std::stoi(sub.getValue())); } sub = settings.getSubResource("Green"); if (isNotEmpty(sub.getValue())) { setGreen(std::stoi(sub.getValue())); } sub = settings.getSubResource("Blue"); if (isNotEmpty(sub.getValue())) { setBlue(std::stoi(sub.getValue())); } sub = settings.getSubResource("Alpha"); if (isNotEmpty(sub.getValue())) { setAlpha(std::stoi(sub.getValue())); } }
ClientAgent::ClientAgent(Client *c, QWidget *parent) : client(c), QDialog(parent), ui(new Ui::ClientAgent) { ui->setupUi(this); setWindowTitle(tr("Client")); if (client->red) { setRed(); } else { setGreen(); } // no need to configure ui->lineEdit_ip->setEnabled(false); ui->lineEdit_port->setEnabled(false); // not work before connection established ui->pushButton_tx->setEnabled(false); ui->pushButton_client_red_green->setEnabled(false); ui->lineEdit_tx->setEnabled(false); // inbox, not editable ui->plainTextEdit_rx->setEnabled(false); ui->plainTextEdit_rx->setStyleSheet("background-color: white;" "font: 24px;"); connect(client, SIGNAL(readed(QByteArray)), this, SLOT(onReaded(QByteArray))); connect(client, SIGNAL(setRed()), this, SLOT(setRed())); connect(client, SIGNAL(setGreen()), this, SLOT(setGreen())); }
void Color::setColor(float red, float green, float blue, float alpha) { setRed(red); setGreen(green); setBlue(blue); setAlpha(alpha); }
void CVX_Material::setColor(int red, int green, int blue, int alpha) { setRed(red); setGreen(green); setBlue(blue); setAlpha(alpha); }
bool Rgb::setSlotGreen(Number* const msg) { LCreal value = msg->getReal(); bool ok = setGreen( value ); if (!ok) std::cerr << "Rgb::setGreen: invalid entry(" << value << "), valid range: 0 to 1" << std::endl; return ok; }
void vTreeLEDControl::setBrightness(uint8_t bright) { brightness = bright; setRed(red); setGreen(green); setBlue(blue); }
void Color::set( Color c ) { setRed( c.getRed() ); setGreen( c.getGreen() ); setBlue( c.getBlue() ); setAlpha( c.getAlpha() ); }
Color::Color( const Colorf& source ) { setRed( convertColorFloatToByte(source.red()) ); setGreen( convertColorFloatToByte(source.green()) ); setBlue( convertColorFloatToByte(source.blue()) ); setAlpha( convertColorFloatToByte(source.alpha()) ); }
void Color::setColor(Color color) { setRed(color.getRed()); setGreen(color.getGreen()); setBlue(color.getBlue()); setAlpha(color.getAlpha()); }
void Color::set( float r, float g, float b, float a ) { setRed( r ); setGreen( g ); setBlue( b ); setAlpha( a ); }
void writeDijkstra(FILE * f, Graphe * G, Arete * sp) { // écriture du sommet src en vert fillCircle(f, BORDER + minX * coefA4x + (int) (G->sommets[G->s]->x * coefA4x), BORDER + minY * coefA4y + (int) (G->sommets[G->s]->y * coefA4y), DIAMETER + 0.5, 0.0, 1.0, 0.0); // écriture du sommet dest en rouge fillCircle(f, BORDER + minX * coefA4x + (int) (G->sommets[G->t]->x * coefA4x), BORDER + minY * coefA4y + (int) (G->sommets[G->t]->y * coefA4y), DIAMETER + 0.5, 1.0, 0.0, 0.0); // écriture du + court chemin reliant src à dest Arete * current = sp; while (current) { setGreen(f); setLineWidth(f, 1); drawLine(f, BORDER + minX * coefA4x + (int) (current->s1->x * coefA4x), BORDER + minY * coefA4y + (int) (current->s1->y * coefA4y), BORDER + minX * coefA4x + (int) (current->s2->x * coefA4x), BORDER + minY * coefA4y + (int) (current->s2->y * coefA4y)); /*drawCircle(f, BORDER + minX * coefA4x + (int) (current->s1->x * coefA4x), BORDER + minY * coefA4y + (int) (current->s1->y * coefA4y), DIAMETER); drawCircle(f, BORDER + minX * coefA4x + (int) (current->s2->x * coefA4x), BORDER + minY * coefA4y + (int) (current->s2->y * coefA4y), DIAMETER);*/ current = current->suivant; } }
int main(void) { init(); int red = 0,green = 0,blue = 255,delta = 5; //255 % delta == 0 while (1) { if(red < 255 && green == 0 && blue > 0) { red += delta; green = 0; blue -= delta; } else if(red > 0 && green < 255 && blue == 0) { red -= delta; green += delta; blue = 0; } else if(red == 0 && green > 0 && blue < 255) { red = 0; green -= delta; blue += delta; } setRed(red); setGreen(green); setBlue(blue); wait(50); } }
/*RGB Animations*/ void blinkGreen(int times) { for (int i = 0; i < times; i++) { setGreen(); delay(250); setBlack(); delay(250); } }
inline Colour& Colour::operator*=(const Colour& c) { setRed(this->_r*c._r); setGreen(this->_g*c._g); setBlue(this->_b*c._b); return *this; }
inline Colour& Colour::operator*=(double t) { setRed(_r*t); setGreen(_g*t); setBlue(_b*t); return *this; }
TestBoxNode::TestBoxNode(const QString& label, QColor color, bool sizeDependsOnParent) : Super{nullptr, TestBoxNode::getMetaData()} { setRed(color.red()); setGreen(color.green()); setBlue(color.blue()); setLabel(label); setSizeDependsOnParent(sizeDependsOnParent); }
void VehicleTrafficLight::goSequenceAnimationStep(Sequencer & sequencer, uint8_t step) { switch (step) { case 1: setYellow(); sequencer.nextWithDelay(VECHILE_GO_YELLOW_ms); break; case 2: setGreen(); break; } }
/*ESP8266 Methods*/ void connectToWifi() { setTeal(); if (wifi.joinAP(SSID, PASSWORD)) { wifiConnected = true; debugSerial2.print(F("Join AP success\r\n")); blinkGreen(3); setGreen(); } else { wifiConnected = false; debugSerial2.print(F("Join AP failure\r\n")); setRed(); } }
void ClientAgent::on_pushButton_client_red_green_clicked() { client->red = !client->red; if (client->red) { emit setRed(); client->writeRed(); } else { emit setGreen(); client->writeGreen(); } }
Color& Color::operator-=( const Color &n ) { int red = static_cast<int>( getRed() ) - static_cast<int>( n.getRed() ); int green = static_cast<int>( getGreen() ) - static_cast<int>( n.getGreen() ); int blue = static_cast<int>( getBlue() ) - static_cast<int>( n. getBlue() ); red = ( red < 0 ? 0 : red ); green = ( green < 0 ? 0 : green ); blue = ( blue < 0 ? 0 : blue ); setRed( static_cast<uint8_t>( red ) ); setGreen( static_cast<uint8_t>( green ) ); setBlue( static_cast<uint8_t>( blue ) ); return *this; }
bool ColorPicker::qt_invoke( int _id, QUObject* _o ) { switch ( _id - staticMetaObject()->slotOffset() ) { case 0: setColor((const QColor&)*((const QColor*)static_QUType_ptr.get(_o+1))); break; case 1: setRed((int)static_QUType_int.get(_o+1)); break; case 2: emitChange(); break; case 3: setGreen((int)static_QUType_int.get(_o+1)); break; case 4: setBlue((int)static_QUType_int.get(_o+1)); break; case 5: reset(); break; case 6: init(); break; default: return QGroupBox::qt_invoke( _id, _o ); } return TRUE; }
/*Arduino Methods*/ void doRGBPOST() { for (int i = 0; i < 5; i++) { setWhite(); delay(500); setBlack(); delay(500); } setRed(); delay(1000); setGreen(); delay(1000); setBlue(); delay(1000); setWhite(); }
void parse( const std::string& value ) { if ( value.length() != 7 && value.length() != 9 ) { return; // bad input } auto c = value.cbegin(); if ( *c != '#' ) { return; // bad input } if ( value.substr( 1, value.length()-1).find_first_not_of( "ABCDEF0123456789" ) != std::string::npos ) { return; // bad input } Color::ColorType colortype = Color::ColorType::RGB; IntType alpha = 255; IntType red = 255; IntType green = 255; IntType blue = 255; if ( value.length() == 9 ) { colortype = Color::ColorType::ARGB; alpha = getInt( value, 1 ); red = getInt( value, 3 ); green = getInt( value, 5 ); blue = getInt( value, 7 ); } else if ( value.length() == 7 ) { colortype = Color::ColorType::RGB; alpha = 255; red = getInt( value, 1 ); green = getInt( value, 3 ); blue = getInt( value, 5 ); } setAlpha( alpha ); setRed( red ); setGreen( green ); setBlue( blue ); setColorType( colortype ); }
void print_info_node(FILE *f, printinfo *p) { fp = f; setGreen(); fprintf(f, "%5s |", getCmdStr(p->cmd->instr.r.cmd)); /* for(int i = 0; i < p.cycle_issued; ++i) // fprintf(f, "%s", " "[MAX_PRINTABLE_DIGITS]); //up to 10 printable spaces ;) fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", " "); fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", "I "); for(int i = 0; i < p.stalls_ex; ++i) fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", " "); fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", "S "); for(int i = 0; i < p.stalls_ex; ++i) fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", " "); for(int i = 0; i < get_instr_ex_cycles(p.cmd); ++i) fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", "E "); if (p.cmd.type != BEQZ){ for(int i = 0; i < p.stalls_wb; ++i) fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", " "); fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", "S "); for(int i = 0; i < p.stalls_wb; ++i) fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", " "); fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", "WB "); } */ setBlue(); for(int i = 1; i < p->cycle_issued; ++i) fprintf(f, " "); fprintf(f, "%5s", " I "); setRed(); for(int i = 0; i < p->stalls_ex; ++i) fprintf(f, "%5s", " S "); setLPurple(); for(int i = 0; i < get_instr_ex_cycles(&p->cmd); ++i) fprintf(f, "%5s", " E "); setRed(); if (p->cmd->type != BEQZ){ for(int i = 0; i < p->stalls_wb; ++i) fprintf(f, "%5s", " S "); setLCyan(); fprintf(f, "%5s", " WB "); } fprintf(f, "\n"); }
// Main program: Counting on T1 int main( void ) { DDRB = 0xFF; // set PORTB for compare output timer1Init(); wait(100); while (1) { int delta = 1; setRed (0); // change some colors // RED for (int red = 0; red<=255; red+=delta) { setRed( red ); setBlue(255-red); // 8-bits PWM on pin OCR1a delta += 2; // progressive steps up wait(100); // delay of 100 ms (busy waiting) } for (int red = 255; red>=0; red-=delta) { setRed( red ); // 8-bits PWM on pin OCR1a setGreen(255-red); delta -= 2; // progressive steps down wait(100); // delay of 100 ms (busy waiting) } for (int green = 0; green<=255; green+=delta) { setGreen( 255-green ); setBlue(green); // 8-bits PWM on pin OCR1a delta += 2; // progressive steps up wait(100); // delay of 100 ms (busy waiting) } setRed( 0 ); delta = 1; wait(100); // RED for (int red = 0; red<=255; red+=delta) { setRed( red ); // 8-bits PWM on pin OCR1a p wait(100); // delay of 100 ms (busy waiting) } for (int red = 255; red>=0; red-=delta) { setRed( red ); // 8-bits PWM on pin OCR1a setGreen(255-red); delta -= 2; // progressive steps down wait(100); // delay of 100 ms (busy waiting) } // GREEN for (int gr = 0; gr<=255; gr+=delta) { setGreen(gr); wait(100); } for (int gr = 255; gr>=0; gr-=delta) { setGreen(gr); wait(100); } // BLUE for (int blue = 0; blue<=255; blue+=delta) { setBlue(blue); wait(100); } for (int blue = 255; blue>=0; blue-=delta) { setBlue(blue); wait(100); } // YELLOW // for (int yellow= 0; yellow<=255; yellow += delta) // . . . // WHITE // for (int white = 0; white<=255; white += delta) // . . . } }
void save_value(String sensorId, String value) { printCurTime(); value.replace(" ", ""); //Build a HTTP GET string to store the update // String URI_STRING = "GET /ping/"; String URI_STRING = "GET /u/"; URI_STRING += wifi.getApMac(); URI_STRING += "/"; URI_STRING += sensorId; URI_STRING += "?rv="; URI_STRING += value; URI_STRING += " HTTP/1.0\r\n\r\n"; // String URI_STRING = "GET /api/postvalue/?token="; // URI_STRING+=API_KEY; // URI_STRING += "&variable="; // URI_STRING += sensorId; // URI_STRING += "&value="; // URI_STRING += value; // URI_STRING += "\r\n\r\n"; debugSerial2.print(F("URI_STRING.length(): ")); debugSerial2.println(URI_STRING.length()); debugSerial2.print(F("URI_STRING: ")); debugSerial2.println(URI_STRING); char uriCharBuffer[URI_STRING_BUFFER_LENGTH]; memset(uriCharBuffer, 0, URI_STRING_BUFFER_LENGTH); URI_STRING.toCharArray(uriCharBuffer, URI_STRING_BUFFER_LENGTH); // uint8_t responseBuffer[256] = { 0 }; for (int i = 0; i < HTTP_RETRIES; i++) { debugSerial2.print(F("HTTP_RETRIES: ")); debugSerial2.print(i); printCurTime(); bool tcpEstablished = false; if (wifi.createTCP(HOST_NAME, HOST_PORT)) { tcpEstablished = true; debugSerial2.print(F("create tcp ok")); printCurTime(); } else { debugSerial2.print(F("create tcp err")); printCurTime(); setYellow(); if (i + 1 == HTTP_RETRIES) { wifiConnected = false; setRed(); } } if (wifiConnected && tcpEstablished) { bool httpGetOk = false; if (!httpGetOk) { wifi.send((const uint8_t*) uriCharBuffer, strlen(uriCharBuffer)); // uint32_t len = wifi.recv(responseBuffer, sizeof(responseBuffer), 10000); httpGetOk = wifi.recvHTTP( HTTP_REQ_TIMEOUT); } debugSerial2.print(F("httpGetOk: ")); debugSerial2.print(httpGetOk); printCurTime(); // if (len > 0) { // debugSerial2.print(F("Received:[")); // for (uint32_t i = 0; i < len; i++) { // debugSerial2.print((char) responseBuffer[i]); // } // debugSerial2.print(F("]\r\n")); // } else { // wifiConnected = false; // } if (httpGetOk) { setGreen(); checkAndReleaseConnection(); break; } else { setYellow(); checkAndReleaseConnection(); } calcAndDoDelay(i); } else { debugSerial2.print(F("Failed TCP connection test")); checkAndReleaseConnection(); printCurTime(); setYellow(); calcAndDoDelay(i); } } }
inline void setColor(const float& red, const float& green, const float& blue, const float& alpha) { setRed(red); setGreen(green); setBlue(blue); setAlpha(alpha); }
inline void setColor(const shared_ptr<ColorRGBA> color) { setRed(color->getRed()); setGreen(color->getGreen()); setBlue(color->getBlue()); setAlpha(color->getAlpha()); }
RGB::RGB(uint8_t red, uint8_t green, uint8_t blue) { setRed(red); setGreen(green); setBlue(blue); }
RGB::RGB(const RGB &color) { setRed(color.red); setGreen(color.green); setBlue(color.blue); }