5.2.1 - Updated I2C files
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
tools/colorize.py@1:f30bdcd2b33b, 2017-02-27 (annotated)
- Committer:
- jacobjohnson
- Date:
- Mon Feb 27 17:45:05 2017 +0000
- Revision:
- 1:f30bdcd2b33b
- Parent:
- 0:098463de4c5d
changed the inputscale from 1 to 7 in analogin_api.c. This will need to be changed later, and accessed from the main level, but for now this allows the adc to read a value from 0 to 3.7V, instead of just up to 1V.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-onsemi | 0:098463de4c5d | 1 | # mbed SDK |
group-onsemi | 0:098463de4c5d | 2 | # Copyright (c) 2016 ARM Limited |
group-onsemi | 0:098463de4c5d | 3 | # |
group-onsemi | 0:098463de4c5d | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
group-onsemi | 0:098463de4c5d | 5 | # you may not use this file except in compliance with the License. |
group-onsemi | 0:098463de4c5d | 6 | # You may obtain a copy of the License at |
group-onsemi | 0:098463de4c5d | 7 | # |
group-onsemi | 0:098463de4c5d | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
group-onsemi | 0:098463de4c5d | 9 | # |
group-onsemi | 0:098463de4c5d | 10 | # Unless required by applicable law or agreed to in writing, software |
group-onsemi | 0:098463de4c5d | 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
group-onsemi | 0:098463de4c5d | 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
group-onsemi | 0:098463de4c5d | 13 | # See the License for the specific language governing permissions and |
group-onsemi | 0:098463de4c5d | 14 | # limitations under the License. |
group-onsemi | 0:098463de4c5d | 15 | |
group-onsemi | 0:098463de4c5d | 16 | """ This python file is responsible for generating colorized notifiers. |
group-onsemi | 0:098463de4c5d | 17 | """ |
group-onsemi | 0:098463de4c5d | 18 | |
group-onsemi | 0:098463de4c5d | 19 | import sys |
group-onsemi | 0:098463de4c5d | 20 | import re |
group-onsemi | 0:098463de4c5d | 21 | from colorama import init, Fore, Back, Style |
group-onsemi | 0:098463de4c5d | 22 | init() |
group-onsemi | 0:098463de4c5d | 23 | |
group-onsemi | 0:098463de4c5d | 24 | COLORS = { |
group-onsemi | 0:098463de4c5d | 25 | 'none' : "", |
group-onsemi | 0:098463de4c5d | 26 | 'default' : Style.RESET_ALL, |
group-onsemi | 0:098463de4c5d | 27 | |
group-onsemi | 0:098463de4c5d | 28 | 'black' : Fore.BLACK, |
group-onsemi | 0:098463de4c5d | 29 | 'red' : Fore.RED, |
group-onsemi | 0:098463de4c5d | 30 | 'green' : Fore.GREEN, |
group-onsemi | 0:098463de4c5d | 31 | 'yellow' : Fore.YELLOW, |
group-onsemi | 0:098463de4c5d | 32 | 'blue' : Fore.BLUE, |
group-onsemi | 0:098463de4c5d | 33 | 'magenta' : Fore.MAGENTA, |
group-onsemi | 0:098463de4c5d | 34 | 'cyan' : Fore.CYAN, |
group-onsemi | 0:098463de4c5d | 35 | 'white' : Fore.WHITE, |
group-onsemi | 0:098463de4c5d | 36 | |
group-onsemi | 0:098463de4c5d | 37 | 'on_black' : Back.BLACK, |
group-onsemi | 0:098463de4c5d | 38 | 'on_red' : Back.RED, |
group-onsemi | 0:098463de4c5d | 39 | 'on_green' : Back.GREEN, |
group-onsemi | 0:098463de4c5d | 40 | 'on_yellow' : Back.YELLOW, |
group-onsemi | 0:098463de4c5d | 41 | 'on_blue' : Back.BLUE, |
group-onsemi | 0:098463de4c5d | 42 | 'on_magenta' : Back.MAGENTA, |
group-onsemi | 0:098463de4c5d | 43 | 'on_cyan' : Back.CYAN, |
group-onsemi | 0:098463de4c5d | 44 | 'on_white' : Back.WHITE, |
group-onsemi | 0:098463de4c5d | 45 | } |
group-onsemi | 0:098463de4c5d | 46 | |
group-onsemi | 0:098463de4c5d | 47 | COLOR_MATCHER = re.compile(r"(\w+)(\W+on\W+\w+)?") |
group-onsemi | 0:098463de4c5d | 48 | def colorstring_to_escapecode(color_string): |
group-onsemi | 0:098463de4c5d | 49 | """ Convert a color string from a string into an ascii escape code that |
group-onsemi | 0:098463de4c5d | 50 | will print that color on the terminal. |
group-onsemi | 0:098463de4c5d | 51 | |
group-onsemi | 0:098463de4c5d | 52 | Positional arguments: |
group-onsemi | 0:098463de4c5d | 53 | color_string - the string to parse |
group-onsemi | 0:098463de4c5d | 54 | """ |
group-onsemi | 0:098463de4c5d | 55 | match = re.match(COLOR_MATCHER, color_string) |
group-onsemi | 0:098463de4c5d | 56 | if match: |
group-onsemi | 0:098463de4c5d | 57 | return COLORS[match.group(1)] + \ |
group-onsemi | 0:098463de4c5d | 58 | (COLORS[match.group(2).strip().replace(" ", "_")] |
group-onsemi | 0:098463de4c5d | 59 | if match.group(2) else "") |
group-onsemi | 0:098463de4c5d | 60 | else: |
group-onsemi | 0:098463de4c5d | 61 | return COLORS['default'] |
group-onsemi | 0:098463de4c5d | 62 | |
group-onsemi | 0:098463de4c5d | 63 | |
group-onsemi | 0:098463de4c5d | 64 | def print_in_color_notifier(color_map, print_fn): |
group-onsemi | 0:098463de4c5d | 65 | """ Wrap a toolchain notifier in a colorizer. This colorizer will wrap |
group-onsemi | 0:098463de4c5d | 66 | notifications in a color if the severity matches a color in the *color_map*. |
group-onsemi | 0:098463de4c5d | 67 | """ |
group-onsemi | 0:098463de4c5d | 68 | def wrap(event, silent=False): |
group-onsemi | 0:098463de4c5d | 69 | """The notification function inself""" |
group-onsemi | 0:098463de4c5d | 70 | file_desc = sys.stdout |
group-onsemi | 0:098463de4c5d | 71 | self = event['toolchain'] |
group-onsemi | 0:098463de4c5d | 72 | if file_desc.isatty() and 'severity' in event and \ |
group-onsemi | 0:098463de4c5d | 73 | event['severity'] in color_map: |
group-onsemi | 0:098463de4c5d | 74 | file_desc.write(colorstring_to_escapecode( |
group-onsemi | 0:098463de4c5d | 75 | color_map[event['severity']])) |
group-onsemi | 0:098463de4c5d | 76 | print_fn(self, event, silent) |
group-onsemi | 0:098463de4c5d | 77 | file_desc.write(colorstring_to_escapecode('default')) |
group-onsemi | 0:098463de4c5d | 78 | else: |
group-onsemi | 0:098463de4c5d | 79 | print_fn(self, event, silent) |
group-onsemi | 0:098463de4c5d | 80 | return wrap |