Because I honestly didn't understand much of your code. But I know you are only receiving the humidity and temperature data, or am I wrong?
A long time ago, when I was at university, did some projects with Arduaros (Chinese Arduinos ). And i use that formula to calculate the enthalpy (several times).
Well i did a extension for you, but Niotron is getting problems with compiling.
Maybe @TIMAI2 can lend a hand.
Source Code
package com.jd.Enthalpy;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
@DesignerComponent(
version = 1,
description = "Humidity % and Temperatura C°",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "https://img.icons8.com/?size=100&id=C44VkfkDwlMV&format=png&color=000000")
/**
* Extension to calculate enthalpy given temperature and humidity.
*/
@SimpleObject
public class EnthalpyCalculator extends AndroidNonvisibleComponent {
// Default values
private float cp = 1.006f; // Specific heat capacity of air in kJ/kgK
private float p = 101.325f; // Atmospheric pressure in kPa
private float h_fg = 2500f; // Latent heat of vaporization in kJ/kg
private float R = 0.462f; // Gas constant in kJ/kgK
// Constructor
public EnthalpyCalculator(ComponentContainer container) {
super(container.$form());
}
@SimpleProperty(description = "Set the Specific heat capacity of the air (cp) in kJ/kgK")
public void setCp(float cp) {
this.cp = cp;
}
@SimpleProperty(description = "Get the Specific heat capacity of the air (cp) kJ/kgK")
public float getCp() {
return this.cp;
}
@SimpleProperty(description = "Set the Atmospheric pressure (p) in kPa")
public void setP(float p) {
this.p = p;
}
@SimpleProperty(description = "Get the Atmospheric pressure (p) in kPa")
public float getP() {
return this.p;
}
@SimpleProperty(description = "Set the Latent heat of vaporization (h_fg) in kJ/kg")
public void setHfg(float h_fg) {
this.h_fg = h_fg;
}
@SimpleProperty(description = "Get the Latent heat of vaporization (h_fg) in kJ/kg")
public float getHfg() {
return this.h_fg;
}
@SimpleProperty(description = "Set the Gas constant (R) in kJ/kgK")
public void setR(float R) {
this.R = R;
}
@SimpleProperty(description = "Get the Gas constant (R) in kJ/kgK")
public float getR() {
return this.R;
}
@SimpleFunction(description = "Calculate the enthalpy given temperature and humidity")
public float calculateEnthalpy(float temperature, float humidity) {
// Calculate enthalpy using the formula
float RH = humidity; // Assuming humidity is in percentage
return (cp * temperature) + ((p * h_fg / R) * (RH / 100));
}
}
Niotron IDE Log
Execution Log
Started Compiling Project EnthalpyCalculator
Buildfile: /compiler/androidX/build.xml
javac:
[mkdir] Created dir: /compiler/androidX/build/udtNl/classes
[javac] Compiling 1 source file to /compiler/androidX/build/udtNl/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] Note: Wrote file file:/compiler/androidX/build/udtNl/classes/simple_components.json
[javac] Note: Wrote file file:/compiler/androidX/build/udtNl/classes/simple_components.txt
[javac] Note: Wrote file file:/compiler/androidX/build/udtNl/classes/simple_components_build_info.json
[javac] Note: Wrote file file:/compiler/androidX/build/udtNl/classes/AutogeneratedOdeMessages.java
[javac] Note: Wrote file file:/compiler/androidX/build/udtNl/classes/ComponentsTranslation.java
process:
[mkdir] Created dir: /compiler/androidX/out/udtNl
[mkdir] Created dir: /compiler/androidX/build/udtNl/externalComponents
[mkdir] Created dir: /compiler/androidX/build/udtNl/externalComponents-classes
[java]
[java] Extensions : Generating extensions
unjarAllExtensionLibraries:
jarAllExtensions:
dexAllExtensions:
extensions:
BUILD SUCCESSFUL
Total time: 0 seconds
No, the formula I use depends on only the temperature in Fahrenheit and the relative humidity. I was unaware of an enthalpy formula using the "Latent heat of evaporation" but I will run some numbers through it. The formula I use which has always worked for me is: Float enthalpy = 0.24*Ftemp+(0.6219)*(0.01*(0.000000007401234*pow(Ftemp,4) - 0.000000493526794*pow(Ftemp,3) + 0.000071281097208*pow(Ftemp,2) - 0.000489806163078*Ftemp + 0.039762055806989)*Humid)/(14.7-(0.01*(0.000000007401234*pow(Ftemp,4) - 0.000000493526794*pow(Ftemp,3) + 0.000071281097208*pow(Ftemp,2) - 0.000489806163078*Ftemp + 0.039762055806989)*Humid))*(1061.2+0.444*Ftemp);
Where Ftemp is the temperature in Fahrenheit and Humidity is the relative humidity percentage (0 - 100). I really think that TIMA12 had it right in this example - that I must "call" my variables in a "get" function but I am still having difficulty incorporating that logic into my "when checkbox clicked" block.
So, TIMA12 was kind enough to convert my enthalpy formula to a "call" and "get" function which, I understand from your previous communications is much more stable/accurate/dependable/etc. While I tried to map TIMA12's function onto my system of "when checkbox clicked," I find I am unable to plug his creation anywhere into my system (see my previous post).
I think I can actually get this myself if I understand the sequence of assembling a statement that uses the get variable command and I start from scratch. Would you please direct me to the basics that will ease my confusion or give me a simple "step 1, step 2, etc.) guide to creating variables that I can call in the appropriate blocks.. My greatest "duh-what" is how to get the orange variables to show up in the purple get blocks. Once I brought TIMA12's creation into my file, it "stood alone" and would not share variables with my blocks. Please understand that you may have shared this and I may have missed it in my overwhelm. Thanks again for any clarification.
That ultimately worked but I am a a loss as to how to interface my "when checkbox checked" block to your call for the enthalpy function. I am going to read over a link that ABG sent regarding procedures (for Dummy's) and see if I can recreate what you provided in my environment. I'm determined to get these 2 or 3 neurons up and running;).
Thank you for that example. I am starting to feel like I am catching on (still some conditionals;). I posted a response question to ABG regarding a small file he created, if you choose to comment on it. Thank you, again. I am grinding on.
Hi, could you address a few questions that I cannot seem to find the answer to? I am still not sure why variables are so great in functions but text boxes are not recommended, even though the contents of the text box are moved into the variable to be read. Were you also( in your dew point example) simply showing how procedures can be used to avoid redundancy and defined for those unfamiliar with the code? Thank you for any clarity you may be able to add.
OK, I've played with that for a couple of days and I am still missing something that is preventing me from calling this enthalpy procedure in the same manor that I would call any other procedure. If you would be so kind, please look over the two PNGs below. The first is typical of most of my check box functions. The second is me trying to fit what you have shown me into my application. As you can see, I can't get there from here with the logic(?) I am using. If you could draw some lines and arrows indication what goes where, I would really appreciate the assist. I do not always find the correct procedure blocks in the bin leading me to believe that I have missed a step.
The second example works fine. It just doesn't completely fulfil the purpose of a procedure.
Keeping procedures/functions/methods as generalized or parametrized is good coding. This maximizes reusability.
The second example, in this case, voids the use of the RH variable (which, honestly, is useless; but including it makes the code much more readable).
Could you please right-click -> download the individual events and procedures?
Assuming what you want to do is similar to what you've done in the save_Dry_Air_Volume procedure:
Inside the save_Enthalpy procedure, call another "to result" procedure to the enthalpy formula (make sure you pass the FTemp and Humid arguments), and then set the value of the corresponding key to that.
Tha magnus_a and magnus_b global variables are there just to help people reading the code.
They basically are there to answer the question
What bodily orifice hat did the code author pull these numbers out of, and how do I know they are right?
They supply the numbers with provenance, to borrow a term from the art dealers' world.
Better alternative would be to use local variables for those, to not clutter up the global name space of the app, and to keep the definition of those numbers close to the place where they are used and far away from the definitions of other numbers used in other formulas.
Another alternative would have been adding AI2 comment bubbles to the blue number blocks, filled with all sorts of text naming the values and telling how they fit into that formula. There is a risk to that, if the person testing parts of the app does a right-click Do It to evanluate that blocks and wipes out the text.
Thank you for that observation, as it is still unclear to me My question in the second example is how to call the equations. It seems (to me) that that the: to save_Enthalpy block should contain the mathematics but the math has a key and the block has a "slot." How might I place that blue mess of equations into a procedural call that is activated upon a click of checkbox 28?
Got it. Thank you for the clarification. It just seems (to me, here and now) that one goes through so many extra steps to make a "programmatically correct" file. I just don't have the bandwidth to figure out procedural calls, with respect to variables. Even the procedures guide you connected me with likening a procedure to telling your child to brush his/her teeth doesn't touch on the orange variable names in the procedure block headers. I wish someone had an "App Inventor for Dummies" handbook in which I could look up a particular block function and find examples of all of the various ways to utilize said block(s).
Thank you for your support through my "I thought I was wrong, but I was mistaken" plase of learning AI2.
Yes, yes, yes! I have been stopped by trying to initialize a global name, not understanding that it was a specific variable. So, initializing a global _______ will create a variable named _______ and place into it whatever is attached by a key. I have been ascribing variables as having some kind of all-knowing aspects when, in fact, they were dictated by sub-routines. I think you gave me the blueprint for properly assembling the enthalpy function in a more readable form. I will do so and see how the data comes out. Thank you for that great lesson in procedure assembly!