Some Insight into the codeดังที่ฉันได้กล่าวถึงในบทช่วยสอนนี้ เราจะสุ่มตัวอย่างจาก the GUI task ของมันเอง, ตัวอย่างเช่น การสุ่มตัวอย่างภายใน the
Model::tick() function. The model source file ถูกแสดงไว้ข้างล่าง.

• ฉันได้รวมบาง definition จาก
line 2-11.
• The
main.h บรรจุ the necessary headers ทั้งหมดสำหรับส่วนประกอบที่เราใช้ใน project นี้.
• ฉันได้กำหนด the ADC handler, ADC_HandleTypeDef hadc3, สำหรับให้ the ADC ทำงาน.
• นอกจากนี้ยังมี a
map function (จาก Arduino source code), ดังนั้นเพื่อแมป the ADC values ภายในช่วงที่กำหนด.
•
Line no 13 เริ่มต้นตัวแปร
Button_State และ
ADC_VAL, ซึ่งถูกประกาศไว้ใน the model header file.
• Lines 21-25 ถูกใช้เพื่ออ่าน the button state.
• ถ้า the button ถูกกด, ตัวแปรนี้จะถูกเซ็ตเป็น
true และถ้า the button ถูกปล่อย, ตัวแปรนี้จะถูกเซ็ตเป็น
false.
•
Lines 27-31 ถูกใช้เพื่ออ่าน the ADC values จาก the potentiometer.
• ที่นี่ฉันใช้ the Poll method เพื่ออ่าน the values.
• จากนั้น The 12 bit ADC values จะถูกแม็ปกับช่วง 0 ถึง 100. ค่าที่ถูกแปลงเหล่านี้จะถูกเก็บไว้ใน the
ADC_VAL variable.
•
Lines 34 and 35 ถูกใช้เพื่อส่ง the button state และ the ADC values ไปยัง the presenter.
• The
modelListener คือ the pointer ไปยัง the active presenter และถูกใช้เพื่อส่ง the data ไปยัง the presenter