// Apply all station bits // !!! This will activate/deactivate valves !!! void OpenSprinkler::apply_all_station_bits() { digitalWrite(PIN_SR_LATCH, LOW); byte bid, s, sbits; bool engage_booster = false; #if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284__) // old station bits static byte old_station_bits[MAX_EXT_BOARDS+1]; #endif // Shift out all station bit values // from the highest bit to the lowest for(bid=0;bid<=MAX_EXT_BOARDS;bid++) { if (status.enabled) sbits = station_bits[MAX_EXT_BOARDS-bid]; else sbits = 0; #if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284__) // check if any station is changing from 0 to 1 // take the bit inverse of the old status // and with the new status if ((~old_station_bits[MAX_EXT_BOARDS-bid]) & sbits) { engage_booster = true; } old_station_bits[MAX_EXT_BOARDS-bid] = sbits; #endif for(s=0;s<8;s++) { digitalWrite(PIN_SR_CLOCK, LOW); #if defined(OSPI) // if OSPi, use dynamically assigned pin_sr_data digitalWrite(pin_sr_data, (sbits & ((byte)1<<(7-s))) ? HIGH : LOW ); #else digitalWrite(PIN_SR_DATA, (sbits & ((byte)1<<(7-s))) ? HIGH : LOW ); #endif digitalWrite(PIN_SR_CLOCK, HIGH); } } #if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284__) if((hw_type==HW_TYPE_DC) && engage_booster) { DEBUG_PRINTLN(F("engage booster")); // boost voltage digitalWrite(PIN_BOOST, HIGH); delay(250); digitalWrite(PIN_BOOST, LOW); // enable boosted voltage for a short period of time digitalWrite(PIN_BOOST_EN, HIGH); digitalWrite(PIN_SR_LATCH, HIGH); delay(500); digitalWrite(PIN_BOOST_EN, LOW); } else { digitalWrite(PIN_SR_LATCH, HIGH); } #else digitalWrite(PIN_SR_LATCH, HIGH); #endif }
//<ID>, <TD01>, START ,<int: tag1>,<int: tag2>,<int: tag3>,<int: tag4> void Theft::TheftDetectionFunction(int id, int command){ DEBUG_PRINT("#In the TheftDetectionFunction with function : '"); DEBUG_PRINT(command); DEBUG_PRINT("' and with ID: "); DEBUG_PRINTLN(id); switch (command) { case START: rfid.RFIDFunctionSetup(); // Read and set rfid tag from serial rfid.RFID_ENABLED = 1; //button.BUTTON_ENABLED = 1; // Enables button this->THEFT_ENABLED = 1; break; case STOP: this->THEFT_ENABLED = 0; // Disable Theft Mode //button.BUTTON_ENABLED = 0; // Disable Button led.LEDFunctionSet(1,0); // Turn off LED rfid.RFID_ENABLED = 0; break; default: break; } }
void do_setup() { initialiseEpoch(); // initialize time reference for millis() and micros() os.begin(); // OpenSprinkler init os.options_setup(); // Setup options pd.init(); // ProgramData init if (os.start_network()) { // initialize network DEBUG_PRINTLN("network established."); os.status.network_fails = 0; } else { DEBUG_PRINTLN("network failed."); os.status.network_fails = 1; } os.status.req_network = 0; }
DHT::DHT(void) { _maxCycles = microsecondsToClockCycles(DHT_MAX_CYCLES); _lastTemperature = _lastHumidity = 0; ADD_BIT(_status, STATUS_TEMP_GOOD | STATUS_HUMI_GOOD); DEBUG_PRINTLN("DHT loaded."); }
int64_t WallOverlapComputation::overlapEndingDistance(Point& a1, Point& a2, Point& b1, Point& b2, int a1b1_dist) { int overlap = lineWidth - a1b1_dist; Point a = a2-a1; Point b = b2-b1; double cos_angle = INT2MM2(dot(a, b)) / vSizeMM(a) / vSizeMM(b); // result == .5*overlap / tan(.5*angle) == .5*overlap / tan(.5*acos(cos_angle)) // [wolfram alpha] == 0.5*overlap * sqrt(cos_angle+1)/sqrt(1-cos_angle) // [assuming positive x] == 0.5*overlap / sqrt( 2 / (cos_angle + 1) - 1 ) if (cos_angle <= 0) { return 0; } else { int64_t dist = overlap * double ( 1.0 / (2.0 * sqrt(2.0 / (cos_angle+1.0) - 1.0)) ); if (dist * dist > vSize2(a) || dist * dist > vSize2(b)) { return 0; DEBUG_PRINTLN("ERROR! overlap end too long!! "); } return dist; } }
void UPnPDeviceWiFiSwitch::onSetSwitchState(bool bState) { DEBUG_PRINT("Request state is "); DEBUG_PRINT(String(bState)); DEBUG_PRINTLN(""); mSwitchStatus = bState ? true : false; }
// Function called in void setup() that instantiates all the variables, attaches pins, ect // This funciton needs to be called before anything else will work void Communicator::initialize() { pinMode(TX_TO_DISCONNECT, INPUT); // Ensure it's in high impedance state pinMode(RX_TO_DISCONNECT, INPUT); // Ensure it's in high impedance state #ifdef DEBUG_COMMUNICATOR SerialUSB.begin(SERIAL_USB_BAUD); // This is to computer DEBUG_PRINTLN("at start of comm initialize"); #endif // Set initial values to 0 altitude = 0; //roll = 0; pitch = 0; altitudeAtDrop = 0; // Start without hardware attached dropBayAttached = 0; // Initialize serial commuication to Xbee. XBEE_SERIAL.begin(XBEE_BAUD); //this is to Xbee //Setup the GPS setupGPS(); }
void loop() { if (Serial) { if (!serialConnected) { serialConnected = true; DEBUG_PRINT(F("LongName: ")); DEBUG_PRINTLN(BleLongName); } } else { if (serialConnected) serialConnected = false; } // poll peripheral blePeripheral.poll(); if (valueCharacteristic.subscribed()) { int sensorValue = 0; if (pin_type == ANALOG) { sensorValue = analogRead(pin); } else if (pin_type == DIGITAL) { sensorValue = digitalRead(pin); } else { sensorValue = 666; } send_data(valueCharacteristic, millis(), sensorValue); } #ifdef GOOSCI_DEVELOPER_MODE heartbeat(); #endif }
bool NeoClock::process( bool changingModes ) { _wheel.setPixelColor(sec, 0); _wheel.setPixelColor(min, 0); _wheel.setPixelColor(hr, 0); sec = _currentTime.second() / 5; min = _currentTime.minute() / 5; hr = _currentTime.hour() % 12; _wheel.setPixelColor(sec, _secColor); _wheel.setPixelColor(min, _minColor); _wheel.setPixelColor(hr, _hrColor); if ( sec == min && sec == hr ) _wheel.setPixelColor(sec, _secColor | _minColor | _hrColor ); else if ( sec == min ) _wheel.setPixelColor(sec, _secColor | _minColor); else if ( sec == hr ) _wheel.setPixelColor(sec, _secColor | _hrColor); else if ( min == hr ) _wheel.setPixelColor(min, _minColor | _hrColor); _wheel.checkColorChange(); _wheel.setBrightness(_wheel.brightnessIndexValue); _wheel.show(); #ifdef DEBUG DEBUG_PRINTTIME( _currentTime ); DEBUG_PRINTLN(""); #endif return false; }
sharedarray<float> monomial_gradient::eval(float x, float y) { float * grad_val = new float[2]{0.0f, 0.0f}; if (this->x_exp > 0 && this->y_exp > 0) { // at least x*y grad_val[0] = this->x_exp * std::pow(x, this->x_exp - 1) * std::pow(y, this->y_exp); //<=> grad_val[1] = std::pow(x, this->x_exp) * this->y_exp * std::pow(y, this->y_exp - 1); //<=> } else if (this->x_exp == 0 && this->y_exp == 0) { //x^0y^0 => nothing to derive here grad_val[0] = 0.f; grad_val[1] = 0.f; } else if (this->x_exp > 0) { //x^n * y^0 => x^n grad_val[0] = this->x_exp * std::pow(x, this->x_exp - 1); //y^0 => 1 grad_val[1] = 0.f; } else if (this->y_exp > 0) { //x^0 * y^m => y^m grad_val[0] = 0.f; grad_val[1] = this->y_exp * std::pow(y, this->y_exp - 1); } else { //there is no other case :) DEBUG_PRINTLN("The impossible has happened in " << __FILE__ << " in " << __LINE__); } sharedarray<float> gradient(grad_val); return gradient; }
uint8_t Adafruit_MQTT::subscribePacket(uint8_t *packet, const char *topic, uint8_t qos) { uint8_t *p = packet; uint16_t len; p[0] = MQTT_CTRL_SUBSCRIBE << 4 | MQTT_QOS_1 << 1; // fill in packet[1] last p+=2; // put in a message id, p[0] = 0xAD; p[1] = 0xAF; p+=2; p = stringprint_P(p, topic); p[0] = qos; p++; len = p - packet; packet[1] = len-2; // don't include the 2 bytes of fixed header data DEBUG_PRINTLN(F("MQTT subscription packet:")); DEBUG_PRINTBUFFER(buffer, len); return len; }
uint8_t Adafruit_MQTT::pingPacket(uint8_t *packet) { packet[0] = MQTT_CTRL_PINGREQ << 4; packet[1] = 0; DEBUG_PRINTLN(F("MQTT ping packet:")); DEBUG_PRINTBUFFER(buffer, 2); return 2; }
void setup() { wait_for_serial(); // set the local name peripheral advertises blePeripheral.setLocalName("Initial"); // set the UUID for the service this peripheral advertises: blePeripheral.setAdvertisedServiceUuid(whistlepunkService.uuid()); // add service and characteristics blePeripheral.addAttribute(whistlepunkService); blePeripheral.addAttribute(valueCharacteristic); blePeripheral.addAttribute(configCharacteristic); blePeripheral.addAttribute(versionCharacteristic); versionCharacteristic.setValue(version); // assign event handlers for connected, disconnected to peripheral blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler); blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); valueCharacteristic.setEventHandler(BLESubscribed, bleNotificationSubscribeHandler); valueCharacteristic.setEventHandler(BLEUnsubscribed, bleNotificationUnsubscribeHandler); configCharacteristic.setEventHandler(BLEWritten, bleConfigChangeHandler); ble_addr_t _local_bda; char _device_name[BLE_MAX_DEVICE_NAME+1]; ble_client_get_factory_config(&_local_bda, _device_name); sprintf(BleLongName, "Sci%02x%02x", _local_bda.addr[0], _local_bda.addr[1]); DEBUG_PRINT("Address is: "); DEBUG_PRINTLN(BleLongName); blePeripheral.setLocalName(BleLongName); // advertise the service blePeripheral.begin(); }
/************************************************************************** * * Update the long name (20 characters or less!) * **************************************************************************/ void GoosciBleGatt::setLongName(const char *newName) { if (strlen(newName) > BTLE_BUFFER_SIZE - 1) { DEBUG_PRINTLN(F("Name too long; new name was not set. ")); return; } else { strcpy(longName, newName); } }
/************************************************************************** * * Update the device name (7 characters or less!) * **************************************************************************/ void GoosciBleGatt::setDeviceName(const char *newName) { if (strlen(newName) > BTLE_DEVICE_NAME_SIZE - 1) { DEBUG_PRINTLN(F("Device name too long; new name was not set. ")); return; } else { strcpy(deviceName, newName); } }
void Display::showTelemetry(Receiver *receiver) { if (telemetrySattelites == receiver->lastSeenSatellites() || telemetryFix == receiver->haveFix()) { return; } telemetryFix = receiver->haveFix(); telemetrySattelites = receiver->lastSeenSatellites(); if (!receiver->haveFix()) { DEBUG_PRINTLN("Telemetry waiting for gps fix"); } DEBUG_PRINT("Telemetry sat:"); DEBUG_PRINTLN(telemetrySattelites); }
void master_cylinder_close( void ) { cli(); analogWrite( PIN_MASTER_CYLINDER_SOLENOID, SOLENOID_PWM_ON ); sei(); DEBUG_PRINTLN( "Master Cylinder Close" ); }
void master_cylinder_open( void ) { cli(); analogWrite( PIN_MASTER_CYLINDER_SOLENOID, SOLENOID_PWM_OFF ); sei(); DEBUG_PRINTLN( "Master Cylinder Open" ); }
void GoosciBleGatt::print_address(void) { get_address(); #ifdef GIT_COMMIT_HASH DEBUG_PRINT(F("Firmware version: ")); DEBUG_PRINTLN(F(GIT_COMMIT_HASH)); #endif #ifdef JENKINS_BUILD_ID DEBUG_PRINT(F("Jenkins build id: ")); DEBUG_PRINTLN(F(JENKINS_BUILD_ID)); #endif DEBUG_PRINT(F("DeviceName: ")); DEBUG_PRINTLN(deviceName); DEBUG_PRINT(F("DeviceDesc: ")); DEBUG_PRINTLN(deviceDesc); DEBUG_PRINT(F("LongName: ")); DEBUG_PRINTLN(longName); }
Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) { uint8_t i, topiclen, datalen; // Check if data is available to read. uint16_t len = readPacket(buffer, MAXBUFFERSIZE, timeout, true); // return one full packet if (!len) return NULL; // No data available, just quit. DEBUG_PRINTBUFFER(buffer, len); // Parse out length of packet. topiclen = buffer[3]; DEBUG_PRINT(F("Looking for subscription len ")); DEBUG_PRINTLN(topiclen); // Find subscription associated with this packet. for (i=0; i<MAXSUBSCRIPTIONS; i++) { if (subscriptions[i]) { // Skip this subscription if its name length isn't the same as the // received topic name. if (strlen_P(subscriptions[i]->topic) != topiclen) continue; // Stop if the subscription topic matches the received topic. Be careful // to make comparison case insensitive. if (strncasecmp_P((char*)buffer+4, subscriptions[i]->topic, topiclen) == 0) { DEBUG_PRINT(F("Found sub #")); DEBUG_PRINTLN(i); break; } } } if (i==MAXSUBSCRIPTIONS) return NULL; // matching sub not found ??? // zero out the old data memset(subscriptions[i]->lastread, 0, SUBSCRIPTIONDATALEN); datalen = len - topiclen - 4; if (datalen > SUBSCRIPTIONDATALEN) { datalen = SUBSCRIPTIONDATALEN-1; // cut it off } // extract out just the data, into the subscription object itself memcpy(subscriptions[i]->lastread, buffer+4+topiclen, datalen); subscriptions[i]->datalen = datalen; DEBUG_PRINT(F("Data len: ")); DEBUG_PRINTLN(datalen); DEBUG_PRINT(F("Data: ")); DEBUG_PRINTLN((char *)subscriptions[i]->lastread); // return the valid matching subscription return subscriptions[i]; }
/** * Die Helligkeit des Displays anpassen. * * @param brightnessInPercent Die Helligkeit. */ void LedDriverUeberPixel::setBrightness(unsigned int brightnessInPercent) { if(_brightness != brightnessInPercent) { _brightness = brightnessInPercent; DEBUG_PRINT(F("MAX7219: Brightness: ")); DEBUG_PRINTLN(_brightness); DEBUG_FLUSH(); byte val = map(_brightness, 0, 100, 1, 15); DEBUG_PRINT(F(" val: ")); DEBUG_PRINTLN(val); DEBUG_FLUSH(); for(byte i = 0; i < 4; i++) { _ledControl->setIntensity(i, val); } } }
//======================================================== // servo_get_target gets position of servo to target // target is 4 times the value of the pulse width in usec //======================================================== uint16_t servo_get_target(uint8_t servo){ if (servo_debug) DEBUG_PRINT("In servo_get_target, servo: "); if (servo_debug) DEBUG_PRINT(servo); if (servo_debug) DEBUG_PRINT(", servo + first_servo: "); if (servo_debug) DEBUG_PRINT(servo + first_servo); if (servo_debug) DEBUG_PRINTLN(); return maestro.getPosition(servo + first_servo); // servos before first_servo are inputs } // end servo_get_target
//======================================================== // servo_set_angles sets all servos to a specified angles // the angles are specified in radians *2^14 // this routine should take into account offsets and non-linearities //======================================================== void servo_set_angles(float radian[NUM_LEGS][NUM_JOINTS_LEG]){ if (servo_debug) DEBUG_PRINTLN("In servo_set_angles"); for(uint8_t leg=0; leg<NUM_LEGS; leg++){ for(uint8_t joint=0; joint<NUM_JOINTS_LEG; joint++){ servo_set_angle((leg * NUM_JOINTS_LEG) + joint, radian[leg][joint]); } } } // end servo_set_angles
int HC05::cmd(const char* cmd, unsigned long timeout) { int recvd = 0; DEBUG_PRINTLN(cmd); setCmdPin(HIGH); // No spec for how long it takes to enter command mode, but 100ms // seems to work- assuming the output has been drained. delay(100); _btSerial.write(cmd); _btSerial.write("\r\n"); _btSerial.setTimeout(timeout); do { // ATTENTION: At least through Arduino v1.0.3, it is not possible // to tell the difference between a timeout and // receiving only the termination character (NL in this // case), because the termination character is not // returned and timeout is not returned as a unique // indication. // In this case the result would be an early return // of a multiline response before the OK is received. // The return would incorrectly indicate an error (no // OK response). recvd = _btSerial.readBytesUntil('\n',_buffer,_bufsize); if (recvd > 0) { DEBUG_WRITE((uint8_t *)_buffer,recvd); DEBUG_WRITE('\n'); } else { DEBUG_PRINTLN("timeout 1"); } } while ((recvd > 0) && (_buffer[0] != 'O' || _buffer[1] != 'K')); setCmdPin(LOW); // Empirically determined that it takes some time to reliably exit // command mode. The appeared to be a baud rate dependency and with // >100ms required at 9600 baud. delay(150); return((_buffer[0] == 'O' && _buffer[1] == 'K')); }
/** * Eine Sekunde startet. Muss von einem externen * Zeitgeber, z. B. einer RTC, aufgerufen werden. * * Zurueckgegeben wird ein Wahrheitswert. * TRUE bedeutet, das Zeittelegramm wurde korrekt ausgewertet, die Zeitdaten * koennen mit den Gettern abgerufen werden. * FALSE bedeutet, die Auswertung laeuft oder war falsch, die Getter liefern * alte Informationen. */ boolean MyDCF77::newSecond() { boolean retVal = false; if (_highcount != 0) { // Daten _meanvalues[_meanpointer] = _highcount; _meanpointer++; if (_meanpointer > MYDCF77_MEANCOUNT) { _meanpointer = 0; } unsigned long average = 0; for (byte i = 0; i < MYDCF77_MEANCOUNT; i++) { average += _meanvalues[i]; } average /= MYDCF77_MEANCOUNT; DEBUG_PRINT(F("average = ")); DEBUG_PRINT(average); DEBUG_PRINT(F("; highcount = ")); DEBUG_PRINT(_highcount); if (_highcount > average) { _bits[_bitsPointer] = 1; DEBUG_PRINTLN(F("; HIGH")); } else { _bits[_bitsPointer] = 0; DEBUG_PRINTLN(F("; LOW")); } _bitsPointer++; if (_bitsPointer > MYDCF77_TELEGRAMMLAENGE) { _bitsPointer = 0; } } else { // Pause DEBUG_PRINTLN(F("PAUSE")); retVal = decode(); _bitsPointer = 0; clearBits(); } _highcount = 0; return retVal; }
void f_systemBootSetupAP(WiFiMode_t wifiMode) { String st; WiFi.mode(wifiMode); // WiFi.disconnect(); delay(100); int n = WiFi.scanNetworks(); DEBUG_PRINTLN("scan done"); if (n == 0) DEBUG_PRINTLN("no networks found"); else { DEBUG_PRINT(n); DEBUG_PRINTLN(" networks found"); for (int i = 0; i < n; ++i) { // Print SSID and RSSI for each network found DEBUG_PRINT(i + 1); DEBUG_PRINT(": "); DEBUG_PRINT(WiFi.SSID(i)); DEBUG_PRINT(" ("); DEBUG_PRINT(WiFi.RSSI(i)); DEBUG_PRINT(")"); DEBUG_PRINTLN((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*"); delay(10); } } DEBUG_PRINTLN(""); st = "<ul>"; for (int i = 0; i < n; ++i) { // Print SSID and RSSI for each network found st += "<li>"; st +=i + 1; st += ": "; st += WiFi.SSID(i); st += " ("; st += WiFi.RSSI(i); st += ")"; st += (WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*"; st += "</li>"; } st += "</ul>"; delay(100); #ifdef D_SYS_BOOT_WIFI_AP_PASSWD WiFi.softAP(D_SYS_BOOT_WIFI_AP_SSID_DEFAULT, D_SYS_BOOT_WIFI_AP_PASSWD); #else WiFi.softAP(D_SYS_BOOT_WIFI_AP_SSID_DEFAULT); #endif DEBUG_PRINTLN("softap"); DEBUG_PRINTLN(""); if (f_SystemBootLaunchApServer_p != NULL) f_SystemBootLaunchApServer_p(st); DEBUG_PRINTLN("over"); }
FeedData::FeedData(Stream& stream, uint16_t length, uint32_t timeoutMS) { // Load the data value from the provided stream. Will read a value up to // length characters in size. If the data can't be read for some reason, // like the timeout exceeding, then the FeedData will be left in an invalid // state. memset(_value, 0, sizeof(_value)); if (length > FEEDDATA_LENGTH-1) { // Not enough space to store the value. DEBUG_PRINTLN(F("Not enough space to store feed data!")); return; } stream.setTimeout(timeoutMS); if (stream.readBytes(_value, length) != length) { // Didn't find enough data, set the value as invalid. DEBUG_PRINTLN(F("Failed to find expected data!")); memset(_value, 0, sizeof(_value)); } }
void DHT::begin(void) { // set up the pins! pinMode(_pin, INPUT_PULLUP); // Using this value makes sure that millis() - lastreadtime will be // >= MIN_INTERVAL right away. Note that this assignment wraps around, // but so will the subtraction. _lastreadtime = -MIN_INTERVAL; DEBUG_PRINT("Max clock cycles: "); DEBUG_PRINTLN(_maxcycles, DEC); }
void OLED::print(char *s, uint8_t r, uint8_t c) { DEBUG_PRINT("print "); DEBUG_PRINT(r); DEBUG_PRINT(","); DEBUG_PRINT(c); DEBUG_PRINT(" "); DEBUG_PRINTLN(s); sendStrXY(s, r, c); }
/************************************************************************** * * Set the device description (20 characters or less!). * This is the place to store the long name. * **************************************************************************/ void GoosciBleGatt::setDeviceDescription(const char *desc) { // Set the value of the description characteristic. if (strlen(desc) > BTLE_BUFFER_SIZE - 1) { DEBUG_PRINTLN(F("Description too long; new description was not set.")); return; } else { strcpy(deviceDesc, desc); } }