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.
Revision 13:d20f32f4d9a0, committed 2015-06-14
- Comitter:
- okano
- Date:
- Sun Jun 14 00:50:06 2015 +0000
- Parent:
- 12:4b91875e6c7f
- Commit message:
- OPERATION_AID option added
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Jun 13 03:45:14 2015 +0000
+++ b/main.cpp Sun Jun 14 00:50:06 2015 +0000
@@ -30,6 +30,8 @@
#define SHORT_LOW 1
#define CONTROL_DIRECTION SHORT_LOW
+//#define OPERATION_AID
+
enum Tone_list {
Tone_A = 0,
Tone_Ais,
@@ -51,6 +53,7 @@
void init( void );
void set_in_flag();
void data_output();
+int tone_indicator( float ci );
int main()
{
@@ -78,6 +81,10 @@
#else
ci = (0.75 + ai * 2.0);
#endif
+
+#ifdef OPERATION_AID
+ leds = tone_indicator( ci );
+#else
//
// reference tone indicator
//
@@ -91,7 +98,7 @@
if ( (0.985663 < ci) && (ci < 1.01455) ) {
leds = 0x7;
}
-
+#endif
vitalsign = (vc++ >> 4) & 0x1;
}
}
@@ -189,3 +196,28 @@
ao = 0.5 + (amp * ((float)sample[ count & 0x3FFF ] / 65536.0));
count += (int)(ref_tone * ci);
}
+
+
+int tone_indicator( float ci )
+{
+ static float indicator_reference[] = {
+ 1.0,
+ pow( 2.0, 2.0 / 12.0 ),
+ pow( 2.0, 4.0 / 12.0 ),
+ pow( 2.0, 5.0 / 12.0 ),
+ pow( 2.0, 7.0 / 12.0 ),
+ pow( 2.0, 9.0 / 12.0 ),
+ pow( 2.0, 11.0 / 12.0 ),
+ };
+ static float ratio = pow( 2.0, 1.0 / 48.0 );
+ int i;
+
+ ci = (ci < 1.0) ? ci + 1.0 : ci;
+ ci = (2.0 < ci) ? ci - 1.0 : ci;
+
+ for ( i = 0; i < sizeof( indicator_reference ) / sizeof( float ); i++ ) {
+ if ( (indicator_reference[ i ] / ratio < ci) && (ci < indicator_reference[ i ] * ratio) )
+ return ( i + 1 );
+ }
+ return ( 0 );
+}
\ No newline at end of file