[مفتوح المصدر] جهاز وزن متعدد الوظائف

——من منتدى مطوري DWIN

في هذا العدد، ندفع بالحالة مفتوحة المصدر الحائزة على جوائز لمنتدى مطوري DWIN - الميزان متعدد الوظائف. يستخدم المهندس شاشة COF ذكية مقاس 4 بوصات، ومن خلال تفاعل البيانات بين T5L OS core ووحدة HX711 ومجموعة مستشعر الضغط 5 كجم، يمكن للمستخدمين بسهولة تحقيق وظائف عرض العد مثل الوزن وسعر الوحدة والسعر الإجمالي والفارغ وما إلى ذلك. ، بالإضافة إلى وظائف العد، وتتبع منحنيات تغيير الوزن، وتصحيح دقة الميزان، وما إلى ذلك، بحيث يكون من السهل التبديل بين سيناريوهات التطبيق المختلفة للاستمتاع بتجربة وزن مريحة وفعالة.

1. تطوير واجهة المستخدم

f26af533d43728cd210e0f7af5e7acc

2.C51 التصميم

جزء من الكود المرجعي للميزان لتنفيذ وظيفة التسعير هو كما يلي:

// صفحة التسعير =============================================

#define VALUATION_UNIT_PRICE_ADDR 0x1010

#تعريف VALUATION_GRAM_ADDR 0x1000

#تعريف VALUATION_TOTAL_PRICES_ADDR 0x1020

uint32_t valuation_decorticate = 0; // تسعير الوزن الفارغ

uint32_t valuation_unit_price = 0; //سعر الوحدة

// تحديث سعر الوحدة

باطلة page_valuation_unit_price_refresh ()

{

uint8_t test_display[10] = {0};

إذا (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);

}

وإلا إذا (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);

}

وإلا إذا كان (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);

}

وإلا إذا (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);

}

}

 

// تحديث الوزن

باطلة page_valuation_weight_refresh ()

{

uint8_t test_display[10] = {0x30};

uint32_t gram_display = 0;

إذا (gram_value >= valuation_decorticate)

{

gram_display = gram_value - valuation_decorticate;

إذا (gram_display

{

test_display[0] = gram_display / 1 % 10 + 0x30;

dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);

}

وإلا إذا (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);

}

وإلا إذا (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);

}

وإلا إذا (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);

}

وإلا إذا (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);

}

}

آخر

{

dgus_show_text_value_set(VALUATION_GRAM_ADDR, test_display, 3);

}

}

 

// تحديث السعر الإجمالي

باطلة page_valuation_price_refresh ()

{

uint32_t Price_value = 0;

uint8_t test_display[10] = {0x30, '.', 0x30, 0x30};

إذا (gram_value >= valuation_decorticate)

{

Price_value = (gram_value - valuation_decorticate) * valuation_unit_price * 2 / 1000؛

إذا (قيمة_السعر

{

test_display[0] = Price_value / 100 % 10 + 0x30;

test_display[1] = '.';

test_display[2] = قيمة_السعر / 10% 10 + 0x30;

test_display[3] = قيمة_السعر / 1% 10 + 0x30;

dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);

}

وإلا إذا كانت (قيمة_السعر

{

test_display[0] = Price_value / 1000 % 10 + 0x30;

test_display[1] = قيمة_السعر / 100% 10 + 0x30;

test_display[2] = '.';

test_display[3] = قيمة_السعر / 10% 10 + 0x30;

test_display[4] = قيمة_السعر / 1% 10 + 0x30;

dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);

}

وإلا إذا كانت (قيمة_السعر

{

test_display[0] = Price_value / 10000 % 10 + 0x30;

test_display[1] = قيمة_السعر / 1000 % 10 + 0x30;

test_display[2] = قيمة_السعر / 100% 10 + 0x30;

test_display[3] = '.';

test_display[4] = قيمة_السعر / 10% 10 + 0x30;

test_display[5] = قيمة_السعر / 1% 10 + 0x30;

dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);

}

وإلا إذا كانت (قيمة_السعر

{

test_display[0] = Price_value / 100000 % 10 + 0x30;

test_display[1] = قيمة_السعر / 10000 % 10 + 0x30;

test_display[2] = Price_value / 1000 % 10 + 0x30;

test_display[3] = قيمة_السعر / 100% 10 + 0x30;

test_display[4] = '.';

test_display[5] = قيمة_السعر / 10% 10 + 0x30;

test_display[6] = قيمة_السعر / 1% 10 + 0x30;

dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);

}

}

آخر

{

dgus_show_text_value_set(VALUATION_TOTAL_PRICES_ADDR, test_display, 4);

}

}

باطلة page_valuation_decorticate ()

{

valuation_decorticate = gram_value;

page_valuation_weight_refresh();

}

باطلة page_valuation_1 ()

{

إذا (valuation_unit_price

{

valuation_unit_price = valuation_unit_price * 10 + 1;

page_valuation_unit_price_refresh();

}

}

باطلة page_valuation_2 ()

{

إذا (valuation_unit_price

{

valuation_unit_price = valuation_unit_price * 10 + 2;

page_valuation_unit_price_refresh();

}

}

باطلة page_valuation_3 ()

{

إذا (valuation_unit_price

{

valuation_unit_price = valuation_unit_price * 10 + 3;

page_valuation_unit_price_refresh();

}

}

باطلة page_valuation_4 ()

{

إذا (valuation_unit_price

{

valuation_unit_price = valuation_unit_price * 10 + 4;

page_valuation_unit_price_refresh();

}

}

باطلة page_valuation_5 ()

{

إذا (valuation_unit_price

{

valuation_unit_price = valuation_unit_price * 10 + 5;

page_valuation_unit_price_refresh();

}

}

باطلة page_valuation_6 ()

{

إذا (valuation_unit_price

{

valuation_unit_price = valuation_unit_price * 10 + 6;

page_valuation_unit_price_refresh();

}

}

باطلة page_valuation_7 ()

{

إذا (valuation_unit_price

{

valuation_unit_price = valuation_unit_price * 10 + 7;

page_valuation_unit_price_refresh();

}

}

باطلة page_valuation_8 ()

{

إذا (valuation_unit_price

{

valuation_unit_price = valuation_unit_price * 10 + 8;

page_valuation_unit_price_refresh();

}

}

باطلة page_valuation_9 ()

{

إذا (valuation_unit_price

{

valuation_unit_price = valuation_unit_price * 10 + 9;

page_valuation_unit_price_refresh();

}

}

باطلة page_valuation_0 ()

{

إذا (valuation_unit_price

{

valuation_unit_price = valuation_unit_price * 10 + 0;

page_valuation_unit_price_refresh();

}

}

باطلة page_valuation_back ()

{

valuation_unit_price = valuation_unit_price / 10;

page_valuation_unit_price_refresh();

}

باطلة page_valuation_clear ()

{

valuation_unit_price = 0؛

page_valuation_unit_price_refresh();

}


وقت النشر: 28 أبريل 2024