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: HCSR04new SSH1106-alan
Thread/Thread_Handle.cpp
- Committer:
- alanchip
- Date:
- 2021-04-19
- Revision:
- 3:17acfeba3730
- Parent:
- 2:1baa0bd2fde0
File content as of revision 3:17acfeba3730:
#include "mbed.h"
#include "platform/mbed_thread.h"
#include "Thread_Handle.h"
#include "HCSR04.h"
#include "main.h"
#include "handleTasks.h"
#include "rtc.h"
#include "SSH1106.h"
Thread sensor_thread0;
Thread sensor_thread1;
Thread RTC_thread;
Thread sensor_capture_thread;
Thread oled_thread;
Thread time_thread;
//Thread realTime_thread;
int Q=1;
//void time_record_thread(void)
//{
// while(true) {
// ssh1106.writeTim_format(10,6, font_5x8,p_tm->tm_hour);
// ssh1106.writeTim_format(60,6, font_5x8,p_tm->tm_min);
// ssh1106.writeTim_format(120,6, font_5x8,p_tm->tm_sec);
// thread_sleep_for(1000);
// }
//
//}
void time_check_thread(void)
{
while(true) {
Q++;
//printf("%d \n\n",Q);
thread_sleep_for(1000);
}
}
//Usensor dist 0-- blue line
void dist0_thread(void)
{
while(true) {
//printf("dist0 = %d \n\n", capteur0.measDist());
Usensor0.dist = capteur0.measDist();
thread_sleep_for(10);
}
}
//Usensor dist 1
void dist1_thread(void)
{
while(true) {
//printf("dist1 = %d \n\n", capteur1.measDist());
Usensor1.dist = capteur1.measDist();
thread_sleep_for(10);
}
}
//Display car number
void OLED_refresh_thread()
{
int n=1;
char str[40];
while(true) {
ssh1106.writeText_format(0,1, font_5x8,"Car num:");
ssh1106.writeDec_format(55,1, font_5x8,carNum );
n = sprintf(str, "%d",Q);
ssh1106.writeText(0,6, font_5x8,str,n);
oled_carStateDisplay();
thread_sleep_for(1);
}
}
//display car state
void capture_sensor_thread()
{
while(true) {
carState_check_in();
display_carState_in();
//printf("dist1 = %d ",Usensor1.dist);
carState_check_out();
display_carState_out();
countCarnum();
carState = nothing;
usensor_paraClear();
thread_sleep_for(10);
}
}
//RTC
void RTC_display_thread(void)
{
while(true) {
RTC_display();
thread_sleep_for(1000);
}
}
void init_thread(void)
{
while(true) {
//clear param
usensor_paraInit();
//OLED init
ssh1106.init();
thread_sleep_for(100);
ssh1106.clear();
oled_thread.start(OLED_refresh_thread);
time_thread.start(time_check_thread);
//realTime_thread.start(time_record_thread);
//RTC
RTC_INIT();
RTC_thread.start(RTC_display_thread);
//thread0 for Usensor0
sensor_thread0.start(dist0_thread);
sensor_capture_thread.start(capture_sensor_thread);
//thread1 for Usensor1
sensor_thread1.start(dist1_thread);
init_start_thread.terminate();// thread gang up
}
}