Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DS1620_improved TextLCD_improved mbed-rtos mbed
Revision 7:05f4f9d3c168, committed 2015-12-13
- Comitter:
- dzoni
- Date:
- Sun Dec 13 11:12:19 2015 +0000
- Parent:
- 6:d1435e38c1b4
- Child:
- 8:812c2b49251f
- Commit message:
- Release 2.0 (RTOS + rewritten to separate tasks). Remaining:; - split tasks to separate source files; - program FSM(s) tisked by RTOS timer instead of Thread::wait() in tasks
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r d1435e38c1b4 -r 05f4f9d3c168 main.cpp
--- a/main.cpp Sun Dec 13 10:43:17 2015 +0000
+++ b/main.cpp Sun Dec 13 11:12:19 2015 +0000
@@ -3,15 +3,14 @@
#include "DS1620.h"
#include "TextLCD.h"
-TextLCD lcd(PA_8, PA_7, PA_9, PA_1, PB_5, PA_10, TextLCD::LCD16x2);
+static TextLCD lcd(PA_8, PA_7, PA_9, PA_1, PB_5, PA_10, TextLCD::LCD16x2);
-DS1620 ds1620Sensor(PB_4, PB_10, PB_3);
+static DS1620 ds1620Sensor(PB_4, PB_10, PB_3);
-static float temperature = 0.0f;
-static uint32_t temp_raw = 0;
static uint32_t uiCnt=0;
-static DigitalOut myled(LED1);
+static DigitalOut led2(LED2);
+static DigitalIn button1(USER_BUTTON);
static DigitalOut trigDist(PB_9);
static DigitalIn echoDist(PA_6);
@@ -23,6 +22,16 @@
float distance;
} dist_data = { 10000, 10.0f };
+static struct {
+ uint32_t temp_raw;
+ float temperature;
+} temp_data = { 0, 10.0f };
+
+static struct {
+ uint32_t on_time;
+ uint32_t off_time;
+} flash_times = { 100, 2500 };
+
static void initDS1620Temp() {
@@ -32,9 +41,36 @@
}
}
+void led2_thread(void const *args) {
+
+ while (true) {
+ led2 = 1;
+ Thread::wait(flash_times.on_time);
+
+ led2 = 0;
+ Thread::wait(flash_times.off_time);
+ }
+}
+
+void ubutton_thread(void const *args) {
+ static uint32_t last_state = button1;
+ uint32_t temp;
+
+ while (true) {
+ if (button1 != last_state) {
+ temp = flash_times.on_time;
+ flash_times.on_time = flash_times.off_time;
+ flash_times.off_time = temp;
+ }
+
+ Thread::wait(250);
+ }
+}
+
+
void temp_thread(void const *args) {
- while (1) {
- myled = myled ^ 1;
+
+ while (true) {
ds1620Sensor.startConversion();
// Wait for conversion completion (Tconv = 750 ms typ)
@@ -42,18 +78,19 @@
while (!(ds1620Sensor.readConfig() & 0x80))
Thread::wait(10);
- temperature = ds1620Sensor.getHighResolutionTemperature();
- temp_raw = ds1620Sensor.readTemperatureRaw();
+ temp_data.temperature = ds1620Sensor.getHighResolutionTemperature();
+ temp_data.temp_raw = ds1620Sensor.readTemperatureRaw();
}
}
void disp_thread(void const *args) {
- while (1) {
+
+ while (true) {
lcd.cls();
- lcd.printf("Raw:%3u % 5.0f mm", temp_raw, dist_data.distance);
+ lcd.printf("Raw:%3u % 5.0f mm", temp_data.temp_raw, dist_data.distance);
uiCnt += 2;
lcd.locate(0, 1);
- lcd.printf("Float: %3.2f%cC", temperature, 0xdf);
+ lcd.printf("Float: %3.2f%cC", temp_data.temperature, 0xdf);
Thread::wait(1900);
}
@@ -61,7 +98,7 @@
void dist_thread(void const *args) {
- while (1) {
+ while (true) {
// Dej puls na trig
trigDist = 1;
Thread::wait(1);
@@ -105,9 +142,11 @@
initDS1620Temp();
- Thread dispThread(disp_thread, NULL, osPriorityNormal);
- Thread tempThread(temp_thread, NULL, osPriorityNormal);
- Thread distThread(dist_thread, NULL, osPriorityNormal);
+ Thread dispThread(disp_thread, NULL, osPriorityLow);
+ Thread tempThread(temp_thread, NULL, osPriorityLow);
+ Thread distThread(dist_thread, NULL, osPriorityRealtime);
+ Thread led2Thread(led2_thread, NULL, osPriorityNormal);
+ Thread ubuttonThread(ubutton_thread, NULL, osPriorityAboveNormal);
Thread::wait(osWaitForever);
}