——Vom DWIN-Entwicklerforum
In dieser Ausgabe treiben wir den preisgekrönten Open-Source-Fall des DWIN Developer Forum – Multifunktionswaage voran. Der Ingenieur verwendet einen 4-Zoll-COF-Smart-Screen, und durch die Dateninteraktion zwischen dem T5L-Betriebssystemkern und dem HX711-Modul sowie dem 5-kg-Drucksensorsatz können Benutzer die Zählanzeigefunktionen wie Gewicht, Stückpreis, Gesamtpreis, Tara usw. problemlos realisieren ., sowie die Funktionen Zählen, Verfolgen von Gewichtsveränderungskurven und Korrektur der Waagengenauigkeit usw., sodass ein einfacher Wechsel zwischen verschiedenen Anwendungsszenarien für ein komfortables und effizientes Wägeerlebnis möglich ist.
1. UI-Entwicklung
![f26af533d43728cd210e0f7af5e7acc](https://ecdn6.globalso.com/upload/p/1355/source/2024-06/665f077223d2b27894.png)
2.C51-Design
Ein Teil des Referenzcodes für die Waage zur Implementierung der Preisfunktion lautet wie folgt:
// Preisseite===================
#define VALUATION_UNIT_PRICE_ADDR 0x1010
#define VALUATION_GRAM_ADDR 0x1000
#define VALUATION_TOTAL_PRICES_ADDR 0x1020
uint32_tvaluation_decorticate = 0; // Preis Taragewicht
uint32_tvaluation_unit_price = 0; //Einzelpreis
// Stückpreisaktualisierung
void page_valuation_unit_price_refresh()
{
uint8_t test_display[10] = {0};
if(valuation_unit_price
{
test_display[0] =valuation_unit_price / 100 % 10 + 0x30;
test_display[1] = '.';
test_display[2] =valuation_unit_price / 10 % 10 + 0x30;
test_display[3] =valuation_unit_price / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_UNIT_PRICE_ADDR, test_display, 4);
}
sonst if(valuation_unit_price
{
test_display[0] =valuation_unit_price / 1000 % 10 + 0x30;
test_display[1] =valuation_unit_price / 100 % 10 + 0x30;
test_display[2] = '.';
test_display[3] =valuation_unit_price / 10 % 10 + 0x30;
test_display[4] =valuation_unit_price / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_UNIT_PRICE_ADDR, test_display, 4);
}
sonst if(valuation_unit_price
{
test_display[0] =valuation_unit_price / 10000 % 10 + 0x30;
test_display[1] =valuation_unit_price / 1000 % 10 + 0x30;
test_display[2] =valuation_unit_price / 100 % 10 + 0x30;
test_display[3] = '.';
test_display[4] =valuation_unit_price / 10 % 10 + 0x30;
test_display[5] =valuation_unit_price / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_UNIT_PRICE_ADDR, test_display, 4);
}
sonst if(valuation_unit_price
{
test_display[0] =valuation_unit_price / 100000 % 10 + 0x30;
test_display[1] =valuation_unit_price / 10000 % 10 + 0x30;
test_display[2] =valuation_unit_price / 1000 % 10 + 0x30;
test_display[3] =valuation_unit_price / 100 % 10 + 0x30;
test_display[4] = '.';
test_display[5] =valuation_unit_price / 10 % 10 + 0x30;
test_display[6] =valuation_unit_price / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_UNIT_PRICE_ADDR, test_display, 4);
}
}
// Gewichtsaktualisierung
void page_valuation_weight_refresh()
{
uint8_t test_display[10] = {0x30};
uint32_t gram_display = 0;
if(gram_value >=valuation_decorticate)
{
gram_display = gram_value -valuation_decorticate;
if(gram_display
{
test_display[0] = gram_display / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
}
sonst if(gram_display
{
test_display[0] = gram_display / 10 % 10 + 0x30;
test_display[1] = gram_display / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
}
sonst if(gram_display
{
test_display[0] = gram_display / 100 % 10 + 0x30;
test_display[1] = gram_display / 10 % 10 + 0x30;
test_display[2] = gram_display / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
}
sonst if(gram_display
{
test_display[0] = gram_display / 1000 % 10 + 0x30;
test_display[1] = gram_display / 100 % 10 + 0x30;
test_display[2] = gram_display / 10 % 10 + 0x30;
test_display[3] = gram_display / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
}
sonst if(gram_display
{
test_display[0] = gram_display / 10000 % 10 + 0x30;
test_display[1] = gram_display / 1000 % 10 + 0x30;
test_display[2] = gram_display / 100 % 10 + 0x30;
test_display[3] = gram_display / 10 % 10 + 0x30;
test_display[4] = gram_display / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
}
}
anders
{
dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
}
}
// Gesamtpreisaktualisierung
void page_valuation_price_refresh()
{
uint32_t preis_wert = 0;
uint8_t test_display[10] = {0x30, '.', 0x30, 0x30};
if(gram_value >=valuation_decorticate)
{
preis_wert = (gram_value -valuation_decorticate) *valuation_unit_price * 2 / 1000;
if(price_value
{
test_display[0] = Preiswert / 100 % 10 + 0x30;
test_display[1] = '.';
test_display[2] = Preiswert / 10 % 10 + 0x30;
test_display[3] = preis_wert / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
}
sonst wenn(Preiswert
{
test_display[0] = Preiswert / 1000 % 10 + 0x30;
test_display[1] = Preiswert / 100 % 10 + 0x30;
test_display[2] = '.';
test_display[3] = preis_wert / 10 % 10 + 0x30;
test_display[4] = preis_wert / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
}
sonst if(price_value
{
test_display[0] = Preiswert / 10000 % 10 + 0x30;
test_display[1] = Preiswert / 1000 % 10 + 0x30;
test_display[2] = Preiswert / 100 % 10 + 0x30;
test_display[3] = '.';
test_display[4] = preis_wert / 10 % 10 + 0x30;
test_display[5] = preiswert / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
}
sonst if(price_value
{
test_display[0] = Preiswert / 100000 % 10 + 0x30;
test_display[1] = Preiswert / 10000 % 10 + 0x30;
test_display[2] = Preiswert / 1000 % 10 + 0x30;
test_display[3] = Preiswert / 100 % 10 + 0x30;
test_display[4] = '.';
test_display[5] = preis_wert / 10 % 10 + 0x30;
test_display[6] = Preiswert / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
}
}
anders
{
dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
}
}
void page_valuation_decorticate()
{
valuation_decorticate = gram_value;
page_valuation_weight_refresh();
}
void page_valuation_1()
{
if(valuation_unit_price
{
valuation_unit_price =valuation_unit_price * 10 + 1;
page_valuation_unit_price_refresh();
}
}
void page_valuation_2()
{
if(valuation_unit_price
{
valuation_unit_price =valuation_unit_price * 10 + 2;
page_valuation_unit_price_refresh();
}
}
void page_valuation_3()
{
if(valuation_unit_price
{
valuation_unit_price =valuation_unit_price * 10 + 3;
page_valuation_unit_price_refresh();
}
}
void page_valuation_4()
{
if(valuation_unit_price
{
valuation_unit_price =valuation_unit_price * 10 + 4;
page_valuation_unit_price_refresh();
}
}
void page_valuation_5()
{
if(valuation_unit_price
{
valuation_unit_price =valuation_unit_price * 10 + 5;
page_valuation_unit_price_refresh();
}
}
void page_valuation_6()
{
if(valuation_unit_price
{
valuation_unit_price =valuation_unit_price * 10 + 6;
page_valuation_unit_price_refresh();
}
}
void page_valuation_7()
{
if(valuation_unit_price
{
valuation_unit_price =valuation_unit_price * 10 + 7;
page_valuation_unit_price_refresh();
}
}
void page_valuation_8()
{
if(valuation_unit_price
{
valuation_unit_price =valuation_unit_price * 10 + 8;
page_valuation_unit_price_refresh();
}
}
void page_valuation_9()
{
if(valuation_unit_price
{
valuation_unit_price =valuation_unit_price * 10 + 9;
page_valuation_unit_price_refresh();
}
}
void page_valuation_0()
{
if(valuation_unit_price
{
valuation_unit_price =valuation_unit_price * 10 + 0;
page_valuation_unit_price_refresh();
}
}
void page_valuation_back()
{
valuation_unit_price =valuation_unit_price / 10;
page_valuation_unit_price_refresh();
}
void page_valuation_clear()
{
valuation_unit_price = 0;
page_valuation_unit_price_refresh();
}
Zeitpunkt der Veröffentlichung: 28. April 2024