@ -0,0 +1,118 @@ | |||||
package gq.yigit.mycity; | |||||
import android.content.Context; | |||||
import android.net.Uri; | |||||
import android.os.Bundle; | |||||
import android.support.v4.app.Fragment; | |||||
import android.view.LayoutInflater; | |||||
import android.view.View; | |||||
import android.view.ViewGroup; | |||||
import com.google.android.gms.maps.MapView; | |||||
import com.google.android.gms.maps.model.LatLng; | |||||
import java.util.ArrayList; | |||||
/** | |||||
* A simple {@link Fragment} subclass. | |||||
* Activities that contain this fragment must implement the | |||||
* {@link CrashMapFragment.OnFragmentInteractionListener} interface | |||||
* to handle interaction events. | |||||
* Use the {@link CrashMapFragment#newInstance} factory method to | |||||
* create an instance of this fragment. | |||||
*/ | |||||
public class CrashMapFragment extends Fragment { | |||||
// TODO: Rename parameter arguments, choose names that match | |||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER | |||||
private static final String ARG_PARAM1 = "param1"; | |||||
private static final String ARG_PARAM2 = "param2"; | |||||
// TODO: Rename and change types of parameters | |||||
private String mParam1; | |||||
private String mParam2; | |||||
MapView mMapView; | |||||
private GoogleMap googleMap; | |||||
ArrayList<LatLng> markerPoints; | |||||
private const String API_KEY = "AIzaSyCe3xvqc_FyrPDvu7MptJ3h2GyR1-EpCLw"; | |||||
private OnFragmentInteractionListener mListener; | |||||
public CrashMapFragment() { | |||||
} | |||||
/** | |||||
* Use this factory method to create a new instance of | |||||
* this fragment using the provided parameters. | |||||
* | |||||
* @param param1 Parameter 1. | |||||
* @param param2 Parameter 2. | |||||
* @return A new instance of fragment CrashMapFragment. | |||||
*/ | |||||
// TODO: Rename and change types and number of parameters | |||||
public static CrashMapFragment newInstance(String param1, String param2) { | |||||
CrashMapFragment fragment = new CrashMapFragment(); | |||||
Bundle args = new Bundle(); | |||||
args.putString(ARG_PARAM1, param1); | |||||
args.putString(ARG_PARAM2, param2); | |||||
fragment.setArguments(args); | |||||
return fragment; | |||||
} | |||||
@Override | |||||
public void onCreate(Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
if (getArguments() != null) { | |||||
mParam1 = getArguments().getString(ARG_PARAM1); | |||||
mParam2 = getArguments().getString(ARG_PARAM2); | |||||
} | |||||
} | |||||
@Override | |||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |||||
Bundle savedInstanceState) { | |||||
// Inflate the layout for this fragment | |||||
return inflater.inflate(R.layout.fragment_crash_map, container, false); | |||||
} | |||||
// TODO: Rename method, update argument and hook method into UI event | |||||
public void onButtonPressed(Uri uri) { | |||||
if (mListener != null) { | |||||
mListener.onFragmentInteraction(uri); | |||||
} | |||||
} | |||||
@Override | |||||
public void onAttach(Context context) { | |||||
super.onAttach(context); | |||||
if (context instanceof OnFragmentInteractionListener) { | |||||
mListener = (OnFragmentInteractionListener) context; | |||||
} else { | |||||
throw new RuntimeException(context.toString() | |||||
+ " must implement OnFragmentInteractionListener"); | |||||
} | |||||
} | |||||
@Override | |||||
public void onDetach() { | |||||
super.onDetach(); | |||||
mListener = null; | |||||
} | |||||
/** | |||||
* This interface must be implemented by activities that contain this | |||||
* fragment to allow an interaction in this fragment to be communicated | |||||
* to the activity and potentially other fragments contained in that | |||||
* activity. | |||||
* <p> | |||||
* See the Android Training lesson <a href= | |||||
* "http://developer.android.com/training/basics/fragments/communicating.html" | |||||
* >Communicating with Other Fragments</a> for more information. | |||||
*/ | |||||
public interface OnFragmentInteractionListener { | |||||
// TODO: Update argument type and name | |||||
void onFragmentInteraction(Uri uri); | |||||
} | |||||
} |
@ -0,0 +1,14 @@ | |||||
<?xml version="1.0" encoding="utf-8"?> | |||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | |||||
android:width="512dp" | |||||
android:height="512dp" | |||||
android:viewportWidth="512" | |||||
android:viewportHeight="512"> | |||||
<path | |||||
android:fillColor="#000000" | |||||
android:pathData="M446.812,493.966l-67.499-142.781c-1.347-2.849-3.681-5.032-6.48-6.223l-33.58-14.949l58.185-97.518 c0.139-0.234,0.27-0.471,0.395-0.713c11.568-22.579,17.434-46.978,17.434-72.515c0-42.959-16.846-83.233-47.435-113.402 C337.248,15.703,296.73-0.588,253.745,0.016c-41.748,0.579-81.056,17.348-110.685,47.22 c-29.626,29.87-46.078,69.313-46.326,111.066c-0.152,25.515,5.877,50.923,17.431,73.479c0.124,0.241,0.255,0.479,0.394,0.713 l58.184,97.517l-33.774,15.031c-2.763,1.229-4.993,3.408-6.285,6.142L65.187,493.966c-2.259,4.775-1.306,10.453,2.388,14.23 c3.693,3.777,9.345,4.859,14.172,2.711l84.558-37.646l84.558,37.646c3.271,1.455,7.006,1.455,10.277,0l84.558-37.646 l84.558,37.646c1.652,0.735,3.401,1.093,5.135,1.093c3.331,0,6.608-1.318,9.037-3.803 C448.119,504.419,449.071,498.743,446.812,493.966z M136.473,219.906c-9.73-19.132-14.599-39.805-14.47-61.453 c0.428-72.429,59.686-132.17,132.094-133.173c36.166-0.486,70.263,13.199,95.993,38.576 c25.738,25.383,39.911,59.267,39.911,95.412c0,21.359-4.869,41.757-14.473,60.638L266.85,402.054 c-3.318,5.56-8.692,6.16-10.849,6.16c-2.158,0-7.532-0.6-10.849-6.16L136.473,219.906z M350.834,447.891 c-3.271-1.455-7.006-1.455-10.277,0l-84.558,37.646l-84.558-37.646c-3.271-1.455-7.006-1.455-10.277,0l-58.578,26.08 l50.938-107.749l32.258-14.356l37.668,63.133c6.904,11.572,19.072,18.481,32.547,18.481c13.475,0,25.643-6.909,32.547-18.48 l37.668-63.133l32.261,14.361l50.935,107.744L350.834,447.891z" /> | |||||
<path | |||||
android:fillColor="#000000" | |||||
android:pathData="M256.004,101.607c-31.794,0-57.659,25.865-57.659,57.658s25.865,57.658,57.659,57.658 c31.793,0.001,57.658-25.865,57.658-57.658S287.797,101.607,256.004,101.607z M256.004,191.657 c-17.861,0.001-32.393-14.529-32.393-32.392c0-17.861,14.531-32.392,32.393-32.392c17.861,0,32.392,14.531,32.392,32.392 S273.865,191.657,256.004,191.657z" /> | |||||
</vector> |
@ -0,0 +1,10 @@ | |||||
<?xml version="1.0" encoding="utf-8"?> | |||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||||
android:layout_width="fill_parent" | |||||
android:layout_height="fill_parent" > | |||||
<com.google.android.gms.maps.MapView | |||||
android:id="@+id/mapView" | |||||
android:layout_width="match_parent" | |||||
android:layout_height="match_parent" /> | |||||
</RelativeLayout> |
@ -1,5 +0,0 @@ | |||||
{ | |||||
"qr": "127.0.0.3", | |||||
"intersection": "127.0.0.1", | |||||
"ambulance": "127.0.0.1" | |||||
} |
@ -1,12 +0,0 @@ | |||||
{ | |||||
"usernames": { | |||||
"qr": "admin", | |||||
"ambulance": "yigit", | |||||
"intersection": "admin" | |||||
}, | |||||
"passwords": { | |||||
"qr": "admin", | |||||
"ambulance": "Ygtclksbl1", | |||||
"intersection": "admin" | |||||
} | |||||
} |
@ -0,0 +1,4 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<project version="4"> | |||||
<component name="SerialMonitorSettings" BaudRate="9600" LineEndingsIndex="0" /> | |||||
</project> |
@ -0,0 +1,6 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<project version="4"> | |||||
<component name="VcsDirectoryMappings"> | |||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" /> | |||||
</component> | |||||
</project> |
@ -0,0 +1,15 @@ | |||||
cmake_minimum_required(VERSION 2.8.4) | |||||
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/ArduinoToolchain.cmake) | |||||
set(PROJECT_NAME light_control) | |||||
project(${PROJECT_NAME}) | |||||
set(${CMAKE_PROJECT_NAME}_SKETCH light_control.ino) | |||||
#### Uncomment below additional settings as needed. | |||||
# set(${CMAKE_PROJECT_NAME}_BOARD mega) | |||||
# set(${CMAKE_PROJECT_NAME}_PORT /dev/ttyACM0) | |||||
# set(mega.build.mcu atmega2560) | |||||
# set(mega.upload.protocol wiring) | |||||
# set(mega.upload.speed 115200) | |||||
generate_arduino_firmware(${CMAKE_PROJECT_NAME}) |
@ -0,0 +1,89 @@ | |||||
#=============================================================================# | |||||
# Author: Tomasz Bogdal (QueezyTheGreat) | |||||
# Home: https://github.com/queezythegreat/arduino-cmake | |||||
# | |||||
# This Source Code Form is subject to the terms of the Mozilla Public | |||||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | |||||
# You can obtain one at http://mozilla.org/MPL/2.0/. | |||||
#=============================================================================# | |||||
set(CMAKE_SYSTEM_NAME Arduino) | |||||
set(CMAKE_C_COMPILER avr-gcc) | |||||
set(CMAKE_CXX_COMPILER avr-g++) | |||||
# Add current directory to CMake Module path automatically | |||||
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/Platform/Arduino.cmake) | |||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}) | |||||
endif() | |||||
#=============================================================================# | |||||
# System Paths # | |||||
#=============================================================================# | |||||
if(UNIX) | |||||
include(Platform/UnixPaths) | |||||
if(APPLE) | |||||
list(APPEND CMAKE_SYSTEM_PREFIX_PATH ~/Applications | |||||
/Applications | |||||
/Developer/Applications | |||||
/sw # Fink | |||||
/opt/local) # MacPorts | |||||
endif() | |||||
elseif(WIN32) | |||||
include(Platform/WindowsPaths) | |||||
endif() | |||||
#=============================================================================# | |||||
# Detect Arduino SDK # | |||||
#=============================================================================# | |||||
if(NOT ARDUINO_SDK_PATH) | |||||
set(ARDUINO_PATHS) | |||||
foreach(DETECT_VERSION_MAJOR 1) | |||||
foreach(DETECT_VERSION_MINOR RANGE 5 0) | |||||
list(APPEND ARDUINO_PATHS arduino-${DETECT_VERSION_MAJOR}.${DETECT_VERSION_MINOR}) | |||||
foreach(DETECT_VERSION_PATCH RANGE 3 0) | |||||
list(APPEND ARDUINO_PATHS arduino-${DETECT_VERSION_MAJOR}.${DETECT_VERSION_MINOR}.${DETECT_VERSION_PATCH}) | |||||
endforeach() | |||||
endforeach() | |||||
endforeach() | |||||
foreach(VERSION RANGE 23 19) | |||||
list(APPEND ARDUINO_PATHS arduino-00${VERSION}) | |||||
endforeach() | |||||
if(UNIX) | |||||
file(GLOB SDK_PATH_HINTS /usr/share/arduino* | |||||
/opt/local/arduino* | |||||
/opt/arduino* | |||||
/usr/local/share/arduino*) | |||||
elseif(WIN32) | |||||
set(SDK_PATH_HINTS "C:\\Program Files\\Arduino" | |||||
"C:\\Program Files (x86)\\Arduino" | |||||
) | |||||
endif() | |||||
list(SORT SDK_PATH_HINTS) | |||||
list(REVERSE SDK_PATH_HINTS) | |||||
endif() | |||||
find_path(ARDUINO_SDK_PATH | |||||
NAMES lib/version.txt | |||||
PATH_SUFFIXES share/arduino | |||||
Arduino.app/Contents/Resources/Java/ | |||||
Arduino.app/Contents/Java/ | |||||
${ARDUINO_PATHS} | |||||
HINTS ${SDK_PATH_HINTS} | |||||
DOC "Arduino SDK path.") | |||||
if(ARDUINO_SDK_PATH) | |||||
list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/avr) | |||||
list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/avr/utils) | |||||
else() | |||||
message(FATAL_ERROR "Could not find Arduino SDK (set ARDUINO_SDK_PATH)!") | |||||
endif() | |||||
set(ARDUINO_CPUMENU) | |||||
if(ARDUINO_CPU) | |||||
set(ARDUINO_CPUMENU ".menu.cpu.${ARDUINO_CPU}") | |||||
endif(ARDUINO_CPU) | |||||
@ -0,0 +1,211 @@ | |||||
#include <Arduino.h> | |||||
/* | |||||
WiFiTelnetToSerial - Example Transparent UART to Telnet Server for esp8266 | |||||
Copyright (c) 2015 Hristo Gochkov. All rights reserved. | |||||
This file is part of the ESP8266WiFi library for Arduino environment. | |||||
This library is free software; you can redistribute it and/or | |||||
modify it under the terms of the GNU Lesser General Public | |||||
License as published by the Free Software Foundation; either | |||||
version 2.1 of the License, or (at your option) any later version. | |||||
This library is distributed in the hope that it will be useful, | |||||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
Lesser General Public License for more details. | |||||
You should have received a copy of the GNU Lesser General Public | |||||
License along with this library; if not, write to the Free Software | |||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |||||
*/ | |||||
#include <ESP8266WiFi.h> | |||||
#include <algorithm> // std::min | |||||
#ifndef STASSID | |||||
#define STASSID "ZyXEL5500bT5" | |||||
#define STAPSK "eBusgxczl5" | |||||
#endif | |||||
/* | |||||
SWAP_PINS: | |||||
0: use Serial1 for logging (legacy example) | |||||
1: configure Hardware Serial port on RX:GPIO13 TX:GPIO15 | |||||
and use SoftwareSerial for logging on | |||||
standard Serial pins RX:GPIO3 and TX:GPIO1 | |||||
*/ | |||||
#define SWAP_PINS 0 | |||||
/* | |||||
SERIAL_LOOPBACK | |||||
0: normal serial operations | |||||
1: RX-TX are internally connected (loopback) | |||||
*/ | |||||
#define SERIAL_LOOPBACK 0 | |||||
#define BAUD_SERIAL 115200 | |||||
#define BAUD_LOGGER 115200 | |||||
#define RXBUFFERSIZE 1024 | |||||
//////////////////////////////////////////////////////////// | |||||
#if SERIAL_LOOPBACK | |||||
#undef BAUD_SERIAL | |||||
#define BAUD_SERIAL 3000000 | |||||
#include <esp8266_peri.h> | |||||
#endif | |||||
#if SWAP_PINS | |||||
#include <SoftwareSerial.h> | |||||
SoftwareSerial* logger = nullptr; | |||||
#else | |||||
#define logger (&Serial1) | |||||
#endif | |||||
#define STACK_PROTECTOR 512 // bytes | |||||
//how many clients should be able to telnet to this ESP8266 | |||||
#define MAX_SRV_CLIENTS 2 | |||||
const char* ssid = STASSID; | |||||
const char* password = STAPSK; | |||||
const int port = 23; | |||||
WiFiServer server(port); | |||||
WiFiClient serverClients[MAX_SRV_CLIENTS]; | |||||
void setup() { | |||||
Serial.begin(BAUD_SERIAL); | |||||
Serial.setRxBufferSize(RXBUFFERSIZE); | |||||
#if SWAP_PINS | |||||
Serial.swap(); | |||||
// Hardware serial is now on RX:GPIO13 TX:GPIO15 | |||||
// use SoftwareSerial on regular RX(3)/TX(1) for logging | |||||
logger = new SoftwareSerial(3, 1); | |||||
logger->begin(BAUD_LOGGER); | |||||
logger->println("\n\nUsing SoftwareSerial for logging"); | |||||
#else | |||||
logger->begin(BAUD_LOGGER); | |||||
logger->println("\n\nUsing Serial1 for logging"); | |||||
#endif | |||||
logger->println(ESP.getFullVersion()); | |||||
logger->printf("Serial baud: %d (8n1: %d KB/s)\n", BAUD_SERIAL, BAUD_SERIAL * 8 / 10 / 1024); | |||||
logger->printf("Serial receive buffer size: %d bytes\n", RXBUFFERSIZE); | |||||
#if SERIAL_LOOPBACK | |||||
USC0(0) |= (1 << UCLBE); // incomplete HardwareSerial API | |||||
logger->println("Serial Internal Loopback enabled"); | |||||
#endif | |||||
WiFi.mode(WIFI_STA); | |||||
WiFi.begin(ssid, password); | |||||
logger->print("\nConnecting to "); | |||||
logger->println(ssid); | |||||
while (WiFi.status() != WL_CONNECTED) { | |||||
logger->print('.'); | |||||
delay(500); | |||||
} | |||||
logger->println(); | |||||
logger->print("connected, address="); | |||||
logger->println(WiFi.localIP()); | |||||
//start server | |||||
server.begin(); | |||||
server.setNoDelay(true); | |||||
logger->print("Ready! Use 'telnet "); | |||||
logger->print(WiFi.localIP()); | |||||
logger->printf(" %d' to connect\n", port); | |||||
} | |||||
void loop() { | |||||
//check if there are any new clients | |||||
if (server.hasClient()) { | |||||
//find free/disconnected spot | |||||
int i; | |||||
for (i = 0; i < MAX_SRV_CLIENTS; i++) | |||||
if (!serverClients[i]) { // equivalent to !serverClients[i].connected() | |||||
serverClients[i] = server.available(); | |||||
logger->print("New client: index "); | |||||
logger->print(i); | |||||
break; | |||||
} | |||||
//no free/disconnected spot so reject | |||||
if (i == MAX_SRV_CLIENTS) { | |||||
server.available().println("busy"); | |||||
// hints: server.available() is a WiFiClient with short-term scope | |||||
// when out of scope, a WiFiClient will | |||||
// - flush() - all data will be sent | |||||
// - stop() - automatically too | |||||
logger->printf("server is busy with %d active connections\n", MAX_SRV_CLIENTS); | |||||
} | |||||
} | |||||
//check TCP clients for data | |||||
#if 1 | |||||
// Incredibly, this code is faster than the bufferred one below - #4620 is needed | |||||
// loopback/3000000baud average 348KB/s | |||||
for (int i = 0; i < MAX_SRV_CLIENTS; i++) | |||||
while (serverClients[i].available() && Serial.availableForWrite() > 0) { | |||||
// working char by char is not very efficient | |||||
Serial.write(serverClients[i].read()); | |||||
} | |||||
#else | |||||
// loopback/3000000baud average: 312KB/s | |||||
for (int i = 0; i < MAX_SRV_CLIENTS; i++) | |||||
while (serverClients[i].available() && Serial.availableForWrite() > 0) { | |||||
size_t maxToSerial = std::min(serverClients[i].available(), Serial.availableForWrite()); | |||||
maxToSerial = std::min(maxToSerial, (size_t)STACK_PROTECTOR); | |||||
uint8_t buf[maxToSerial]; | |||||
size_t tcp_got = serverClients[i].read(buf, maxToSerial); | |||||
size_t serial_sent = Serial.write(buf, tcp_got); | |||||
if (serial_sent != maxToSerial) { | |||||
logger->printf("len mismatch: available:%zd tcp-read:%zd serial-write:%zd\n", maxToSerial, tcp_got, serial_sent); | |||||
} | |||||
} | |||||
#endif | |||||
// determine maximum output size "fair TCP use" | |||||
// client.availableForWrite() returns 0 when !client.connected() | |||||
size_t maxToTcp = 0; | |||||
for (int i = 0; i < MAX_SRV_CLIENTS; i++) | |||||
if (serverClients[i]) { | |||||
size_t afw = serverClients[i].availableForWrite(); | |||||
if (afw) { | |||||
if (!maxToTcp) { | |||||
maxToTcp = afw; | |||||
} else { | |||||
maxToTcp = std::min(maxToTcp, afw); | |||||
} | |||||
} else { | |||||
// warn but ignore congested clients | |||||
logger->println("one client is congested"); | |||||
} | |||||
} | |||||
//check UART for data | |||||
size_t len = std::min((size_t)Serial.available(), maxToTcp); | |||||
len = std::min(len, (size_t)STACK_PROTECTOR); | |||||
if (len) { | |||||
uint8_t sbuf[len]; | |||||
size_t serial_got = Serial.readBytes(sbuf, len); | |||||
// push UART data to all connected telnet clients | |||||
for (int i = 0; i < MAX_SRV_CLIENTS; i++) | |||||
// if client.availableForWrite() was 0 (congested) | |||||
// and increased since then, | |||||
// ensure write space is sufficient: | |||||
if (serverClients[i].availableForWrite() >= serial_got) { | |||||
size_t tcp_sent = serverClients[i].write(sbuf, serial_got); | |||||
if (tcp_sent != len) { | |||||
logger->printf("len mismatch: available:%zd serial-read:%zd tcp-write:%zd\n", len, serial_got, tcp_sent); | |||||
} | |||||
} | |||||
} | |||||
} |