AppWindow::AppWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::AppWindow) { main_all_groups_window = new AllGroups(); group_info_window = new GroupInfo(this); main_login_window = new LoginWindow(this); myAppWindow = new AppWindowData(); this->setFixedSize(900, 600); connect(this, SIGNAL(sendGroupID(QString)), group_info_window, SLOT(setLabelText(QString))); ui->setupUi(this); addItemsToCourseNameComboBox(); resetRowCount(); setColumnsOfTable(); main_login_window->show(); QHeaderView* header = ui->listOfAllGroups->horizontalHeader(); header->setSectionResizeMode(QHeaderView::Stretch); web_interface = HTTPInterface::getInstance(); ui->deleteButton->hide(); ui->userdeleteButton_2->hide(); ui->adminprivButton->hide(); ui->userlistbox->hide(); }
//Deals with incoming Serial Messages boolean Ospom::incomingUSBmsg(void) { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // add it to the inputString: InputString += inChar; // if the incoming character is a '!', see who it's for if (inChar == '!') { String GroupIDIn = ""; for (int i = 0; i<= 7; i++) { //Read the ID char inChar = InputString.charAt(i); GroupIDIn += inChar; } if (GroupIDIn == GroupID) { //If the ID from serial matches the ID from eeprom if (SendData) { Pause = true; //if it's sending continuous data, stop for a bit } //decide what kind of message it is if ((InputString.charAt(8) == 's') || (InputString.charAt(8) == 'a')) { ElementCommand = true; stringcomplete = true; elementParse(); } else if (((InputString.charAt(8) - '0') >= 0) && ((InputString.charAt(8) - '0') <=9)) { groupCommand = true; stringcomplete = true; } else { fail(); } } else if ((InputString.charAt(0) == '0') && (InputString.length() == 2)) { sendGroupID(); } else { fail(); //Return a -1 } GroupIDIn = ""; } } return stringcomplete; }
//This is the main function that gets called from the Arduino program void Ospom::Run(int SensorReadDelayMS) { //Having these written out twice as const int's saves a lot of RAM const int EEPIDLoc[23] = {9,28,47,66,85,104,123,142,161,180,199,218,237,256,275,294,313,332,351,370}; //Location of Element Type (Sensor, actuator, nothing) const int EEPTypLoc[23] = {17,36,55,74,93,112,131,150,169,188,207,226,245,264,283,302,321,340,359,378}; //Location of Element Function (Analog Read, Digital Read, Analog Write, ect) const int EEPFuncLoc[23] = {18,37,56,75,94,113,132,151,170,189,208,227,246,265,284,303,322,341,360,379}; //Location of Element Slope(if sensor) or Fail Safe(if actuator) value const int EEPSlopeFSLoc[23] = {20,39,58,77,96,115,134,153,172,191,210,229,248,267,286,305,324,343,362,381}; //Location of Element Y-intercept(if sensor) or Extra(if actuator) const int EEPYintExLoc[23] = {24,43,62,81,100,119,138,157,176,195,214,233,252,271,290,309,328,347,366,385}; unsigned long TimeNow = 0; static unsigned long SensorStreamStartTime; static unsigned long LastMeasurement; static unsigned long LastSend; static unsigned int SendDelay; if (TriacDimming) { triacDimming(); } if (incomingUSBmsg()) { if (groupCommand) { //Do Group Command Stuff switch (groupCommandVal()) { case 0: sendGroupID(); break; case 10: sendSensorData(); break; case 11: SendDelay = GroupCommandInt; //Grab the time in milliseconds SensorStreamStartTime = millis(); //to delay before sending again SendData = true; break; case 13: sendActuatorData(); break; case 17: watchDog(); break; case 18: setGroupID(); break; default: fail(); break; } } //Element Command Section accepts commands and takes action else if (ElementCommand) { //Store the Element ID we are working with in a temporary variable char ElementID[9] = " "; //A temporary Variable for the ELement ID EEPROM.readBlock<char>(EEPIDLoc[ElementNumber], ElementID, 8); //Reads the Element ID from EEPROM //Do what the command Character says if (ElementCommandChar == 'R') { //Read the element value, and send it back to the odroid Serial.print(GroupID); Serial.print("/"); Serial.print(ElementID); Serial.print(":"); Serial.println(ElementCalVal[ElementNumber]); } else if (ElementCommandChar == 'I') { //Change the Elements ID EEPROM.updateBlock<char>(EEPIDLoc[ElementNumber], CommandCharArray, 8); success(); } else if (ElementCommandChar == 'T') { //Change the Elements Type (s = sensor, a = actuator, n = nothing, z=SetBy EEPROM Loader Program) EEPROM.write(EEPTypLoc[ElementNumber],CommandCharArray[0]); ElementType[ElementNumber] = EEPROM.read(EEPTypLoc[ElementNumber]); success(); } else if (ElementCommandChar == 'C') { //Change the Elements Function (0=unused, 1=analogRead, 2=digitalRead, 3=analogWrite, // 4=digitalWrite, 5=Triac, 10=SetBy EEPROM Loader Program) EEPROM.updateInt(EEPFuncLoc[ElementNumber], ElementCommandInt); ElementFunction[ElementNumber] = EEPROM.readInt(EEPFuncLoc[ElementNumber]); success(); } else if (ElementCommandChar == 'A') { //Read the Element Type and Send it back to the odroid Serial.print(GroupID); Serial.print("/"); Serial.print(ElementID); Serial.print(":"); Serial.println(ElementType[ElementNumber]); } else if (ElementCommandChar == 'D') { //Read the Element Function and Send it back to the odroid Serial.print(GroupID); Serial.print("/"); Serial.print(ElementID); Serial.print(":"); Serial.println(ElementFunction[ElementNumber]); } else if (ElementCommandChar == 'M') { //Change the Elements Calibration Slope EEPROM.updateFloat(EEPSlopeFSLoc[ElementNumber], ElementCommandFloat); //Save value to EEPROM); ElementSlopeFS[ElementNumber] = ElementCommandFloat; success(); } else if (ElementCommandChar == 'B') { //Change the Elements Calibration Slope EEPROM.updateFloat(EEPYintExLoc[ElementNumber], ElementCommandFloat); //Save value to EEPROM); ElementYintEx[ElementNumber] = ElementCommandFloat; success(); } else if (ElementCommandChar == 'W') { //Write (Set) the Actuator if (ElementType[ElementNumber] == 'a') { //Make sure it's an actuator (so we don't break sensors) if ((ElementFunction[ElementNumber] == 3) && (ElementCommandInt != 100) && (ElementCommandInt != 0)) { //AnalogWrite if ((ElementCommandInt > 0) && (ElementCommandInt < 100)) { ElementCalVal[ElementNumber] = ElementCommandInt; //Save the Actuator Value so it can tell what it is if asked ElementCommandInt = ElementCommandInt * 255 / 100; //convert to 0-255 for PWM analogWrite(ElementPin[ElementNumber], ElementCommandInt); //AnalogWrite (PWM) if it's a 1-99 value success(); } else { fail(); } } //This does the digital writes, and also takes care of 100% on and 100% off PWM dimming else if ((ElementFunction[ElementNumber] == 4) || (ElementFunction[ElementNumber] == 3)) { //DigitalWrite ElementCalVal[ElementNumber] = ElementCommandInt; //Save the Actuator Value so it can tell what it is if asked if (ElementCommandInt == 0) { //0 means turn off the actuator digitalWrite(ElementPin[ElementNumber], LOW); success(); } else if (ElementCommandInt == 100) { //100 means turn on the actuator digitalWrite(ElementPin[ElementNumber], HIGH); success(); } else { fail(); } } else if (ElementFunction[ElementNumber] == 5) { //Triac Dimming 115v/240v AC Outlets //Decides if the input was appropriate, and sets the Stored Value betwenn 0 and 100 % if (ElementCommandInt == 0) { digitalWrite(ElementPin[ElementNumber], LOW); ElementCalVal[ElementNumber] = ElementCommandInt; //Save the Actuator Value so it can tell what it is if asked success(); } else if (ElementCommandInt == 100) { //100 means turn on the outlet all the way digitalWrite(ElementPin[ElementNumber], HIGH); ElementCalVal[ElementNumber] = ElementCommandInt; success(); } else if ((ElementCommandInt > 0.00) && (ElementCommandInt < 100.00)) { ElementCalVal[ElementNumber] = ElementCommandInt; ElementTotalValue[ElementNumber] = ElementCalVal[ElementNumber]; ElementTotalValue[ElementNumber] = 80 * ElementTotalValue[ElementNumber]; ElementTotalValue[ElementNumber] = 8000 - ElementTotalValue[ElementNumber]; ElementYintEx[ElementNumber] = 1; // ElementCalVal[ElementNumber] = 80 * ElementCalVal[ElementNumber]; //convert to Delay: // ElementCalVal[ElementNumber] = 8000 - ElementCalVal[ElementNumber]; // MilliDelay=8300-(83*%Dim) Serial.println(ElementCalVal[ElementNumber]); Serial.println(ElementTotalValue[ElementNumber]); success(); } else { fail(); } //Sets the TriacDimming Boolean to true if any of the outlets are dimmed between 1 and 99% TriacDimming = false; for (int i = 0; i < 20; i++) { if (ElementType[i] == 'a') { //s = sensor, a = actuator, n = nothing if (ElementFunction[i] == 5) { // 5=Triac Dimming if ((ElementCalVal[i] < 100.00) && (ElementCalVal[i] > 0.00)) { TriacDimming = true; } } } } } else { fail(); } } else { fail(); } } else if (ElementCommandChar == 'S') { //Not sure if storing an in where a float goes sometimes will matter //Set Fail Safe Value EEPROM.updateInt(EEPSlopeFSLoc[ElementNumber], ElementCommandInt); ElementSlopeFS[ElementNumber] = ElementCommandInt; success(); } else if (ElementCommandChar == 'F') { //Read Fail Safe Value Serial.print(GroupID); Serial.print("/"); Serial.print(ElementID); Serial.print(":"); Serial.println(EEPROM.readInt(EEPSlopeFSLoc[ElementNumber])); } else { fail(); //Return a -1 } clearTheMsg(); } else { fail(); } clearTheMsg(); } //Measure sensor elements (with the delay decided in the main sketch), put them in an array TimeNow = millis(); //Check the time if (TimeNow > LastMeasurement + SensorReadDelayMS) { LastMeasurement = millis(); readSensors(); } //Send a Stream of Sensor Data for 1 minute if it has been requested if (SendData) { if (SensorStreamStartTime + 60000 > TimeNow) { //Send Data Stream if (Pause) { Pause = false; } else { if (TimeNow > LastSend + SendDelay) { sendSensorData(); LastSend = millis(); } } } else { // Stop Sending Data SendData = false; SensorStreamStartTime = 0; SendDelay = 0; LastSend = 0; } } }