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.
numThread.cpp
00001 #include "main.h" 00002 00003 DigitalIn evenNum1(p15); 00004 DigitalIn evenNum2(p16); 00005 00006 extern Queue<Event_t, 16> eventQueue; 00007 extern Mutex queue_mutex; 00008 00009 void samplingNum(void const *n) 00010 { 00011 static bool stateChanged[2] = {false, false}; 00012 static bool value[2] = {1, 1}; 00013 00014 stateChanged[0] = (value[0] != evenNum1.read()); 00015 stateChanged[1] = (value[1] != evenNum2.read()); 00016 00017 if((stateChanged[0] == true) || (stateChanged[1] == true)) 00018 { 00019 wait_ms(50); 00020 stateChanged[0] = (value[0] != evenNum1.read()); 00021 stateChanged[1] = (value[1] != evenNum2.read()); 00022 00023 if(stateChanged[0]) 00024 { 00025 Event_t *event1 = new Event_t(); 00026 event1->type = SWITCH_1; 00027 event1->time = time(NULL); 00028 queue_mutex.lock(); 00029 eventQueue.put(event1); 00030 queue_mutex.unlock(); 00031 value[0] = !value[0]; 00032 } 00033 if(stateChanged[1]) 00034 { 00035 Event_t *event2 = new Event_t(); 00036 event2->type = SWITCH_2; 00037 event2->time = time(NULL); 00038 queue_mutex.lock(); 00039 eventQueue.put(event2); 00040 queue_mutex.unlock(); 00041 value[1] = !value[1]; 00042 } 00043 } 00044 } 00045 00046 void NumEvent_thread(void const *args) 00047 { 00048 RtosTimer samplingTimer(samplingNum, osTimerPeriodic, (void *)0); 00049 samplingTimer.start(NUM_DELAY); 00050 while (true){} 00051 }
Generated on Wed Jul 13 2022 03:00:04 by
1.7.2