背景:MPLAB X IDE 4.01、XC32 V1.44、和声V2.04、PIC32 MZ2064 DAG176、NEWHAVEN 4.3“显示四线电阻触摸屏(ST722T2内部控制器)、内部DDR。我不喜欢再次碰撞,但我认为我误解了关于显示标签文本的一些事情。我有两个整数:一个是数字[09999 ],另一个是[0,3]。第一个数是实际数(在我们的情况下是设定点),后者是小数点。所以,如果你有5000和2,TFT显示器应该显示50。我使用的逻辑如下:问题是,如果我有一个零的初始值,那么我可以改变我想要的小数点,它总是显示“0”。不是“0”,如果我有小数点1,或“0”为2,等等。这里是奇怪的部分:如果我把小数点设置为1,例如,值仍然在0,那么我可以将它设置为任何数目从[0,9],它也不会改变。如果将值设置为10,它将正确显示“1”。现在,如果我把数字设置为5,它将正确地显示“0.5”。奇怪的是,如果小数点是2,它将需要一个大于100的数字来解开它,1000的小数点为3。一旦它“unclit'”,一切都显示完美,前提是我不改变小数点。这使我相信我的FrutATHOLL号函数工作正常,但是无论是LaSTRIGIN CREATEOVER CHARBASH还是LalabelWistGETScript都引起了问题。有什么想法吗?编辑1:我希望避免通过堆栈挖掘,但问题在于如何比较拉弦。在LabRiaWiGigLay.Label.C中有LalabelWistGoGETStEnt函数。这个函数调用LaString比较,如果字符串与以前相同,它就不会更新。这个比较函数最终归结为LabRiaSyStudio.c中的LaaStrucMP。这个函数,你可以想象,像STRCMP一样工作。这在正常操作中是好的,但是如果你在我的情况下“0”不同于“0”,那该怎么办?我明白,这避免了在没有必要时重绘的性能损失,但它不考虑像我这样的拐角情况,也不知道如何容易地绕过这一点,而不是修改堆栈。应负责确定两个字符串何时“相等”。在我的情况下,我会说如果长度不同,那么它们就不相等。因此,在LAYSTRCMP中检查字符串长度是一个很好的选择,如果取出它将不起作用。不过,我可以验证删除SETTATE中的LaSTRIGIN比较和后续返回值可以解决我的问题。
以上来自于百度翻译
以下为原文
Background: MPLAB X IDE 4.01, XC32 v1.44, Harmony v2.04, PIC32MZ2064DAG176, Newhaven 4.3" display with 4-wire resistive touch panel (ST7282T2 internal controller), internal DDR.
I hate to bump this again, but I think I am misunderstanding something regarding displaying label text. I have two integers: one is a number [0,9999] and another [0,3]. The first number is the actual number (setpoint in our case) and the latter is the decimal point. So, if you have 5000 and 2, the TFT display should display 50.00. The logic that I use is the following:
static void format_number(char *num, uint8_t dp, double val)
{
const char *formatters[] = {"%1.0f","%2.1f","%3.2f","%4.3f"};
const uint16_t divisor[] = {1,10,100,1000};
if (dp > 3)
return;
val /= divisor[dp];
sprintf(num, formatters[dp], val);
}
uint16_t dp;
uint16_t sp;
char buff[20];
laString val;
//Setpoint
format_number(buff, dp, sp);
val = laString_CreateFromCharBuffer(buff, &DINBd____MainValues);
laLabelWidget_SetText(LabelSetpoint, val);
laString_Destroy(&val);
The problem is that if I have an initial value of zero, then I can change the decimal point all I want and it will always display "0". Not "0.0" if I have a decimal point of 1, or "0.00" for 2, etc. Here is the strange part: if I set the decimal point to 1, for example, and the value is still at 0 then I can set it to any number from [0,9] and it won't change either. If I set the value to 10 it will correctly display "1.0". Now if I set the number to 5, it will correctly display "0.5".
Oddly enough, if the decimal point is 2, it will take a number larger than 100 to unstick it and 1000 for a decimal point of 3. As soon as it's "unstuck", everything displays perfectly provided that I don't change the decimal point.
This leads me to believe that my format_number function works fine, but either laString_CreateFromCharBuffer or laLabelWidget_SetText is causing problems.
Any thoughts?
Edit 1: I was hoping to avoid digging through the stack, but the problem is with how laString is compared. In libaria_widget_label.c there is the laLabelWidget_SetText function. This function calls laString_Compare and, if the string is the same as before, it won't update. This comparison function ultimately boils down to la_strcmp in libaria_string.c. This function, as you can imagine, works like strcmp.
This is fine in normal operation, but what if you're in my situation where "0" is different than "0.00"? I understand that this avoids the performance penalty from a redraw when none is needed, but it doesn't account for corner cases like mine, nor can I see a way to get around this easily, short of modifying the stack.
I would propose that this string compare business be taken out and that the application should be responsible for determining when two strings are "equal". In my case, I would say if the lengths are different then they're not equal. Therefore, checking string lengths in la_strcmp is a good alternative if taking it out won't work. I can verify, though, that removing the laString_Compare and subsequent return value in SetText solves my problem.