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.
annThread.cpp
00001 #include "main.h" 00002 00003 AnalogIn evenAnn1(p19); 00004 AnalogIn evenAnn2(p20); 00005 00006 extern Queue<Event_t, 16> eventQueue; 00007 extern Mutex queue_mutex; 00008 00009 short Average(short values[5]) 00010 { 00011 return ((values[0] + values[1] + values[2] + values[3] + values[4]) /5); 00012 } 00013 00014 void samplingAnn(void const *n) 00015 { 00016 static short tabPot1[5] = {0, 0, 0, 0, 0}; 00017 static short tabPot2[5] = {0, 0, 0, 0, 0}; 00018 static short currentValue[2] = {0, 0}; 00019 short avg[2]= {0, 0}; 00020 static short tabPtr = 0; 00021 static bool ready = false; 00022 00023 currentValue[0] = evenAnn1.read() * 1000; 00024 avg[0] = Average(tabPot1); 00025 00026 currentValue[1] = evenAnn2.read() * 1000; 00027 avg[1] = Average(tabPot2); 00028 00029 if(ready) 00030 { 00031 if((currentValue[0] < (avg[0] - ANN_THRESOLD)) || (currentValue[0] > (avg[0] + ANN_THRESOLD))) 00032 { 00033 Event_t *event1 = new Event_t(); 00034 event1->type = POT_1; 00035 event1->time = time(NULL); 00036 queue_mutex.lock(); 00037 eventQueue.put(event1); 00038 queue_mutex.unlock(); 00039 } 00040 00041 if((currentValue[1] < (avg[1] - ANN_THRESOLD)) || (currentValue[1] > (avg[1] + ANN_THRESOLD))) 00042 { 00043 Event_t *event2 = new Event_t(); 00044 event2->type = POT_2; 00045 event2->time = time(NULL); 00046 queue_mutex.lock(); 00047 eventQueue.put(event2); 00048 queue_mutex.unlock(); 00049 } 00050 } 00051 00052 tabPot1[tabPtr] = currentValue[0]; 00053 tabPot2[tabPtr] = currentValue[1]; 00054 00055 tabPtr++; 00056 if(tabPtr == 5) 00057 { 00058 tabPtr = 0; 00059 ready = true; 00060 } 00061 } 00062 00063 void AnnEvent_thread(void const *args) 00064 { 00065 RtosTimer samplingTimer(samplingAnn, osTimerPeriodic, (void *)0); 00066 samplingTimer.start(ANN_DELAY); 00067 while (true){} 00068 }
Generated on Wed Jul 13 2022 03:00:04 by
1.7.2