Commit 421a98ac authored by yuichitamiya's avatar yuichitamiya
Browse files

Internet Distance

parent 936168d3
Pipeline #242227 passed with stage
in 36 seconds
# program
## map3cp_for _b2
``(program ver.3 circuit python for Google_map for board ver.2)``
ref. [Build a simple USB HID Macropad using Seeeduino Xiao & CircuitPython](https://andywarburton.co.uk/build-a-simple-usb-hid-macropad-using-seeeduino-xiao-circuitpython/)
ref. [SeeeduinoXIAOでCircuitPythonをインストールして動作させる](https://wiki.seeedstudio.com/jp/Seeeduino-XIAO-CircuitPython/)
- download [Seeeduino XIAO's CircuitPython bootloader .uf2](https://circuitpython.org/board/seeeduino_xiao/)
- CircuitPython 6.3.0
- download [CircuitPython Libraries](https://circuitpython.org/libraries)
- Bundle Version 6.x
- Copy the files you NEED onto the CIRCUITPY drive into the lib directory. Due to the size restrictions on this device, you won’t be able to use more than a couple before you run out of space.
ref. [Creating and Editing Code](https://learn.adafruit.com/adafruit-clue/creating-and-editing-code)
```
Naming Your Program File
CircuitPython looks for a code file on the board to run.
There are four options:
- code.txt
- code.py
- main.txt
- main.py
CircuitPython looks for those files, in that order, and then runs the first one it finds.
While we suggest using code.py as your code file
```
ref. [Adafruit HID Library](https://circuitpython.readthedocs.io/projects/hid/en/latest/examples.html#keyboard-shortcuts)
---
## map2_for_b2
``(program ver.2 for Google_map for board ver.2)``
......@@ -12,8 +50,221 @@ ref. [XIAOでMacのスクリーンショット専用USBキーを作るDIY](https
ref. Sample: [xiao_usb1.ino](../sketch/xiao_usb1/xiao_usb1.ino)
<details closed>
<summary>xiao_usb1.ino</summary>
<pre>
/*
* Sample program demonstrating TinyUSB_Mouse_and_Keyboard.h module which
* auto selects between standard Arduino Mouse.h API and TinyUSB mouse API.
* This program tests the keyboard portion alone.
*/
//Include this module whether using Arduino stack or TinyUSB stack
// https://github.com/cyborg5/TinyUSB_Mouse_and_Keyboards
#include <TinyUSB_Mouse_and_Keyboard.h>
// Launchpad sc > F5
void setup() {
Keyboard.begin(); //Unlike Arduino Keyboard.h, you must use begin.
Serial.begin(115200);
while (! Serial)delay (1);
//Serial.println("USB keyboard test");
//find terminal
Keyboard.write(KEY_F5);
Keyboard.press(KEY_LEFT_GUI);//command
delay(100);
Keyboard.write('f');
Keyboard.releaseAll();
delay(100);
// 英字モードに変更。CTL+SHIFT+;
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.write(';');
Keyboard.releaseAll();
delay(100);
Keyboard.print("terminal");
delay(500);
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
delay(200);
// New terminal windows
Keyboard.press(KEY_LEFT_GUI);
Keyboard.write('n');
Keyboard.releaseAll();
//open site
Keyboard.print("open http://yuichitamiya.fabcloud.io/fab16/");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll(); //release the control key
Serial.println("USB keyboard test completed");
};
void loop() {
}
/*
* Click below before uploading and it will type characters in this comment
*
*
*
*
*
*
*
*
*/
</pre>
</details>
---
ref. 4 button keyboard: [ss-key.ino](../sketch/ss-key/ss-key.ino)
<details closed>
<summary>ss-key.ino</summary>
<pre>
/*
XIAO USB Keyboard.example.
https://junkhack.gpl.jp/2021/03/01/make-mac-sskey-xiao/
*/
// https://github.com/cyborg5/TinyUSB_Mouse_and_Keyboard
//#include <TinyUSB_Mouse_and_Keyboard.h>
#include "TinyUSB_Mouse_and_Keyboard.h"
uint8_t pins[] = { A7 , A8 , A9 , A10 };
uint8_t Key0; //A7
uint8_t Key1; //A8
uint8_t Key2; //A9
uint8_t Key3; //A10
// 残り7Pin
void setup() {
Keyboard.begin();
// led pin
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
//
pinMode(pins[0], INPUT_PULLUP);
pinMode(pins[1], INPUT_PULLUP);
pinMode(pins[2], INPUT_PULLUP);
pinMode(pins[3], INPUT_PULLUP);
}
void loop() {
Key0 = digitalRead(pins[0]);
Key1 = digitalRead(pins[1]);
Key2 = digitalRead(pins[2]);
Key3 = digitalRead(pins[3]);
if (Key0 == LOW ) { // XIAOでは、LOW = On
Key0_act();
}
if (Key1 == LOW ) {
skitch_ss();
}
if (Key2 == LOW ) {
skitch_pict_copy();
}
if (Key3 == LOW ) {
Key3_act();
}
}
void Key0_act() {
// esc
Keyboard.write(KEY_ESC);
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void skitch_pict_copy() {
//find skitch
Keyboard.write(KEY_F5);
Keyboard.press(KEY_LEFT_GUI);
delay(100);
Keyboard.write('f');
Keyboard.releaseAll();
delay(100);
// 英字モードに変更する必要ある。CTL+SHIFT+;
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.write(';');
Keyboard.releaseAll();
delay(100);
Keyboard.print("skitch");
delay(500);
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
delay(200);
// skitch pict copy
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press(KEY_LEFT_GUI);
Keyboard.write('c');
Keyboard.releaseAll();
delay(100);
// ひらがなモードに変更。CTL+SHIFT+j
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.write('j');
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);// XIAOでは、LOW = On
KeyRelease();
}
void skitch_ss() {
// skitch
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press(KEY_LEFT_GUI);
Keyboard.write('5');
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key3_act() {
//find terminal
Keyboard.write(KEY_F5);
Keyboard.press(KEY_LEFT_GUI);
delay(100);
Keyboard.write('f');
Keyboard.releaseAll();
delay(100);
// 英字モードに変更する必要ある。CTL+SHIFT+;
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.write(';');
Keyboard.releaseAll();
delay(100);
Keyboard.print("terminal");
delay(500);
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
delay(200);
// New terminal windows
Keyboard.press(KEY_LEFT_GUI);
Keyboard.write('n');
Keyboard.releaseAll();
//open URL
Keyboard.print("open https://www.canva.com/");
Keyboard.press(KEY_RETURN);
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void KeyRelease() {
Keyboard.releaseAll();
delay(500);
digitalWrite(LED_BUILTIN, HIGH);// XIAOでは、HIGH = Off
}
</pre>
</details>
<!--
<details closed>
<summary>shownhere</summary>
......
docs/eagle/b2/b2sch.png

151 KB | W: | H:

docs/eagle/b2/b2sch.png

184 KB | W: | H:

docs/eagle/b2/b2sch.png
docs/eagle/b2/b2sch.png
docs/eagle/b2/b2sch.png
docs/eagle/b2/b2sch.png
  • 2-up
  • Swipe
  • Onion skin
# Journey to FAB16 Montreal 2021
# Internet Distance
``` Journey to FAB16 Montreal 2021 ```
......
/*********************************************************************
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
Copyright (c) 2019 Ha Thach for Adafruit Industries
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
#include "Adafruit_TinyUSB.h"
/* This sketch demonstrates USB HID keyboard.
* - PIN A0-A5 is used to send digit '0' to '5' respectively
* - LED will be used as Caplock indicator
*/
#define KEY_UP_ARROW 0x52
#define KEY_LEFT_ARROW 0x50
#define KEY_RIGHT_ARROW 0x4F
#define KEY_DOWN_ARROW 0x51
// HID report descriptor using TinyUSB's template
// Single Report (no ID) descriptor
uint8_t const desc_hid_report[] =
{
TUD_HID_REPORT_DESC_KEYBOARD(),
};
Adafruit_USBD_HID usb_hid;
// Array of pins and its keycode
// For keycode definition see BLEHidGeneric.h
// uint8_t pins[] = { A0, A1, A2, A3, A4, A5 };
// uint8_t hidcode[] = { HID_KEY_0, HID_KEY_1, HID_KEY_2, HID_KEY_3 , HID_KEY_4, HID_KEY_5 };
uint8_t pins[] = { A1, A0, A2, A3, A7, A8, A10 };
uint8_t hidcode[] = { KEY_LEFT_ARROW, KEY_RIGHT_ARROW, KEY_UP_ARROW, KEY_DOWN_ARROW, KEY_UP_ARROW, KEY_DOWN_ARROW, KEY_UP_ARROW };
uint8_t pincount = sizeof(pins)/sizeof(pins[0]);
// the setup function runs once when you press reset or power the board
void setup()
{
usb_hid.setPollInterval(2);
usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
usb_hid.setReportCallback(NULL, hid_report_callback);
usb_hid.begin();
// led pin
//pinMode(LED_BUILTIN, OUTPUT);
//digitalWrite(LED_BUILTIN, LOW);
// Set up pin as input
for (uint8_t i=0; i<pincount; i++)
{
pinMode(pins[i], INPUT_PULLUP);
}
// wait until device mounted
while( !USBDevice.mounted() ) delay(1);
}
void loop()
{
// poll gpio once each 2 ms
delay(2);
// // Remote wakeup
// if ( USBDevice.suspended() && btn )
// {
// // Wake up host if we are in suspend mode
// // and REMOTE_WAKEUP feature is enabled by host
// USBDevice.remoteWakeup();
// }
if ( !usb_hid.ready() ) return;
static bool keyPressedPreviously = false;
bool anyKeyPressed = false;
uint8_t count=0;
uint8_t keycode[6] = { 0 };
// scan normal key and send report
for(uint8_t i=0; i < pincount; i++)
{
if ( 0 == digitalRead(pins[i]) )
{
// if pin is active (low), add its hid code to key report
keycode[count++] = hidcode[i];
// 6 is max keycode per report
if (count == 6)
{
usb_hid.keyboardReport(0, 0, keycode);
delay(2); // delay for report to send out
// reset report
count = 0;
memset(keycode, 0, 6);
}
// used later
anyKeyPressed = true;
keyPressedPreviously = true;
}
}
// Send any remaining keys (not accumulated up to 6)
if ( count )
{
usb_hid.keyboardReport(0, 0, keycode);
}
// Send All-zero report to indicate there is no keys pressed
// Most of the time, it is, though we don't need to send zero report
// every loop(), only a key is pressed in previous loop()
if ( !anyKeyPressed && keyPressedPreviously )
{
keyPressedPreviously = false;
usb_hid.keyboardRelease(0);
}
}
// Output report callback for LED indicator such as Caplocks
void hid_report_callback(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
{
// LED indicator is output report with only 1 byte length
if ( report_type != HID_REPORT_TYPE_OUTPUT ) return;
// The LED bit map is as follows: (also defined by KEYBOARD_LED_* )
// Kana (4) | Compose (3) | ScrollLock (2) | CapsLock (1) | Numlock (0)
uint8_t ledIndicator = buffer[0];
// turn on LED if caplock is set
//digitalWrite(LED_BUILTIN, ledIndicator & KEYBOARD_LED_CAPSLOCK);
}
/*
XIAO USB Keyboard.example.
http://yuichitamiya.fabcloud.io/fab16/How_to/program/
Google map help
https://support.google.com/maps/answer/6396990?co=GENIE.Platform%3DDesktop&hl=ja
Ctrl+/ to show help menu
a or ← :left
d or →:right
*/
// https://github.com/cyborg5/TinyUSB_Mouse_and_Keyboard
#include <TinyUSB_Mouse_and_Keyboard.h>
//#include "TinyUSB_Mouse_and_Keyboard.h"
uint8_t pins[] = { A0 , A1 , A2 , A3 , A4 , A5 , A6 , A7 , A8 }; //A9: nouse,A10:JACK_L
uint8_t Key0; //A0
uint8_t Key1; //A1
uint8_t Key2; //A2
uint8_t Key3; //A3
uint8_t Key4; //A4
uint8_t Key5; //A5
uint8_t Key6; //A6
uint8_t Key7; //A7
uint8_t Key8; //A8
//uint8_t Key9; //A9 nouse
void setup() {
Keyboard.begin();
// led pin
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
//
pinMode(pins[0], INPUT_PULLUP);
pinMode(pins[1], INPUT_PULLUP);
pinMode(pins[2], INPUT_PULLUP);
pinMode(pins[3], INPUT_PULLUP);
pinMode(pins[4], INPUT_PULLUP);
pinMode(pins[5], INPUT_PULLUP);
pinMode(pins[6], INPUT_PULLUP);
pinMode(pins[7], INPUT_PULLUP);
pinMode(pins[8], INPUT_PULLUP);
}
void loop() {
Key0 = digitalRead(pins[0]);
Key1 = digitalRead(pins[1]);
Key2 = digitalRead(pins[2]);
Key3 = digitalRead(pins[3]);
Key4 = digitalRead(pins[4]);
Key5 = digitalRead(pins[5]);
Key6 = digitalRead(pins[6]);
Key7 = digitalRead(pins[7]);
Key8 = digitalRead(pins[8]);
// XIAOでは、LOW = On
if (Key0 == LOW ) { //
Key0_act();
}
if (Key1 == LOW ) {
Key1_act();
}
if (Key2 == LOW ) {
Key2_act();
}
if (Key3 == LOW ) {
Key3_act();
}
if (Key4 == LOW ) {
Key4_act();
}
if (Key5 == LOW ) {
Key5_act();
}
if (Key6 == LOW ) {
Key6_act();
}
if (Key7 == LOW ) {
Key7_act();
}
if (Key8 == LOW ) {
Key8_act();
}
}
void Key0_act() {
// <-
//Keyboard.press(KEY_RIGHT_ARROW);
Keyboard.press('d');
//Keyboard.write('D');
//delay(100);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);// XIAOでは、LOW = On
KeyRelease();
}
void Key1_act() {
// ->
//Keyboard.press(KEY_LEFT_ARROW);
Keyboard.press('a');
//Keyboard.write('A');
//delay(100);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key2_act() {
// down arrow
Keyboard.press(KEY_DOWN_ARROW);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key3_act() {
// up arrow
Keyboard.press(KEY_UP_ARROW);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key4_act() {
// move to right tab
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(KEY_RIGHT_ALT);
Keyboard.press(KEY_RIGHT_ARROW);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key6_act() {
//select url
Keyboard.press(KEY_LEFT_GUI);
Keyboard.write('l');
Keyboard.releaseAll();
delay(100);
//copy
Keyboard.press(KEY_LEFT_GUI);
Keyboard.write('c');
Keyboard.releaseAll();
delay(100);
//move to left tab
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(KEY_RIGHT_ALT);
Keyboard.press(KEY_LEFT_ARROW);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key5_act() {
// run spreadsheet script
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(KEY_RIGHT_ALT);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.write('1');
Keyboard.releaseAll();
delay(3000);
// paste
Keyboard.press(KEY_LEFT_GUI);
Keyboard.write('v');
Keyboard.releaseAll();
delay(100);
// move to right tab
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(KEY_RIGHT_ALT);
Keyboard.press(KEY_RIGHT_ARROW);
Keyboard.releaseAll();
// tab to forcus screen
Keyboard.press(KEY_TAB);
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key7_act() {
// tab to forcus screen
Keyboard.press(KEY_TAB);
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key8_act() {
//move to left tab
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(KEY_RIGHT_ALT);