From: AceVest Date: Wed, 10 Jan 2018 16:19:26 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=97f6816da959de17946e1471b3917d98e01be46e;p=acecode.git ... --- diff --git a/arduino/clockintr/clockintr.ino b/arduino/clockintr/clockintr.ino new file mode 100644 index 0000000..25f0363 --- /dev/null +++ b/arduino/clockintr/clockintr.ino @@ -0,0 +1,96 @@ + +int led0 = 7; +int led1 = 8; +int led2 = 12; +int cnt0 = 0; +int cnt1 = 0; +int cnt2 = 0; +void setup(){ + Serial.begin(9600); + pinMode(LED_BUILTIN, OUTPUT); + pinMode(led0, OUTPUT); + pinMode(led1, OUTPUT); + pinMode(led2, OUTPUT); + + cli();//stop interrupts + +#if 0 // 设置timer0会影响到loop函数里调用的delay,会使其失效 + //set timer0 interrupt at 2kHz + TCCR0A = 0;// set entire TCCR0A register to 0 + TCCR0B = 0;// same for TCCR0B + TCNT0 = 0;//initialize counter value to 0 + // set compare match register for 2khz increments + OCR0A = 124;// = (16*10^6) / (2000*64) - 1 (must be <256) + // turn on CTC mode + TCCR0A |= (1 << WGM01); + // Set CS01 and CS00 bits for 64 prescaler (参考上表) + TCCR0B |= (1 << CS01) | (1 << CS00); + // enable timer compare interrupt + TIMSK0 |= (1 << OCIE0A); +#endif + +#if 1 + //set timer1 interrupt at 1Hz + TCCR1A = 0;// set entire TCCR1A register to 0 + TCCR1B = 0;// same for TCCR1B + TCNT1 = 0;//initialize counter value to 0 + // set compare match register for 1hz increments + OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536) + // turn on CTC mode + TCCR1B |= (1 << WGM12); + // Set CS10 and CS12 bits for 1024 prescaler (参考上表) + TCCR1B |= (1 << CS12) | (1 << CS10); + // enable timer compare interrupt + TIMSK1 |= (1 << OCIE1A); +#endif + +#if 1 + //set timer2 interrupt at 8kHz + TCCR2A = 0;// set entire TCCR2A register to 0 + TCCR2B = 0;// same for TCCR2B + TCNT2 = 0;//initialize counter value to 0 + // set compare match register for 8khz increments + OCR2A = 249;// = (16*10^6) / (8000*8) - 1 (must be <256) + // turn on CTC mode + TCCR2A |= (1 << WGM21); + // Set CS21 bit for 8 prescaler (参考上表) + TCCR2B |= (1 << CS21); + // enable timer compare interrupt + TIMSK2 |= (1 << OCIE2A); +#endif + + sei();//allow interrupts + +}//end setup + +void loop() { + Serial.println("High"); + digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) + delay(1000); // wait for a second + + Serial.println("Low"); + digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW + delay(1000); // wait for a second +} + +ISR(TIMER0_COMPA_vect){ + cnt0++; + if(cnt0 % 1000 == 0) { + cnt0 == 0; + digitalWrite(led0, !digitalRead(led0)); + } +} + +ISR(TIMER1_COMPA_vect){ + cnt1++; + digitalWrite(led1, !digitalRead(led1)); +} + +ISR(TIMER2_COMPA_vect) { + cnt2++; + if(cnt2 % 1000 == 0) { + cnt2 = 0; + digitalWrite(led2, !digitalRead(led2)); + } +} + diff --git a/arduino/ir/irrecv/irrecv.ino b/arduino/ir/irrecv/irrecv.ino new file mode 100644 index 0000000..445838d --- /dev/null +++ b/arduino/ir/irrecv/irrecv.ino @@ -0,0 +1,179 @@ +//------------------------------------------------------------------------------ +// Include the IRremote library header +// +#include + +// HX1838(用金属包住头) 面对HX1838正面从左至右三个脚分别为 OUT、GND、VCC + +//------------------------------------------------------------------------------ +// Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838) +// +int recvPin = 11; +IRrecv irrecv(recvPin); + +//+============================================================================= +// Configure the Arduino +// +void setup ( ) +{ + Serial.begin(9600); // Status message will be sent to PC at 9600 baud + irrecv.enableIRIn(); // Start the receiver +} + +//+============================================================================= +// Display IR code +// +void ircode (decode_results *results) +{ + // Panasonic has an Address + if (results->decode_type == PANASONIC) { + Serial.print(results->address, HEX); + Serial.print(":"); + } + + // Print Code + Serial.print(results->value, HEX); +} + +//+============================================================================= +// Display encoding type +// +void encoding (decode_results *results) +{ + switch (results->decode_type) { + default: + case UNKNOWN: Serial.print("UNKNOWN"); break ; + case NEC: Serial.print("NEC"); break ; + case SONY: Serial.print("SONY"); break ; + case RC5: Serial.print("RC5"); break ; + case RC6: Serial.print("RC6"); break ; + case DISH: Serial.print("DISH"); break ; + case SHARP: Serial.print("SHARP"); break ; + case JVC: Serial.print("JVC"); break ; + case SANYO: Serial.print("SANYO"); break ; + case MITSUBISHI: Serial.print("MITSUBISHI"); break ; + case SAMSUNG: Serial.print("SAMSUNG"); break ; + case LG: Serial.print("LG"); break ; + case WHYNTER: Serial.print("WHYNTER"); break ; + case AIWA_RC_T501: Serial.print("AIWA_RC_T501"); break ; + case PANASONIC: Serial.print("PANASONIC"); break ; + case DENON: Serial.print("Denon"); break ; + } +} + +//+============================================================================= +// Dump out the decode_results structure. +// +void dumpInfo (decode_results *results) +{ + // Check if the buffer overflowed + if (results->overflow) { + Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWBUF"); + return; + } + + // Show Encoding standard + Serial.print("Encoding : "); + encoding(results); + Serial.println(""); + + // Show Code & length + Serial.print("Code : "); + ircode(results); + Serial.print(" ("); + Serial.print(results->bits, DEC); + Serial.println(" bits)"); +} + +//+============================================================================= +// Dump out the decode_results structure. +// +void dumpRaw (decode_results *results) +{ + // Print Raw data + Serial.print("Timing["); + Serial.print(results->rawlen-1, DEC); + Serial.println("]: "); + + for (int i = 1; i < results->rawlen; i++) { + unsigned long x = results->rawbuf[i] * USECPERTICK; + if (!(i & 1)) { // even + Serial.print("-"); + if (x < 1000) Serial.print(" ") ; + if (x < 100) Serial.print(" ") ; + Serial.print(x, DEC); + } else { // odd + Serial.print(" "); + Serial.print("+"); + if (x < 1000) Serial.print(" ") ; + if (x < 100) Serial.print(" ") ; + Serial.print(x, DEC); + if (i < results->rawlen-1) Serial.print(", "); //',' not needed for last one + } + if (!(i % 8)) Serial.println(""); + } + Serial.println(""); // Newline +} + +//+============================================================================= +// Dump out the decode_results structure. +// +void dumpCode (decode_results *results) +{ + // Start declaration + Serial.print("unsigned int "); // variable type + Serial.print("rawData["); // array name + Serial.print(results->rawlen - 1, DEC); // array size + Serial.print("] = {"); // Start declaration + + // Dump data + for (int i = 1; i < results->rawlen; i++) { + Serial.print(results->rawbuf[i] * USECPERTICK, DEC); + if ( i < results->rawlen-1 ) Serial.print(","); // ',' not needed on last one + if (!(i & 1)) Serial.print(" "); + } + + // End declaration + Serial.print("};"); // + + // Comment + Serial.print(" // "); + encoding(results); + Serial.print(" "); + ircode(results); + + // Newline + Serial.println(""); + + // Now dump "known" codes + if (results->decode_type != UNKNOWN) { + + // Some protocols have an address + if (results->decode_type == PANASONIC) { + Serial.print("unsigned int addr = 0x"); + Serial.print(results->address, HEX); + Serial.println(";"); + } + + // All protocols have data + Serial.print("unsigned int data = 0x"); + Serial.print(results->value, HEX); + Serial.println(";"); + } +} + +//+============================================================================= +// The repeating section of the code +// +void loop ( ) +{ + decode_results results; // Somewhere to store the results + + if (irrecv.decode(&results)) { // Grab an IR code + dumpInfo(&results); // Output the results + dumpRaw(&results); // Output the results in RAW format + dumpCode(&results); // Output the results as source code + Serial.println(""); // Blank line between entries + irrecv.resume(); // Prepare for the next value + } +} diff --git a/arduino/ir/irsend/irsend.ino b/arduino/ir/irsend/irsend.ino new file mode 100644 index 0000000..c30aac6 --- /dev/null +++ b/arduino/ir/irsend/irsend.ino @@ -0,0 +1,46 @@ +/* + * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend + * An IR LED must be connected to Arduino PWM pin 3. + * Version 0.1 July, 2009 + * Copyright 2009 Ken Shirriff + * http://arcfn.com + */ + + +// arduino ~3号引脚接940纳米发送头的长引脚 +// 短引脚接100欧电阻,再接GND + +#include + +IRsend irsend; + +void setup() +{ + Serial.begin(9600); +} + +void loop() { + + // 电信机顶盒用NEC发送 + + irsend.sendNEC(0xCD3201FE, 32); // 音量+ + Serial.println("+"); + delay(1000); + irsend.sendNEC(0xCD32817E, 32); // 音量- + Serial.println("-"); + delay(1000); + + + // 小米电视遥控 + int khz = 38; // 38kHz carrier frequency for the NEC protocol + // xiaomi increase volume signal + unsigned int ivs[] = {1000,600, 550,1150, 600,600, 550,900, 550,1150, 600,550, 600,600, 550,1450, 550,1200, 550,600, 550,600, 550}; + // xiaomi decrease volume signal + unsigned int dvs[] = {1050,550, 650,1050, 650,500, 650,800, 650,1100, 650,500, 650,500, 650,1400, 650,1350, 650,500, 650,800, 650}; + irsend.sendRaw(ivs, sizeof(ivs) / sizeof(ivs[0]), khz); + Serial.println("tv+"); + delay(1000); + irsend.sendRaw(dvs, sizeof(dvs) / sizeof(dvs[0]), khz); + Serial.println("tv-"); + delay(1000); +} diff --git a/documents/ArduinoClockInterrupt.md b/documents/ArduinoClockInterrupt.md new file mode 100644 index 0000000..b89fe99 --- /dev/null +++ b/documents/ArduinoClockInterrupt.md @@ -0,0 +1,126 @@ +# arduino clock interrupt + +## Clock Select Bit Description + + +|CS02|CS01|CS00|Description| +|---|---|---|---| +|0|0|0|no clock source (Timer/Counter stopped)| +|0|0|1|clk/1 (no prescaler)| +|0|1|0|clk/8 (from prescaler)| +|0|1|1|clk/64 (from prescaler)| +|1|0|0|clk/256 (from prescaler)| +|1|0|1|clk/1024 (from prescaler)| +|1|1|0|external clock source on T0 pin. clock falling edge| +|1|1|1|external clock source on T0 pin. clock rising edge| + + + +|CS12|CS11|CS10|Description| +|---|---|---|---| +|0|0|0|no clock source (Timer/Counter stopped)| +|0|0|1|clk/1 (no prescaler)| +|0|1|0|clk/8 (from prescaler)| +|0|1|1|clk/64 (from prescaler)| +|1|0|0|clk/256 (from prescaler)| +|1|0|1|clk/1024 (from prescaler)| +|1|1|0|external clock source on T1 pin. clock falling edge| +|1|1|1|external clock source on T1 pin. clock rising edge| + + +|CS22|CS21|CS20|Description| +|---|---|---|---| +|0|0|0|no clock source (Timer/Counter stopped)| +|0|0|1|clkT2S/1 (no prescaler)| +|0|1|0|clkT2S/8 (from prescaler)| +|0|1|1|clkT2S/64 (from prescaler)| + +## Compare Match Register计算方法 + +arduino有三个时钟计数器:Timer0、Timer1、Timer2。 + +arduino的时钟频率是16MHz,所以每个嘀嗒(tick)代表1/16000000秒(约为63ns)。而arduino的Timer0、Timer2的时钟计数器是8位、Timer1是16位。因此这就意味着就算把值设置成最大的,对于8位的将以256/1600000(约16us),对于16位将以65536/16000000(约4ms)的频率触发。因此如果想让它频率变得更低一点,比如一秒触发一次就有点不现实。 + +除非可以利用预分频器(prescaler)来控制时钟计数器的增加方式: + +`(时钟计数频率(Hz)) = 16MHz / prescaler` + +所以当prescaler=1,时钟计数频率=16MHz;当prescaler=64,时钟计数频率=250KHz。 + +如上表所述,prescaler只能在1, 8, 64, 256, 1024中取值。 + +所以: + +`(计数器触发频率(Hz)) = 16MHz / ( prescaler*(CompareMatchRegister+1) )` + +变换一下上式: + +`CompareMatchRegister = 16MHz / ( prescaler*(计数器触发频率(Hz)) ) - 1` + +**注意:Timer0、Timer1的CompareMatchRegister必需小于256;Timer1的CompareMatchRegister必需小于65536** + +所以如果想要1Hz的触发频率,则`CompareMatchRegister = 16MHz / ( 1024*1) - 1 = 15624`,这里的prescaler=1024,因为prescaler取到最大值了CompareMatchRegister还等于15624,256<15624<65536,所以必需要用到Timer1。 + + +## 示例代码 + +``` +void setup(){ + + cli();//stop interrupts + + //设置timer0会影响到loop函数里调用的delay,会使其失效 + //set timer0 interrupt at 2kHz + TCCR0A = 0;// set entire TCCR0A register to 0 + TCCR0B = 0;// same for TCCR0B + TCNT0 = 0;//initialize counter value to 0 + // set compare match register for 2khz increments + OCR0A = 124;// = (16*10^6) / (2000*64) - 1 (must be <256) + // turn on CTC mode + TCCR0A |= (1 << WGM01); + // Set CS01 and CS00 bits for 64 prescaler (参考上表) + TCCR0B |= (1 << CS01) | (1 << CS00); + // enable timer compare interrupt + TIMSK0 |= (1 << OCIE0A); + + //set timer1 interrupt at 1Hz + TCCR1A = 0;// set entire TCCR1A register to 0 + TCCR1B = 0;// same for TCCR1B + TCNT1 = 0;//initialize counter value to 0 + // set compare match register for 1hz increments + OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536) + // turn on CTC mode + TCCR1B |= (1 << WGM12); + // Set CS10 and CS12 bits for 1024 prescaler (参考上表) + TCCR1B |= (1 << CS12) | (1 << CS10); + // enable timer compare interrupt + TIMSK1 |= (1 << OCIE1A); + + //set timer2 interrupt at 8kHz + TCCR2A = 0;// set entire TCCR2A register to 0 + TCCR2B = 0;// same for TCCR2B + TCNT2 = 0;//initialize counter value to 0 + // set compare match register for 8khz increments + OCR2A = 249;// = (16*10^6) / (8000*8) - 1 (must be <256) + // turn on CTC mode + TCCR2A |= (1 << WGM21); + // Set CS21 bit for 8 prescaler (参考上表) + TCCR2B |= (1 << CS21); + // enable timer compare interrupt + TIMSK2 |= (1 << OCIE2A); + + sei();//allow interrupts + +}//end setup + +void loop() { } + +ISR(TIMER0_COMPA_vect){ /* TODO */ } +ISR(TIMER1_COMPA_vect){ /* TODO */ } +ISR(TIMER2_COMPA_vect){ /* TODO */ } +``` + + + +## 注 +1. 1MHz = 1 * 1000KHz = 1 * 1000 * 1000Hz,这里是1000不是1024 \ No newline at end of file diff --git "a/documents/\351\201\245\346\216\247\347\272\242\345\244\226\347\272\277\347\274\226\347\240\201.md" "b/documents/\351\201\245\346\216\247\347\272\242\345\244\226\347\272\277\347\274\226\347\240\201.md" new file mode 100644 index 0000000..54d8db4 --- /dev/null +++ "b/documents/\351\201\245\346\216\247\347\272\242\345\244\226\347\272\277\347\274\226\347\240\201.md" @@ -0,0 +1,45 @@ + +## 1. 电信机顶盒遥控编码 +||格式|编码| +|---|---|---| +|电源|NEC|`CD328F70`| +|待机|NEC|`CD323BC4`| +|频道+|NEC|`CD32A15E`| +|频道-|NEC|`CD32619E`| +|音量+|NEC|`CD3201FE`| +|音量-|NEC|`CD32817E`| +|返回|NEC|`CD32A35C`| +|确定|NEC|`CD32738C`| +|上|NEC|`CD3253AC`| +|下|NEC|`CD324BB4`| +|左|NEC|`CD329966`| +|右|NEC|`CD32837C`| +|上页|NEC|`CD32BB44`| +|下页|NEC|`CD3231CE`| +|0|NEC|`CD32E11E`| +|1|NEC|`CD3249B6`| +|2|NEC|`CD32C936`| +|3|NEC|`CD3233CC`| +|4|NEC|`CD32718E`| +|5|NEC|`CD32F10E`| +|6|NEC|`CD3213EC`| +|7|NEC|`CD3251AE`| +|8|NEC|`CD32D12E`| +|9|NEC|`CD3223DC`| + + +## 2. 小米电视遥控编码 + +||格式|编码|RawData| +|---|---|---|---| +|电源|UNKNOWN|`5E7DB3DC`|`{1100,500, 650,500, 650,1400, 650,1350, 650,500, 650,1400, 650,500, 650,1350, 650,550, 650,1350, 650,1350, 650}`| +|上|UNKNOWN|`3F9089B2`|`{1100,500, 600,1150, 650,500, 600,850, 650,1050, 650,550, 650,500, 650,800, 650,800, 650,1050, 650,1400, 650}`| +|下|UNKNOWN|`B23FB1E9`|`{1050,550, 600,1150, 600,550, 600,850, 650,1050, 650,550, 600,550, 600,850, 650,1050, 650,1100, 650,500, 650}`| +|左|UNKNOWN|`8753BA5C`|`{1000,600, 600,1150, 550,600, 550,900, 550,1200, 550,600, 550,600, 550,1200, 550,1450, 550,900, 550,900, 550}`| +|右|UNKNOWN|`69893291`|`{1000,600, 550,1200, 550,600, 550,900, 550,1150, 600,600, 550,600, 550,1450, 550,600, 600,600, 550,1150, 550}`| +|确定|UNKNOWN|`76A77416`|`{1000,600, 550,1200, 550,600, 550,900, 550,1150, 600,600, 550,600, 550,1450, 550,900, 550,600, 550,1500, 550}`| +|HOME|UNKNOWN|`F874E0F8`|`{1000,600, 550,1200, 550,600, 550,900, 550,1150, 600,600, 550,600, 550,1150, 600,600, 550,900, 550,1150, 550}`| +|返回|UNKNOWN|`DE3AA631`|`{950,650, 500,1200, 550,650, 550,850, 550,1250, 500,650, 450,650, 550,900, 550,1500, 500,1250, 500,900, 550}`| +|MENU|UNKNOWN|`F574DC41`|`{1000,600, 550,1200, 550,600, 550,900, 550,1200, 550,600, 550,600, 550,900, 550,600, 550,1200, 550,1150, 600}`| +|音量+|UNKNOWN|`8753BA5C`|`{1000,600, 550,1150, 600,600, 550,900, 550,1150, 600,550, 600,600, 550,1450, 550,1200, 550,600, 550,600, 550}`| +|音量-|UNKNOWN|`8453B5A5`|`{1050,550, 650,1050, 650,500, 650,800, 650,1100, 650,500, 650,500, 650,1400, 650,1350, 650,500, 650,800, 650}`| diff --git a/tools/AceBox/AceBox.xcodeproj/project.pbxproj b/tools/AceBox/AceBox.xcodeproj/project.pbxproj index 617ae79..c4d9a97 100644 --- a/tools/AceBox/AceBox.xcodeproj/project.pbxproj +++ b/tools/AceBox/AceBox.xcodeproj/project.pbxproj @@ -128,6 +128,12 @@ 50A4F2741AF2154100DB7E36 = { CreatedOnToolsVersion = 6.3.1; DevelopmentTeam = VR7L9Q5L2E; + ProvisioningStyle = Automatic; + SystemCapabilities = { + com.apple.BackgroundModes = { + enabled = 1; + }; + }; }; }; }; @@ -285,12 +291,15 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = VR7L9Q5L2E; INFOPLIST_FILE = AceBox/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tencent.voip.ace; PRODUCT_NAME = Ace; + PROVISIONING_PROFILE_SPECIFIER = ""; }; name = Debug; }; @@ -298,12 +307,15 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = VR7L9Q5L2E; INFOPLIST_FILE = AceBox/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tencent.voip.ace; PRODUCT_NAME = Ace; + PROVISIONING_PROFILE_SPECIFIER = ""; }; name = Release; }; diff --git a/tools/AceBox/AceBox.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate b/tools/AceBox/AceBox.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate index edc0110..b20ba3c 100644 Binary files a/tools/AceBox/AceBox.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate and b/tools/AceBox/AceBox.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/tools/AceBox/AceBox/AppDelegate.swift b/tools/AceBox/AceBox/AppDelegate.swift index 5cf83f7..469c173 100644 --- a/tools/AceBox/AceBox/AppDelegate.swift +++ b/tools/AceBox/AceBox/AppDelegate.swift @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/tools/AceBox/AceBox/Base.lproj/LaunchScreen.xib b/tools/AceBox/AceBox/Base.lproj/LaunchScreen.xib index 816612e..6e80504 100644 --- a/tools/AceBox/AceBox/Base.lproj/LaunchScreen.xib +++ b/tools/AceBox/AceBox/Base.lproj/LaunchScreen.xib @@ -1,10 +1,19 @@ - - + + + + + - + + + + + HelveticaNeue + + @@ -15,24 +24,24 @@ - - + + - + diff --git a/tools/AceBox/AceBox/Base.lproj/Main.storyboard b/tools/AceBox/AceBox/Base.lproj/Main.storyboard index cc32045..d68453c 100644 --- a/tools/AceBox/AceBox/Base.lproj/Main.storyboard +++ b/tools/AceBox/AceBox/Base.lproj/Main.storyboard @@ -5,7 +5,7 @@ - + diff --git a/tools/AceBox/AceBox/Info.plist b/tools/AceBox/AceBox/Info.plist index 222ac74..6a070d0 100644 --- a/tools/AceBox/AceBox/Info.plist +++ b/tools/AceBox/AceBox/Info.plist @@ -20,8 +20,20 @@ ???? CFBundleVersion 1 + LSApplicationCategoryType + + en + LSRequiresIPhoneOS + NSLocationAlwaysAndWhenInUseUsageDescription + 需要始终访问你的地理位置 + NSLocationWhenInUseUsageDescription + 需要在使用应用时访问你的地理位置 + UIBackgroundModes + + location + UILaunchStoryboardName LaunchScreen UIMainStoryboardFile diff --git a/tools/AceBox/AceBox/SecondViewController.swift b/tools/AceBox/AceBox/SecondViewController.swift index b403572..3e2c11b 100644 --- a/tools/AceBox/AceBox/SecondViewController.swift +++ b/tools/AceBox/AceBox/SecondViewController.swift @@ -7,20 +7,94 @@ // import UIKit +import CoreLocation -class SecondViewController: UIViewController { +class SecondViewController: UIViewController, CLLocationManagerDelegate { + + var locationMgr:CLLocationManager! + var cnt:Int = 0 + var labelGPS:UILabel! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. //view.backgroundColor = UIColor.blueColor() view.backgroundColor = UIColor(red: 0, green: 0.47843137250000001, blue: 1, alpha: 1) + + locationMgr = CLLocationManager() + locationMgr.desiredAccuracy = kCLLocationAccuracyBestForNavigation + if #available(iOS 9.0, *) { + locationMgr.allowsBackgroundLocationUpdates = true + } + locationMgr.pausesLocationUpdatesAutomatically = false + + //locationMgr.distanceFilter = 50 + + locationMgr.requestAlwaysAuthorization() + + locationMgr.delegate = self + + if CLLocationManager.locationServicesEnabled() { + locationMgr.startUpdatingLocation() + } else { + print("no location service") + } + + labelGPS = UILabel(frame: CGRect(x: 10, y: 20, width: 300, height: 100)) + labelGPS.text = "searching" + labelGPS.textColor = UIColor.white + labelGPS.numberOfLines = 3 + self.view.addSubview(labelGPS) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } + + + func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { + print(error) + } + + func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + if locations.count > 0 { + let locationInfo = locations.last! + + let msg = "次数:\(cnt)\n经度:\(locationInfo.coordinate.longitude)\n纬度:\(locationInfo.coordinate.latitude)" + + cnt += 1 + + //let alert:UIAlertView = UIAlertView(title:"Get Location", message:msg, delegate:nil, cancelButtonTitle:"Yes") + //alert.show() + + print(msg) + + labelGPS.text = msg + /* + let fileManager = FileManager.default + let filePath:String = NSHomeDirectory() + "/Documents/gps.data" + let exist = fileManager.fileExists(atPath: filePath) + if exist { + print("exist \(filePath)") + let data = "\(cnt) \(locationInfo.coordinate.longitude) \(locationInfo.coordinate.latitude)\n" + //try! data.write(toFile: filePath, atomically: true, encoding: String.Encoding.utf8) + + let writeHandler = try? FileHandle(forWritingAtPath: filePath) + writeHandler!?.seekToEndOfFile() + writeHandler!?.write(data.data(using: String.Encoding.utf8, allowLossyConversion: true)!) + + let rd = fileManager.contents(atPath: filePath) + print("content: \(String(data:rd!, encoding: String.Encoding.utf8))") + } else { + print(NSHomeDirectory()) + try! fileManager.createDirectory(atPath: NSHomeDirectory()+"/Documents/", + withIntermediateDirectories: true, attributes: nil) + let createSuccess = fileManager.createFile(atPath: filePath, contents: nil, attributes: nil) + print("create file \(filePath) return \(createSuccess)") + }*/ + } + } }