/** * Get the PWM value directly from the hardware. * * Read a raw value from a PWM channel. * * @return Raw PWM control value. */ unsigned short PWM::GetRaw() const { if (StatusIsFatal()) return 0; int32_t status = 0; unsigned short value = getPWM(m_pwm_ports[m_channel], &status); wpi_setErrorWithContext(status, getHALErrorMessage(status)); return value; }
int writeDatalink(float frequency){ if (time - lastTime > frequency) { lastTime = time; struct telem_block* statusData = getDebugTelemetryBlock();//createTelemetryBlock(); if (statusData == 0){ return 0; } statusData->lat = getLatitude(); statusData->lon = getLongitude(); statusData->millis = getUTCTime(); statusData->groundSpeed = getSpeed(); statusData->heading = getHeading(); statusData->lastCommandSent = lastCommandSentCode; statusData->errorCodes = getErrorCodes(); statusData->gpsStatus = (char)(getSatellites() + (isGPSLocked() << 4)); statusData->steeringSetpoint = getPWM(1); statusData->throttleSetpoint = getPWM(2); statusData->steeringOutput = sData; statusData->throttleOutput = tData; statusData->debugChar = debugChar; statusData->debugInt = debugInt; statusData->debugFloat = debugFloat; if (BLOCKING_MODE) { sendTelemetryBlock(statusData); destroyTelemetryBlock(statusData); } else { return pushOutboundTelemetryQueue(statusData); } } else if (time < lastTime){ lastTime = time; return 0; } return 0; }
void Send_MotoPWM(void) { u8 _cnt=0; u8 i; uint16_t Moto_PWM[6]; u8 sum = 0; getPWM(Moto_PWM); for(i=0;i<6;i++) Moto_PWM[i] -= 1000; data_to_send[_cnt++]=0xAA; data_to_send[_cnt++]=0xAA; data_to_send[_cnt++]=0x06; data_to_send[_cnt++]=0; data_to_send[_cnt++]=BYTE1(Moto_PWM[1]); data_to_send[_cnt++]=BYTE0(Moto_PWM[1]); data_to_send[_cnt++]=BYTE1(Moto_PWM[3]); data_to_send[_cnt++]=BYTE0(Moto_PWM[3]); data_to_send[_cnt++]=BYTE1(Moto_PWM[5]); data_to_send[_cnt++]=BYTE0(Moto_PWM[5]); data_to_send[_cnt++]=BYTE1(Moto_PWM[2]); data_to_send[_cnt++]=BYTE0(Moto_PWM[2]); data_to_send[_cnt++]=BYTE1(Moto_PWM[0]); data_to_send[_cnt++]=BYTE0(Moto_PWM[0]); data_to_send[_cnt++]=BYTE1(Moto_PWM[4]); data_to_send[_cnt++]=BYTE0(Moto_PWM[4]); data_to_send[3] = _cnt-4; for(i=0;i<_cnt;i++) sum += data_to_send[i]; data_to_send[_cnt++]=sum; Send_Data(data_to_send, _cnt); }
char getReg(uint16_t reg, int* val) { if (reg >= REG_RELAY0 && reg < REG_RELAY0 + REG_RELAY_CNT) { *val = getOutput(reg - REG_RELAY0) ? 1 : 0; } else if (reg >= REG_PWM0 && reg < REG_PWM0 + REG_RELAY_CNT) { *val = getPWM(reg - REG_PWM0); } else if (reg == REG_TEMP) { *val = w1_temp(0); if (*val == TEMPERATURE_INVALID) return 0; } else if (reg == REG_ADC_CONF) { *val = EEPROM_readByte(&eeData.adcconf); } else if (reg == REG_RESET_BY_WD) { *val = EEPROM_readByte(&eeData.resetByWd); } else if (reg == REG_WD_ON_RECEIVE) { *val = EEPROM_readByte(&eeData.wdOnReceive); } else if (reg == REG_TIME_CORR_EN) { *val = EEPROM_readByte(&eeData.timeCorrEn); } else if (reg == REG_TIME_CORR) { *val = getCorr1(); } else if (reg == REG_TIME_HI) { timeBuffer = getTime(); *val = timeBuffer >> 16; } else if (reg == REG_TIME_LO) {
int8_t DigitalOutput::showWebinterface(WebServer* server, WebServer::ConnectionType type, char* url) { #ifdef PROVIDE_WEBIF File templateFile; TemplateParser* parser; int16_t matchIdx; char templateFileName[template_digitaloutput_fnsize]; strcpy_P(templateFileName, template_digitaloutput_fname); float dC = -1.0; if (type == WebServer::POST) { int8_t repeat; char name[16], value[16]; do { repeat = server->readPOSTparam(name, 16, value, 16); if (strcmp_P(name, (PGM_P) pgm_read_word(&(template_digitaloutput_inputs[DO_I_ON]))) == 0) { m_OnValue = atoi(value); m_OffValue = 1 - m_OnValue; } else if (strcmp_P(name, (PGM_P) pgm_read_word(&(template_digitaloutput_inputs[DO_I_PIN]))) == 0) { m_Pin = atoi(value); pinMode(m_Pin, OUTPUT); } else if (strcmp_P(name, (PGM_P) pgm_read_word(&(template_digitaloutput_inputs[DO_I_PWM]))) == 0) { dC = atof(value); if (dC < 0.0) dC = 0; else if (dC > 100.0) dC = 100.0; dC /= 100; } } while (repeat); if (dC >= 0) setPWM(dC); server->httpSeeOther(this->m_URL); } else { server->httpSuccess(); parser = __aquaduino->getTemplateParser(); templateFile = SD.open(templateFileName, FILE_READ); while ((matchIdx = parser->processTemplateUntilNextMatch(&templateFile, template_digitaloutput, template_digitaloutput_elements, server)) >= 0) { switch (matchIdx) { case DO_ANAME: server->print(getName()); break; case DO_PIN_NAME: server->print((const __FlashStringHelper *) (pgm_input_pin)); break; case DO_PIN_VAL: server->print(m_Pin); break; case DO_PIN_SIZE: server->print(3); break; case DO_PIN_MAXLENGTH: server->print(2); break; case DO_PWM_NAME: server->print((const __FlashStringHelper *) (pgm_input_pwm)); break; case DO_PWM_VAL: if (supportsPWM()) { server->print(getPWM() * 100); } else { server->print(F("No PWM")); } break; case DO_PWM_SIZE: server->print(7); break; case DO_PWM_MAXLENGTH: server->print(6); break; case DO_ON_NAME: server->print((const __FlashStringHelper *) (pgm_input_on)); break; case DO_ON_OPTIONS: parser->selectListOption("LOW", "0", m_OnValue == 0, server); parser->selectListOption("HIGH", "1", m_OnValue == 1, server); break; } } templateFile.close(); } #endif //PROVIDE_WEBIF return true; }