——Dari Forum Pembangun DWIN
Dalam isu ini, kami menolak kes sumber terbuka yang memenangi anugerah DWIN Developer Forum - Multi-function Weigher. Jurutera menggunakan skrin pintar COF 4-inci, dan melalui interaksi data antara teras T5L OS dan modul HX711 dan set sensor tekanan 5kg, pengguna boleh dengan mudah menyedari fungsi paparan pengiraan seperti berat, harga unit, jumlah harga, lalang, dll. ., serta fungsi mengira, menjejak lengkung perubahan berat, dan membetulkan ketepatan penimbang, dsb., supaya mudah untuk bertukar antara senario aplikasi yang berbeza untuk menikmati pengalaman penimbangan yang mudah dan cekap.
1. Pembangunan UI
![f26af533d43728cd210e0f7af5e7acc](https://ecdn6.globalso.com/upload/p/1355/source/2024-06/665f077223d2b27894.png)
2.C51 Reka Bentuk
Sebahagian daripada kod rujukan untuk penimbang untuk melaksanakan fungsi harga adalah seperti berikut:
// Halaman Harga ====================
#define VALUATION_UNIT_PRICE_ADDR 0x1010
#define VALUATION_GRAM_ADDR 0x1000
#define VALUATION_TOTAL_PRICES_ADDR 0x1020
uint32_t valuation_decorticate = 0; // Harga Berat Tara
uint32_t valuation_unit_price = 0; //Harga seunit
// Muat Semula Harga Unit
batal page_valuation_unit_price_refresh()
{
uint8_t test_display[10] = {0};
jika(harga_unit_nilai
{
test_display[0] = valuation_unit_price / 100 % 10 + 0x30;
test_display[1] = '.';
paparan_ujian[2] = harga_unit_nilai / 10 % 10 + 0x30;
paparan_ujian[3] = harga_unit_nilai / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_UNIT_PRICE_ADDR, test_display, 4);
}
else if(harga_unit_nilai
{
test_display[0] = valuation_unit_price / 1000 % 10 + 0x30;
paparan_ujian[1] = harga_unit_nilai / 100 % 10 + 0x30;
test_display[2] = '.';
paparan_ujian[3] = harga_unit_nilai / 10 % 10 + 0x30;
paparan_ujian[4] = harga_unit_nilai / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_UNIT_PRICE_ADDR, test_display, 4);
}
else if(harga_unit_nilai
{
test_display[0] = valuation_unit_price / 10000 % 10 + 0x30;
paparan_ujian[1] = harga_unit_nilai / 1000 % 10 + 0x30;
paparan_ujian[2] = harga_unit_nilai / 100 % 10 + 0x30;
test_display[3] = '.';
paparan_ujian[4] = harga_unit_nilai / 10 % 10 + 0x30;
paparan_ujian[5] = harga_unit_nilai / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_UNIT_PRICE_ADDR, test_display, 4);
}
else if(harga_unit_nilai
{
paparan_ujian[0] = harga_unit_nilai / 100000 % 10 + 0x30;
paparan_ujian[1] = harga_unit_nilai / 10000 % 10 + 0x30;
paparan_ujian[2] = harga_unit_nilai / 1000 % 10 + 0x30;
paparan_ujian[3] = harga_unit_nilai / 100 % 10 + 0x30;
test_display[4] = '.';
paparan_ujian[5] = harga_unit_nilai / 10 % 10 + 0x30;
paparan_ujian[6] = harga_unit_nilai / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_UNIT_PRICE_ADDR, test_display, 4);
}
}
// Penyegaran Berat
batal 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;
jika(gram_paparan
{
test_display[0] = gram_display / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
}
else 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);
}
else 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);
}
else 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);
}
else 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);
}
}
lain
{
dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);
}
}
// Jumlah Muat Semula Harga
batalkan page_valuation_price_refresh()
{
uint32_t price_value = 0;
uint8_t test_display[10] = {0x30, '.', 0x30, 0x30};
if(gram_value >= valuation_decorticate)
{
nilai_harga = (nilai_gram - valuation_decorticate) * valuation_unit_price * 2 / 1000;
jika(nilai_harga
{
paparan_ujian[0] = nilai_harga / 100 % 10 + 0x30;
test_display[1] = '.';
paparan_ujian[2] = nilai_harga / 10 % 10 + 0x30;
paparan_ujian[3] = nilai_harga / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
}
else if(nilai_harga
{
paparan_ujian[0] = nilai_harga / 1000 % 10 + 0x30;
paparan_ujian[1] = nilai_harga / 100 % 10 + 0x30;
test_display[2] = '.';
paparan_ujian[3] = nilai_harga / 10 % 10 + 0x30;
paparan_ujian[4] = nilai_harga / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
}
else if(nilai_harga
{
paparan_ujian[0] = nilai_harga / 10000 % 10 + 0x30;
paparan_ujian[1] = nilai_harga / 1000 % 10 + 0x30;
paparan_ujian[2] = nilai_harga / 100 % 10 + 0x30;
test_display[3] = '.';
paparan_ujian[4] = nilai_harga / 10 % 10 + 0x30;
paparan_ujian[5] = nilai_harga / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
}
else if(nilai_harga
{
paparan_ujian[0] = nilai_harga / 100000 % 10 + 0x30;
paparan_ujian[1] = nilai_harga / 10000 % 10 + 0x30;
paparan_ujian[2] = nilai_harga / 1000 % 10 + 0x30;
paparan_ujian[3] = nilai_harga / 100 % 10 + 0x30;
test_display[4] = '.';
paparan_ujian[5] = nilai_harga / 10 % 10 + 0x30;
paparan_ujian[6] = nilai_harga / 1 % 10 + 0x30;
dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
}
}
lain
{
dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);
}
}
batal page_valuation_decorticate()
{
valuation_decorticate = nilai_gram;
page_valuation_weight_refresh();
}
batal page_valuation_1()
{
jika(harga_unit_nilai
{
valuation_unit_price = valuation_unit_price * 10 + 1;
page_valuation_unit_price_refresh();
}
}
batal page_valuation_2()
{
jika(harga_unit_nilai
{
valuation_unit_price = valuation_unit_price * 10 + 2;
page_valuation_unit_price_refresh();
}
}
batal page_valuation_3()
{
jika(harga_unit_nilai
{
valuation_unit_price = valuation_unit_price * 10 + 3;
page_valuation_unit_price_refresh();
}
}
batal page_valuation_4()
{
jika(harga_unit_nilai
{
valuation_unit_price = valuation_unit_price * 10 + 4;
page_valuation_unit_price_refresh();
}
}
batal page_valuation_5()
{
jika(harga_unit_nilai
{
valuation_unit_price = valuation_unit_price * 10 + 5;
page_valuation_unit_price_refresh();
}
}
batal page_valuation_6()
{
jika(harga_unit_nilai
{
valuation_unit_price = valuation_unit_price * 10 + 6;
page_valuation_unit_price_refresh();
}
}
batal page_valuation_7()
{
jika(harga_unit_nilai
{
valuation_unit_price = valuation_unit_price * 10 + 7;
page_valuation_unit_price_refresh();
}
}
batal page_valuation_8()
{
jika(harga_unit_nilai
{
valuation_unit_price = valuation_unit_price * 10 + 8;
page_valuation_unit_price_refresh();
}
}
batal page_valuation_9()
{
jika(harga_unit_nilai
{
valuation_unit_price = valuation_unit_price * 10 + 9;
page_valuation_unit_price_refresh();
}
}
batal page_valuation_0()
{
jika(harga_unit_nilai
{
valuation_unit_price = valuation_unit_price * 10 + 0;
page_valuation_unit_price_refresh();
}
}
batal page_valuation_back()
{
valuation_unit_price = valuation_unit_price / 10;
page_valuation_unit_price_refresh();
}
batal page_valuation_clear()
{
valuation_unit_price = 0;
page_valuation_unit_price_refresh();
}
Masa siaran: Apr-28-2024