repo_name
stringlengths 6
97
| path
stringlengths 3
341
| text
stringlengths 8
1.02M
|
---|---|---|
AndrejGajdos/C-assignments | csvParser/csvParser.c | /*
============================================================================
Name : csvParser.c
Author : 359234
Copyright : <EMAIL>
Description : GPS parsing
============================================================================
*/
#include "csvParser.h"
int parseCSVLine(FILE * file, gpxTag * tag) {
char line[101];
memset(line,0,101);
if ((file==NULL)||(tag==NULL))
return INVALID_ARGUMENTS;
fgets (line, 100, file);
if (line[0] == '\0')
return EOF;
int countCommas = 0;
for(unsigned int i=0; i<strlen(line); i++)
{
if (line[i] == ',')
{
countCommas++;
}
}
if (countCommas != 10)
return OTHER_ERROR;
// Split one row into arrays
char rok[5];
memset(rok,0,5);
char mesiac[3];
memset(mesiac,0,3);
char den[3];
memset(den,0,3);
char hodina[3];
memset(hodina,0,3);
char minuta[3];
memset(minuta,0,3);
char sekunda[3];
memset(sekunda,0,3);
char sirka[10];
memset(sirka,0,10);
char dlzka[10];
memset(dlzka,0,10);
char vyska[8];
memset(vyska,0,8);
char* substring;
int year,month,day,hour,minute,second;
double lat,lon,ele;
char date[11];
memset(date,0,11);
char time[9];
memset(time,0,9);
substring = strstr(line,",")+3;
strncpy(rok,substring,4);
year = atoi(rok);
substring = strstr(line,"/")+1;
strncpy(mesiac,substring,2);
month = atoi(mesiac);
substring = strstr(line,"/")+4;
strncpy(den,substring,2);
day = atoi(den);
strcat(date,rok);
strcat(date,"-");
strcat(date,mesiac);
strcat(date,"-");
strcat(date,den);
substring = strstr(line,":")-2;
strncpy(hodina,substring,2);
hour = atoi(hodina);
substring = strstr(line,":")+1;
strncpy(minuta,substring,2);
minute = atoi(minuta);
substring = strstr(line,":")+4;
strncpy(sekunda,substring,2);
second = atoi(sekunda);
strcat(time,hodina);
strcat(time,":");
strcat(time,minuta);
strcat(time,":");
strcat(time,sekunda);
substring = strstr(line,":")+7;
strncpy(sirka,substring,9);
lat = strtod(sirka, NULL);
substring = strstr(line,"N")+2;
strncpy(dlzka,substring,9);
lon = strtod(dlzka, NULL);
substring = strstr(line,"E")+2;
strncpy(vyska,substring,7);
ele = strtod(vyska, NULL);
if(lat == 0.0 || lon == 0.0 || ele == 0.0)
return PARSING_ERROR;
// If items are correct
if ((year > 1970) && (year <= 9999) && (day>=1) && (day<=31) && (month>=1) && (month<=12) && (hour>=0) && (hour<=23) && (minute>=0) && (minute<=59) && (second>=0) && (second<=59))
{
tag->lat = lat;
tag->lon = lon;
tag->ele = ele;
for (int i=0;i<=8;i++)
{
tag->time[i] = time[i];
}
//tag->(time[9]) = NULL;
for (int i=0;i<=10;i++)
{
tag->date[i] = date[i];
}
//tag->date[11] = NULL;
return SUCCESS;
}
else
return OTHER_ERROR;
}
int writeGPXTag(FILE * file, gpxTag * tag)
{
if ((file==NULL)||(tag==NULL))
{
return INVALID_ARGUMENTS;
}
fprintf(file,"<trkpt lat=\"%f\" lon=\"%f\">\n<ele>%.3f</ele>\n<time>%sT%sZ</time>\n<sym>Dot</sym>\n</trkpt>",tag->lat,tag->lon,tag->ele,tag->date,tag->time);
return SUCCESS;
}
int writeHeader(FILE * file) {
if (file == NULL) {
return INVALID_ARGUMENTS;
}
fprintf(
file,
"<?xml version=\"1.0\" standalone=\"yes\"?>\n"
"<gpx version=\"1.0\" creator=\"PB071\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
"xmlns=\"http://www.topografix.com/GPX/1/0\""
" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n"
"<trk><name>Holux GPS Track</name><trkseg>\n");
return SUCCESS;
}
int writeFooter(FILE * file) {
if (file == NULL) {
return INVALID_ARGUMENTS;
}
fprintf(file, "</trkseg></trk></gpx>\n");
return SUCCESS;
}
|
AndrejGajdos/C-assignments | csvParser/csvParser.h | #ifndef CSVPARSER_H_
#define CSVPARSER_H_
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SUCCESS 0
#define INVALID_ARGUMENTS 1
#define FILE_NOT_FOUND 2
#define OTHER_ERROR 3
#define PARSING_ERROR 4
/**
* Amount of memory (e.g. number of lines) allocated at once while reading input file.
*/
#define MEM_SIZE 100
/**
* Structure for storing information used in GPX tag.
* lat - lattitude (in degrees, north)
* lon - longitude (in degrees, east)
* ele - elevation (in meters)
* time - time in 24 hour format hh:mm:ss (e.g. 06:43:50)
* date - date in format yyyy-mm-dd (e.g. 2011-09-25)
*/
typedef struct gpxTag {
double lat;
double lon;
double ele;
char time[9];
char date[11];
} gpxTag;
/**
* Parses line from csv file and stores information into tag.
* @param file pointer into input file
* @param tag pointer to tag where to store GPX information
* @return SUCCESS when line was successfully parsed,
* PARSING_ERROR when the line is not in requested format
* EOF when end of file is reached
* INVALID_ARGUMENTS when some parameter is NULL
* OTHER_ERROR when some error occures while reading
*/
int parseCSVLine(FILE * file, gpxTag * tag);
/**
* Writes one gpx tag into output file. Whitespace between xml tags does not
* matter.
* @param file pointer into output file
* @param tag ponter to the tag that should be written
* @return SUCCESS when line was successfully written,
* INVALID_ARGUMENTS when some parameter is NULL
* OTHER_ERROR when some error occures while writing
*/
int writeGPXTag(FILE * file, gpxTag * tag);
/**
* Writes XML/GPX header into file.
* @param file file where to write header
* @return SUCCESS on success, INVALID_ARGUMENTS in case of invalid parameter
*/
int writeHeader(FILE * file);
/**
* Writes XML/GPX footer into file.
* @param file file where to write footer
* @return SUCCESS on success, INVALID_ARGUMENTS in case of invalid parameter
*/
int writeFooter(FILE * file);
#endif /* CSVPARSER_H_ */
|
xukiki/QqcComFuncDef | QqcComFuncDef/QqcComFuncDef.h | //
// QqcComFuncDef.h
// QqcBaseFramework
//
// Created by hc on 15/2/4.
// Copyright (c) 2015年 Qqc. All rights reserved.
//
#ifndef QqcBaseFramework_QqcComFuncDef_h
#define QqcBaseFramework_QqcComFuncDef_h
//获取医随身服务器其它大小图片
#define img_with_size(_origin_, _size_) [((NSString*)_origin_) stringByReplacingOccurrencesOfString:@"default" withString:_size_]
//字符串空值判断
#define str_is_exist_qqc(_str_) (_str_ && ![_str_ isEqualToString:@""])
//NSInteger 2 NSString
#define str_from_int(_int_) [NSString stringWithFormat:@"%ld", (long)_int_]
//把字符串连接转换成NSURL对象
#define url_from_str(_str_) [NSURL URLWithString:_str_]
//类名称
#define name_class_qqc NSStringFromClass([self class])
//cell的Identifier
#define cell_identity(_cellName_) [NSString stringWithFormat:@"%@Identity", _cellName_]
//App应用名称
#define name_diplay_app_qqc [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]
//获取bundle
#define bundle_with_name(_name_) [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:_name_ ofType:@"bundle"]]
//从某个bundle中获取nib
#define nib_with_name_from_somebundle(_nibName_, _bundleName_) \
UINib* nib = nil; \
if (str_is_exist_qqc(_bundleName_)) { \
nib = [UINib nibWithNibName:_nibName_ bundle:bundle_with_name(_bundleName_)]; \
}else{ \
nib = [UINib nibWithNibName:_nibName_ bundle:[NSBundle mainBundle]]; \
}\
return nib;
//通过名字获取image(有缓存[NSBundle mainBundle])
#define image_with_name(_name_) [UIImage imageNamed:_name_]
//通过名字,从文件中获取image(无缓存[NSBundle mainBundle])
#define image_from_file_with_name(_name_) \
UIImage* imageRet; \
NSString* strName; \
NSString* strType; \
NSRange rang = [strFullName rangeOfString:@"." options:NSBackwardsSearch]; \
if (rang.length > 0) \
{ \
strName = [_name_ substringToIndex:rang.location]; \
\
if ([UIScreen mainScreen].scale == 2) { \
strName = [strName stringByAppendingString:@"@2x"]; \
} \
else if([UIScreen mainScreen].scale == 3) \
{ \
strName = [strName stringByAppendingString:@"@3x"]; \
} \
\
strType = [strFullName substringFromIndex:rang.location+1]; \
}else{ \
strName = strFullName; \
strType = @"png"; \
} \
\
NSString* strImgPath = [[NSBundle mainBundle] pathForResource:strName ofType:strType]; \
imageRet = [UIImage imageWithContentsOfFile:strImgPath]; \
return imageRet;
//从某个bundle中获取image(有缓存,某个bundle)
#define image_with_name_from_somebundle(_imageName_, _bundleName_) \
UIImage* imageRet = nil; \
NSBundle* bundle = bundle_with_name(_bundleName_); \
if (bundle) { \
imageRet = [UIImage imageNamed:_imageName_ inBundle:bundle compatibleWithTraitCollection:nil]; \
} \
\
return imageRet;
//从某个bundle中通过名字,从文件中获取image(无缓存,某个bundle)
#define image_from_file_with_name_from_somebundle(_imageName_, _bundleName_) \
UIImage* imageRet; \
NSString* strName; \
NSString* strType; \
NSRange rang = [strFullName rangeOfString:@"." options:NSBackwardsSearch]; \
if (rang.length > 0) \
{ \
strName = [_name_ substringToIndex:rang.location]; \
\
if ([UIScreen mainScreen].scale == 2) { \
strName = [strName stringByAppendingString:@"@2x"]; \
} \
else if([UIScreen mainScreen].scale == 3) \
{ \
strName = [strName stringByAppendingString:@"@3x"]; \
} \
\
strType = [strFullName substringFromIndex:rang.location+1]; \
}else{ \
strName = strFullName; \
strType = @"png"; \
} \
\
NSString* strImgPath = [bundle_with_name(_bundleName_) pathForResource:strName ofType:strType]; \
imageRet = [UIImage imageWithContentsOfFile:strImgPath]; \
return imageRet;
//判断是否为iphone4
#define is_iphone4_qqc() (fabs((double)[[UIScreen mainScreen] bounds].size.height-(double)480.f ) < DBL_EPSILON )
//判断是否为iphone5
#define is_iphone5_qqc() (fabs((double)[[UIScreen mainScreen] bounds].size.height-(double)568.f ) < DBL_EPSILON )
//判断是否为iphone6
#define is_iphone6_qqc() (fabs((double)[[UIScreen mainScreen] bounds].size.height-(double)667.f ) < DBL_EPSILON )
//判断是否为iphone6p
#define is_iphone6p_qqc() (fabs((double)[[UIScreen mainScreen] bounds].size.height-(double)736.f ) < DBL_EPSILON )
//判断是否为ipod
#define is_ipod_qqc() ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])
//判断是否为ipad
#define is_ipad_qqc() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
//获取的一个cell 类的标识
#define identity_of_cell(_strCellClassName_) [NSString stringWithFormat:@"%@Identity", _strCellClassName_]
//去掉日期中的时间部分
#define date_2_no_time(_date_) [[NSDate dateWithString:_date_ formatString:@"yyyy-MM-dd HH:mm:ss"] convertToStringWithFormat:@"yyyy-MM-dd"]
//去掉日期中的时间秒部分
#define date_2_no_second(_date_) [[NSDate dateWithString:_date_ formatString:@"yyyy-MM-dd HH:mm:ss"] convertToStringWithFormat:@"yyyy-MM-dd HH:mm"]
//去掉时间中的秒部分
#define time_2_no_second(_date_) [[NSDate dateWithString:_date_ formatString:@"HH:mm:ss"] convertToStringWithFormat:@"HH:mm"]
//从日期中获取年份
#define year_from_date(_date_) [[NSDate dateWithString:_date_ formatString:@"yyyy-MM-dd HH:mm:ss"] convertToStringWithFormat:@"yyyy"];
//从日期中获取月份
#define month_from_date(_date_) [[NSDate dateWithString:_date_ formatString:@"yyyy-MM-dd HH:mm:ss"] convertToStringWithFormat:@"MM"];
//从日期中获取日份
#define day_from_date(_date_) [[NSDate dateWithString:_date_ formatString:@"yyyy-MM-dd HH:mm:ss"] convertToStringWithFormat:@"dd"]
#endif
|
stevedonovan/AndroLua | jni/lua/test.c | #include "lobject.h"
#include "stdio.h"
int main() {
printf("String: %d, Udata: %d\n", sizeof(TString), sizeof(Udata));
return 0;
}
|
stevedonovan/AndroLua | jni/luajava/luajava.h | <reponame>stevedonovan/AndroLua
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_keplerproject_luajava_LuaState */
#ifndef _Included_org_keplerproject_luajava_LuaState
#define _Included_org_keplerproject_luajava_LuaState
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _open
* Signature: ()Lorg/keplerproject/luajava/CPtr;
*/
JNIEXPORT jobject JNICALL Java_org_keplerproject_luajava_LuaState__1open
(JNIEnv *, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _close
* Signature: (Lorg/keplerproject/luajava/CPtr;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1close
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _newthread
* Signature: (Lorg/keplerproject/luajava/CPtr;)Lorg/keplerproject/luajava/CPtr;
*/
JNIEXPORT jobject JNICALL Java_org_keplerproject_luajava_LuaState__1newthread
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _getTop
* Signature: (Lorg/keplerproject/luajava/CPtr;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1getTop
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _setTop
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1setTop
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _pushValue
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1pushValue
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _remove
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1remove
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _insert
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1insert
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _replace
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1replace
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _checkStack
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1checkStack
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _xmove
* Signature: (Lorg/keplerproject/luajava/CPtr;Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1xmove
(JNIEnv *, jobject, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _isNumber
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1isNumber
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _isString
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1isString
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _isCFunction
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1isCFunction
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _isUserdata
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1isUserdata
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _type
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1type
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _typeName
* Signature: (Lorg/keplerproject/luajava/CPtr;I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_keplerproject_luajava_LuaState__1typeName
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _equal
* Signature: (Lorg/keplerproject/luajava/CPtr;II)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1equal
(JNIEnv *, jobject, jobject, jint, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _rawequal
* Signature: (Lorg/keplerproject/luajava/CPtr;II)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1rawequal
(JNIEnv *, jobject, jobject, jint, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _lessthan
* Signature: (Lorg/keplerproject/luajava/CPtr;II)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1lessthan
(JNIEnv *, jobject, jobject, jint, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _toNumber
* Signature: (Lorg/keplerproject/luajava/CPtr;I)D
*/
JNIEXPORT jdouble JNICALL Java_org_keplerproject_luajava_LuaState__1toNumber
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _toInteger
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1toInteger
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _toBoolean
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1toBoolean
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _toString
* Signature: (Lorg/keplerproject/luajava/CPtr;I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_keplerproject_luajava_LuaState__1toString
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _objlen
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1objlen
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _toThread
* Signature: (Lorg/keplerproject/luajava/CPtr;I)Lorg/keplerproject/luajava/CPtr;
*/
JNIEXPORT jobject JNICALL Java_org_keplerproject_luajava_LuaState__1toThread
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _pushNil
* Signature: (Lorg/keplerproject/luajava/CPtr;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1pushNil
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _pushNumber
* Signature: (Lorg/keplerproject/luajava/CPtr;D)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1pushNumber
(JNIEnv *, jobject, jobject, jdouble);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _pushInteger
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1pushInteger
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _pushString
* Signature: (Lorg/keplerproject/luajava/CPtr;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1pushString__Lorg_keplerproject_luajava_CPtr_2Ljava_lang_String_2
(JNIEnv *, jobject, jobject, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _pushString
* Signature: (Lorg/keplerproject/luajava/CPtr;[BI)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1pushString__Lorg_keplerproject_luajava_CPtr_2_3BI
(JNIEnv *, jobject, jobject, jbyteArray, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _pushBoolean
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1pushBoolean
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _getTable
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1getTable
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _getField
* Signature: (Lorg/keplerproject/luajava/CPtr;ILjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1getField
(JNIEnv *, jobject, jobject, jint, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _rawGet
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1rawGet
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _rawGetI
* Signature: (Lorg/keplerproject/luajava/CPtr;II)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1rawGetI
(JNIEnv *, jobject, jobject, jint, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _createTable
* Signature: (Lorg/keplerproject/luajava/CPtr;II)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1createTable
(JNIEnv *, jobject, jobject, jint, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _getMetaTable
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1getMetaTable
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _getFEnv
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1getFEnv
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _setTable
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1setTable
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _setField
* Signature: (Lorg/keplerproject/luajava/CPtr;ILjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1setField
(JNIEnv *, jobject, jobject, jint, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _rawSet
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1rawSet
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _rawSetI
* Signature: (Lorg/keplerproject/luajava/CPtr;II)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1rawSetI
(JNIEnv *, jobject, jobject, jint, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _setMetaTable
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1setMetaTable
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _setFEnv
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1setFEnv
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _call
* Signature: (Lorg/keplerproject/luajava/CPtr;II)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1call
(JNIEnv *, jobject, jobject, jint, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _pcall
* Signature: (Lorg/keplerproject/luajava/CPtr;III)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1pcall
(JNIEnv *, jobject, jobject, jint, jint, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _yield
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1yield
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _resume
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1resume
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _status
* Signature: (Lorg/keplerproject/luajava/CPtr;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1status
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _gc
* Signature: (Lorg/keplerproject/luajava/CPtr;II)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1gc
(JNIEnv *, jobject, jobject, jint, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _error
* Signature: (Lorg/keplerproject/luajava/CPtr;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1error
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _next
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1next
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _concat
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1concat
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _pop
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1pop
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _newTable
* Signature: (Lorg/keplerproject/luajava/CPtr;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1newTable
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _strlen
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1strlen
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _isFunction
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1isFunction
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _isTable
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1isTable
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _isNil
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1isNil
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _isBoolean
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1isBoolean
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _isThread
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1isThread
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _isNone
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1isNone
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _isNoneOrNil
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1isNoneOrNil
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _setGlobal
* Signature: (Lorg/keplerproject/luajava/CPtr;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1setGlobal
(JNIEnv *, jobject, jobject, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _getGlobal
* Signature: (Lorg/keplerproject/luajava/CPtr;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1getGlobal
(JNIEnv *, jobject, jobject, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _getGcCount
* Signature: (Lorg/keplerproject/luajava/CPtr;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1getGcCount
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LdoFile
* Signature: (Lorg/keplerproject/luajava/CPtr;Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1LdoFile
(JNIEnv *, jclass, jobject, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LdoString
* Signature: (Lorg/keplerproject/luajava/CPtr;Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1LdoString
(JNIEnv *, jobject, jobject, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LgetMetaField
* Signature: (Lorg/keplerproject/luajava/CPtr;ILjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1LgetMetaField
(JNIEnv *, jobject, jobject, jint, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LcallMeta
* Signature: (Lorg/keplerproject/luajava/CPtr;ILjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1LcallMeta
(JNIEnv *, jobject, jobject, jint, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _Ltyperror
* Signature: (Lorg/keplerproject/luajava/CPtr;ILjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1Ltyperror
(JNIEnv *, jobject, jobject, jint, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LargError
* Signature: (Lorg/keplerproject/luajava/CPtr;ILjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1LargError
(JNIEnv *, jobject, jobject, jint, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LcheckString
* Signature: (Lorg/keplerproject/luajava/CPtr;I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_keplerproject_luajava_LuaState__1LcheckString
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LoptString
* Signature: (Lorg/keplerproject/luajava/CPtr;ILjava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_keplerproject_luajava_LuaState__1LoptString
(JNIEnv *, jobject, jobject, jint, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LcheckNumber
* Signature: (Lorg/keplerproject/luajava/CPtr;I)D
*/
JNIEXPORT jdouble JNICALL Java_org_keplerproject_luajava_LuaState__1LcheckNumber
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LoptNumber
* Signature: (Lorg/keplerproject/luajava/CPtr;ID)D
*/
JNIEXPORT jdouble JNICALL Java_org_keplerproject_luajava_LuaState__1LoptNumber
(JNIEnv *, jobject, jobject, jint, jdouble);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LcheckInteger
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1LcheckInteger
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LoptInteger
* Signature: (Lorg/keplerproject/luajava/CPtr;II)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1LoptInteger
(JNIEnv *, jobject, jobject, jint, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LcheckStack
* Signature: (Lorg/keplerproject/luajava/CPtr;ILjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1LcheckStack
(JNIEnv *, jobject, jobject, jint, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LcheckType
* Signature: (Lorg/keplerproject/luajava/CPtr;II)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1LcheckType
(JNIEnv *, jobject, jobject, jint, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LcheckAny
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1LcheckAny
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LnewMetatable
* Signature: (Lorg/keplerproject/luajava/CPtr;Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1LnewMetatable
(JNIEnv *, jobject, jobject, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LgetMetatable
* Signature: (Lorg/keplerproject/luajava/CPtr;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1LgetMetatable
(JNIEnv *, jobject, jobject, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _Lwhere
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1Lwhere
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _Lref
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1Lref
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LunRef
* Signature: (Lorg/keplerproject/luajava/CPtr;II)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1LunRef
(JNIEnv *, jobject, jobject, jint, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LgetN
* Signature: (Lorg/keplerproject/luajava/CPtr;I)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1LgetN
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LsetN
* Signature: (Lorg/keplerproject/luajava/CPtr;II)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1LsetN
(JNIEnv *, jobject, jobject, jint, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LloadFile
* Signature: (Lorg/keplerproject/luajava/CPtr;Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1LloadFile
(JNIEnv *, jobject, jobject, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LloadBuffer
* Signature: (Lorg/keplerproject/luajava/CPtr;[BJLjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1LloadBuffer
(JNIEnv *, jobject, jobject, jbyteArray, jlong, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LloadString
* Signature: (Lorg/keplerproject/luajava/CPtr;Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_keplerproject_luajava_LuaState__1LloadString
(JNIEnv *, jobject, jobject, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _Lgsub
* Signature: (Lorg/keplerproject/luajava/CPtr;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_keplerproject_luajava_LuaState__1Lgsub
(JNIEnv *, jobject, jobject, jstring, jstring, jstring);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _LfindTable
* Signature: (Lorg/keplerproject/luajava/CPtr;ILjava/lang/String;I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_keplerproject_luajava_LuaState__1LfindTable
(JNIEnv *, jobject, jobject, jint, jstring, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _openBase
* Signature: (Lorg/keplerproject/luajava/CPtr;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1openBase
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _openTable
* Signature: (Lorg/keplerproject/luajava/CPtr;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1openTable
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _openIo
* Signature: (Lorg/keplerproject/luajava/CPtr;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1openIo
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _openOs
* Signature: (Lorg/keplerproject/luajava/CPtr;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1openOs
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _openString
* Signature: (Lorg/keplerproject/luajava/CPtr;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1openString
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _openMath
* Signature: (Lorg/keplerproject/luajava/CPtr;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1openMath
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _openDebug
* Signature: (Lorg/keplerproject/luajava/CPtr;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1openDebug
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _openPackage
* Signature: (Lorg/keplerproject/luajava/CPtr;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1openPackage
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _openLibs
* Signature: (Lorg/keplerproject/luajava/CPtr;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1openLibs
(JNIEnv *, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: luajava_open
* Signature: (Lorg/keplerproject/luajava/CPtr;I)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState_luajava_1open
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _getObjectFromUserdata
* Signature: (Lorg/keplerproject/luajava/CPtr;I)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_org_keplerproject_luajava_LuaState__1getObjectFromUserdata
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _isObject
* Signature: (Lorg/keplerproject/luajava/CPtr;I)Z
*/
JNIEXPORT jboolean JNICALL Java_org_keplerproject_luajava_LuaState__1isObject
(JNIEnv *, jobject, jobject, jint);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _pushJavaObject
* Signature: (Lorg/keplerproject/luajava/CPtr;Ljava/lang/Object;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1pushJavaObject
(JNIEnv *, jobject, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _pushJavaArray
* Signature: (Lorg/keplerproject/luajava/CPtr;Ljava/lang/Object;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1pushJavaArray
(JNIEnv *, jobject, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _pushJavaFunction
* Signature: (Lorg/keplerproject/luajava/CPtr;Lorg/keplerproject/luajava/JavaFunction;)V
*/
JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1pushJavaFunction
(JNIEnv *, jobject, jobject, jobject);
/*
* Class: org_keplerproject_luajava_LuaState
* Method: _isJavaFunction
* Signature: (Lorg/keplerproject/luajava/CPtr;I)Z
*/
JNIEXPORT jboolean JNICALL Java_org_keplerproject_luajava_LuaState__1isJavaFunction
(JNIEnv *, jobject, jobject, jint);
#ifdef __cplusplus
}
#endif
#endif
|
jungervin/fs-gauge-bridge | BridgeGauge/common.h | <reponame>jungervin/fs-gauge-bridge<gh_stars>1-10
#pragma once
#ifndef _COMMON_H_
#define _COMMON_H_
#include <MSFS\MSFS.h>
#include <MSFS\MSFS_Render.h>
#include <MSFS\Legacy\gauges.h>
#include <SimConnect.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cassert>
#include <exception>
#ifndef __INTELLISENSE__
# define MODULE_EXPORT __attribute__( ( visibility( "default" ) ) )
# define MODULE_WASM_MODNAME(mod) __attribute__((import_module(mod)))
#else
# define MODULE_EXPORT
# define MODULE_WASM_MODNAME(mod)
# define __attribute__(x)
# define __restrict__
#endif
#ifdef _MSC_VER
#define snprintf _snprintf_s
#elif !defined(__MINGW32__)
#include <iconv.h>
#endif
#endif
|
DrisBigB/ShineUpdater | Shine/Supporting Files/Shine.h | //
// Shine.h
// Shine
//
// Created by <NAME> on 4/11/18.
// Copyright © 2018 Eighty Three Creative, Inc. All rights reserved.
//
#import <UIKit/UIKit.h>
//! Project version number for Shine.
FOUNDATION_EXPORT double ShineVersionNumber;
//! Project version string for Shine.
FOUNDATION_EXPORT const unsigned char ShineVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <Shine/PublicHeader.h>
|
LegendaryyDoc/RaylibPhysics | raygame/shapes.h | #pragma once
#include "glm/glm/vec2.hpp"
#include "mapbox/variant.hpp"
struct circle
{
float radius;
};
struct aabb
{
glm::vec2 halfExtents;
};
using shape = mapbox::util::variant<circle, aabb>;
bool checkCircleCirlce(glm::vec2 posA, circle circleA, glm::vec2 posB, circle circleB);
bool checkAABBAABB(glm::vec2 posA, aabb aabbA, glm::vec2 posB, aabb aabbB);
bool checkCircleAABB(glm::vec2 posA, circle circ, glm::vec2 posB, aabb ab);
bool checkCircleX(glm::vec2 posA, circle lhs, glm::vec2 posB, shape rhs);
bool checkAABBX(glm::vec2 posA, aabb lhs, glm::vec2 posB, shape rhs);
void resolvePhysBodies(class physObject& lhs, class physObject& rhs);
void resolveCollision(glm::vec2 posA, glm::vec2 velA, float massA,
glm::vec2 posB, glm::vec2 velB, float massB,
float elasticity, glm::vec2 normal, glm::vec2* dst); |
LegendaryyDoc/RaylibPhysics | raygame/physics.h | #pragma once
#include "glm/glm/vec2.hpp"
#include "raylib/raylib.h"
#include "shapes.h"
class physObject
{
public:
glm::vec2 pos;
glm::vec2 vel;
glm::vec2 forces;
physObject();
float mass;
float drag;
shape collider;
void tickPhys(float delta);
void draw() const;
// Add a continuous force with respect to mass
void addForce(glm::vec2 force);
// Add a instantaneous force with respect to mass
void addImpluse(glm::vec2 impulse);
// Accelerates the objects w/o respect to mass
void addAccel(glm::vec2 accel);
// Adds an instantaneous force w/o respect to mass
void addVelcityChange(glm::vec2 delta);
}; |
charles-l/zumo-32u4-ms | motors.c | #define F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>
#include "microscheme_types.c"
void init() {
DDRB |= _BV(DDB6); // OUTPUT - left motor PWM
DDRB |= _BV(DDB2); // OUTPUT - left motor direction
DDRB |= _BV(DDB5); // OUTPUT - right motor PWM
DDRB |= _BV(DDB1); // OUTPUT - right motor direction
DDRD |= _BV(DDD3); // pin 1 - LCD control line
PORTD &= ~(_BV(PORTD3)); // LO lcd
// Timer 1 configuration
// prescaler: clockI/O / 1
// outputs enabled
// phase-correct PWM
// top of 400
//
// PWM frequency calculation
// 16MHz / 1 (prescaler) / 2 (phase-correct) / 400 (top) = 20kHz
TCCR1A = 0b10100000;
TCCR1B = 0b00010001;
ICR1 = 400;
OCR1A = 0;
OCR1B = 0;
}
static inline unsigned int clamp_speed(unsigned int speed) {
if (speed > 400) // Max
return 400;
return speed;
}
void set_left_speed(ms_value speed, ms_value rev) {
speed = clamp_speed(speed);
OCR1B = speed;
if (asBool(rev)) {
PORTB &= ~(_BV(PORTB2)); // set LO - forwards
} else {
PORTB |= _BV(PORTB2); // set HI - backewards
}
}
void set_right_speed(ms_value speed, ms_value rev) {
speed = clamp_speed(speed);
OCR1A = speed;
if (asBool(rev)) {
PORTB &= ~(_BV(PORTB1)); // set LO - forwards
} else {
PORTB |= _BV(PORTB1); // set HI - backwards
}
}
|
charles-l/zumo-32u4-ms | microscheme_types.c | #include <stdbool.h>
#include <stdlib.h>
struct vector;
struct pair;
struct closure;
typedef unsigned int ms_value;
typedef struct pair {
ms_value car;
ms_value cdr;
} pair;
typedef struct vector {
unsigned int length;
ms_value data[];
} vector;
typedef struct closure {
unsigned char arity;
unsigned int entry;
struct closure *chain;
ms_value cells[];
} closure;
pair *asPair (ms_value x) {
return (pair*) (unsigned int) (x & 0b0001111111111111);
}
vector *asVector (ms_value x) {
return (vector*) (unsigned int) (x & 0b0001111111111111);
}
closure *asClosure (ms_value x) {
return (closure*) (unsigned int) (x & 0b0001111111111111);
}
unsigned char asChar (ms_value x) {
return x & 0x00FF;
}
bool asBool (ms_value x) {
return (x >> 8) & 0b00000001;
}
bool isNull (ms_value x) {
return ((x >> 8) & 0b11111000) == 0b11101000;
}
ms_value ms_null = 0b1110100000000000;
ms_value ms_true = 0b1111100100000000;
ms_value ms_false = 0b1111100000000000;
ms_value toChar (unsigned char x) {
return 0b1110000000000000 | x;
}
ms_value toPair (pair *x) {
return 0b1000000000000000 | (0b0001111111111111 & ((unsigned int) x));
}
ms_value toVector (vector *x) {
return 0b1010000000000000 | (0b0001111111111111 & ((unsigned int) x));
}
ms_value toClosure (closure *x) {
return 0b1100000000000000 | (0b0001111111111111 & ((unsigned int) x));
}
ms_value cons(ms_value x, ms_value y) {
pair *newcell = malloc(4);
newcell->car = x;
newcell->cdr = y;
return toPair(newcell);
}
ms_value make_vector(unsigned int len) {
vector *newvect = malloc(2 + len + len);
newvect->length = len;
return toVector(newvect);
} |
7glyphs/SGKeyChain | SGKeyChain.h | //
// SGKeyChain.h
// 7 glyphs Ltd.
//
// Created by <NAME> on 5/02/15.
// Copyright (c) 2015 7 glyphs Limited. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface SGKeyChain : NSObject
- (instancetype)initWithIdentifier:(NSString *)identifier accessGroup:(NSString *)accessGroup;
- (void)setObject:(id)inObject forKey:(id)key;
- (id)objectForKey:(id)key;
- (void)resetKeychainItem;
@end
|
piuslee1/rover-ctl | src/arduino/messages.h | <filename>src/arduino/messages.h
#include <Servo.h>
const uint32_t HASH_PRIME = 59359;
// Doesn't register until 104, 87
const int32_t MIN_ANGLE = 40;
const int32_t MAX_ANGLE = 150;
const int32_t MAX_SPEED_CHANGE = 2;
const int32_t UNCONNECTED = 11;
const unsigned char MTR_FR = 8;
const unsigned char MTR_MR = 4;
const unsigned char MTR_BR = 5;
const unsigned char MTR_FL = 6;
const unsigned char MTR_ML = 2;
const unsigned char MTR_BL = 3;
struct Motor {
unsigned char pin;
unsigned char max_speed;
bool bidirectional;
int32_t goal_speed;
int32_t current_speed;
Servo handle;
Motor(unsigned char pin, unsigned char max_speed, bool bidirectional, int32_t goal_speed, int32_t current_speed, Servo handle){
this->pin = pin;
this->max_speed = max_speed;
this->bidirectional = bidirectional;
this->goal_speed = goal_speed;
this->current_speed = current_speed;
this->handle = handle;
}
};
typedef struct {
uint32_t num_speeds;
uint32_t target_system; // ie drive, arm, drill
// unsigned char num_speeds;
// unsigned char target_system; // ie drive, arm, drill
uint32_t hash;
int32_t speeds[6];
} __attribute__((packed)) Message;
uint32_t hash_msg(Message * msg) {
uint32_t sum = 0;
for (int32_t i=0; i<msg->num_speeds; i++) {
sum += msg->speeds[i] * HASH_PRIME;
}
return sum + msg->target_system * HASH_PRIME;
}
void init_motors(Motor * mtrs, int32_t num_mtrs) {
for (int32_t i=0; i<num_mtrs; i++) {
mtrs[i].handle.attach(mtrs[i].pin);
mtrs[i].goal_speed = 0;
mtrs[i].current_speed = 0;
}
}
void set_goal_speeds(Motor * mtrs, int32_t num_mtrs, int32_t *val) {
for (int32_t i=0; i<num_mtrs; i++) {
mtrs[i].goal_speed = min(mtrs[i].max_speed,
max(val[i], -mtrs[i].max_speed));
}
}
void write_motor(Motor * motor, int speed){
Serial.print("writing_motor: ");
if(motor->bidirectional){
int32_t current_angle = int32_t(float(abs(speed))
/ 255. * (MAX_ANGLE-MIN_ANGLE));
motor->handle.write(current_angle);
Serial.print("BI DIRECTIONAL ");
Serial.println(current_angle);
if(speed > 0){
digitalWrite(motor->pin + 1, 1);
}
else{
digitalWrite(motor->pin + 1, 0);
}
}
else{
int32_t current_angle = int32_t(speed
/ 255. * (MAX_ANGLE-MIN_ANGLE)
- (MAX_ANGLE-MIN_ANGLE)/2
+ MIN_ANGLE);
motor->handle.write(current_angle);
Serial.println(current_angle);
}
}
void update_system(Motor * mtrs, int32_t num_mtrs) {
for (int32_t i=0; i<num_mtrs; i++) {
int32_t difference = mtrs[i].goal_speed - mtrs[i].current_speed;
int32_t actual_movement = min(MAX_SPEED_CHANGE, abs(difference));
if(difference != 0){
mtrs[i].current_speed += actual_movement * difference/abs(difference);
}
write_motor(&mtrs[i], mtrs[i].goal_speed);
}
}
void move(Motor * mtrs, int32_t num_mtrs, int32_t * val) {
}
void stop(Motor * mtrs, int32_t num_mtrs) {
int32_t mtr_vals[num_mtrs];
for (int32_t i=0; i<num_mtrs; i++) {
write_motor(&mtrs[i], 0);
}
}
void calibrate(Motor * mtrs, int32_t num_mtrs) {
for (int32_t i=0; i<2; i++) {
for (int32_t j=-255; j<255; j+=10) {
int32_t mtr_vals[num_mtrs];
for (int32_t i=0; i<num_mtrs; i++) {
mtr_vals[i] = j;
}
move(mtrs, num_mtrs, mtr_vals);
delay(300);
}
}
stop(mtrs, num_mtrs);
delay(2000);
stop(mtrs, num_mtrs);
delay(2000);
}
|
anconaesselmann/Stats | Example/Pods/Target Support Files/Stats/Stats-umbrella.h | #ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
FOUNDATION_EXPORT double StatsVersionNumber;
FOUNDATION_EXPORT const unsigned char StatsVersionString[];
|
ChatPy/ChatPy | server.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *command;
strcpy(command, "python3 server.py");
system(command);
return 0;
}
|
szarnyasg/pygraphblas | pygraphblas/cdef/LAGraph/LAGraph_internal.h | <gh_stars>0
//------------------------------------------------------------------------------
// LAGraph_internal.h: include file for internal use in LAGraph
//------------------------------------------------------------------------------
/*
LAGraph: graph algorithms based on GraphBLAS
Copyright 2019 LAGraph Contributors.
(see Contributors.txt for a full list of Contributors; see
ContributionInstructions.txt for information on how you can Contribute to
this project).
All Rights Reserved.
NO WARRANTY. THIS MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. THE LAGRAPH
CONTRIBUTORS MAKE NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
THE MATERIAL. THE CONTRIBUTORS DO NOT MAKE ANY WARRANTY OF ANY KIND WITH
RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
Released under a BSD license, please see the LICENSE file distributed with
this Software or contact <EMAIL> for full terms.
Created, in part, with funding and support from the United States
Government. (see Acknowledgments.txt file).
This program includes and/or can make use of certain third party source
code, object code, documentation and other files ("Third Party Software").
See LICENSE file for more details.
*/
//------------------------------------------------------------------------------
// LAGraph_internal.h: contributed by <NAME>, Texas A&M
// Include file for LAGraph functions. This file should not be included in
// user applications. See LAGraph.h instead.
// #include "LAGraph.h"
#ifndef CMPLX
#define CMPLX(real,imag) \
( \
(double complex)((double)(real)) + \
(double complex)((double)(imag) * _Complex_I) \
)
#endif
#ifdef MATLAB_MEX_FILE
// compiling LAGraph for a MATLAB mexFunction. Use mxMalloc, mxFree, etc.
#include "mex.h"
#include "matrix.h"
#define malloc mxMalloc
#define free mxFree
#define calloc mxCalloc
#define realloc mxRealloc
#endif
//------------------------------------------------------------------------------
// code development settings
//------------------------------------------------------------------------------
// LAGRAPH_XSTR: convert the content of x into a string "x"
#define LAGRAPH_XSTR(x) LAGRAPH_STR(x)
#define LAGRAPH_STR(x) #x
// turn off debugging; do not edit these three lines
#ifndef NDEBUG
#define NDEBUG
#endif
// These flags are used for code development. Uncomment them as needed.
// to turn on debugging, uncomment this line:
// #undef NDEBUG
#undef ASSERT
#ifndef NDEBUG
// debugging enabled
#ifdef MATLAB_MEX_FILE
#define ASSERT(x) \
{ \
if (!(x)) \
{ \
mexErrMsgTxt ("failure: " __FILE__ " line: " \
LAGRAPH_XSTR(__LINE__)) ; \
} \
}
#else
#include <assert.h>
#define ASSERT(x) assert (x) ;
#endif
#else
// debugging disabled
#define ASSERT(x)
#endif
//------------------------------------------------------------------------------
// Matrix Market format
//------------------------------------------------------------------------------
// %%MatrixMarket matrix <fmt> <type> <storage> uses the following enums:
typedef enum
{
MM_coordinate,
MM_array,
}
MM_fmt_enum ;
typedef enum
{
MM_real,
MM_integer,
MM_complex,
MM_pattern
}
MM_type_enum ;
typedef enum
{
MM_general,
MM_symmetric,
MM_skew_symmetric,
MM_hermitian
}
MM_storage_enum ;
// maximum length of each line in the Matrix Market file format
// The MatrixMarket format specificies a maximum line length of 1024.
// This is currently sufficient for GraphBLAS but will need to be relaxed
// if this function is extended to handle arbitrary user-defined types.
#define MMLEN 1024
#define MAXLINE MMLEN+6
|
szarnyasg/pygraphblas | pygraphblas/cdef/extra.h | <reponame>szarnyasg/pygraphblas<gh_stars>0
const double INFINITY = 0.0; // ... is ints only, so this is a workaround
#define UINT64_MAX ...
#define INT64_MAX ...
#define UINT32_MAX ...
#define INT32_MAX ...
#define UINT16_MAX ...
#define INT16_MAX ...
#define UINT8_MAX ...
#define INT8_MAX ...
#define INT64_MIN ...
#define INT32_MIN ...
#define INT16_MIN ...
#define INT8_MIN ...
|
szarnyasg/pygraphblas | pygraphblas/cdef/LAGraph/LAGraph_Vector_to_dense.c | //------------------------------------------------------------------------------
// LAGraph_Vector_to_dense: convert a vector to dense
//------------------------------------------------------------------------------
/*
LAGraph: graph algorithms based on GraphBLAS
Copyright 2019 LAGraph Contributors.
(see Contributors.txt for a full list of Contributors; see
ContributionInstructions.txt for information on how you can Contribute to
this project).
All Rights Reserved.
NO WARRANTY. THIS MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. THE LAGRAPH
CONTRIBUTORS MAKE NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
THE MATERIAL. THE CONTRIBUTORS DO NOT MAKE ANY WARRANTY OF ANY KIND WITH
RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
Released under a BSD license, please see the LICENSE file distributed with
this Software or contact <EMAIL> for full terms.
Created, in part, with funding and support from the United States
Government. (see Acknowledgments.txt file).
This program includes and/or can make use of certain third party source
code, object code, documentation and other files ("Third Party Software").
See LICENSE file for more details.
*/
//------------------------------------------------------------------------------
// LAGraph_Vector_to_dense: convert a vector to dense, contributed by Tim
// Davis, Texas A&M
// vdense is a dense copy of v. Where v(i) exists, vdense(i) = v(i). If v(i)
// is not in the pattern, it is assigned the value v(i) = id.
#include "LAGraph_internal.h"
#define LAGRAPH_FREE_ALL \
GrB_free (&u) ;
GrB_Info LAGraph_Vector_to_dense
(
GrB_Vector *vdense, // output vector
GrB_Vector v, // input vector
void *id // pointer to value to fill vdense with
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
GrB_Info info ;
GrB_Vector u = NULL ;
if (vdense == NULL || id == NULL)
{
// TODO decide on a consistent error-handling mechanism
LAGRAPH_ERROR ("arguments missing", GrB_NULL_POINTER) ;
}
(*vdense) = NULL ;
// GxB_fprint (v, 2, stderr) ;
//--------------------------------------------------------------------------
// get the type and size of v
//--------------------------------------------------------------------------
GrB_Type type ;
GrB_Index n, nvals ;
LAGRAPH_OK (GxB_Vector_type (&type, v)) ;
LAGRAPH_OK (GrB_Vector_size (&n, v)) ;
LAGRAPH_OK (GrB_Vector_nvals (&nvals, v)) ;
// u = empty vector, the same type and size as v
LAGRAPH_OK (GrB_Vector_new (&u, type, n)) ;
//--------------------------------------------------------------------------
// create u as a dense vector, all entries equal to (*id)
//--------------------------------------------------------------------------
// define macro to fill u with all entries equal to (*id)
#define FILL(ctype,gtype,arg) \
{ \
/* cast the void pointer to the right type and dereference it */ \
ctype value = (* (ctype *) id) ; \
for (GrB_Index i = 0 ; i < n ; i++) \
{ \
/* u (i) = value */ \
LAGRAPH_OK (GrB_Vector_setElement_ ## gtype (u, arg, i)) ; \
} \
id_is_zero = (value == 0) ; \
}
bool id_is_zero ;
if (type == GrB_BOOL ) FILL (bool , BOOL , value)
else if (type == GrB_INT8 ) FILL (int8_t , INT8 , value)
else if (type == GrB_INT16 ) FILL (int16_t , INT16 , value)
else if (type == GrB_INT32 ) FILL (int32_t , INT32 , value)
else if (type == GrB_INT64 ) FILL (int64_t , INT64 , value)
else if (type == GrB_UINT8 ) FILL (uint8_t , UINT8 , value)
else if (type == GrB_UINT16 ) FILL (uint16_t , UINT16, value)
else if (type == GrB_UINT32 ) FILL (uint32_t , UINT32, value)
else if (type == GrB_UINT64 ) FILL (uint64_t , UINT64, value)
else if (type == GrB_FP32 ) FILL (float , FP32 , value)
else if (type == GrB_FP64 ) FILL (double , FP64 , value)
else if (type == LAGraph_Complex ) FILL (double complex, UDT , id )
else
{
LAGRAPH_ERROR ("type not supported", GrB_INVALID_VALUE) ;
}
// finish the vector
GrB_Index ignore ;
LAGRAPH_OK (GrB_Vector_nvals (&ignore, u)) ;
//--------------------------------------------------------------------------
// scatter the sparse vector v into u
//--------------------------------------------------------------------------
if (nvals > 0)
{
if (id_is_zero && type != LAGraph_Complex)
{
// use v itself for the mask for built-in types, if (*id) is zero
// u (v != 0) = v
LAGRAPH_OK (GrB_assign (u, v, NULL, v, GrB_ALL, n, NULL)) ;
}
else
{
// TODO: not yet written
// get the pattern of v
// u (pattern) = v
LAGRAPH_ERROR ("TODO", GrB_INVALID_VALUE) ;
}
}
// GxB_fprint (u, 2, stderr) ;
// finish the assignment
LAGRAPH_OK (GrB_Vector_nvals (&ignore, u)) ;
//--------------------------------------------------------------------------
// return result
//--------------------------------------------------------------------------
(*vdense) = u ;
return (GrB_SUCCESS) ;
}
|
szarnyasg/pygraphblas | pygraphblas/cdef/LAGraph/LAGraph_rand.c | //------------------------------------------------------------------------------
// LAGraph_rand: return a random number
//------------------------------------------------------------------------------
/*
LAGraph: graph algorithms based on GraphBLAS
Copyright 2019 LAGraph Contributors.
(see Contributors.txt for a full list of Contributors; see
ContributionInstructions.txt for information on how you can Contribute to
this project).
All Rights Reserved.
NO WARRANTY. THIS MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. THE LAGRAPH
CONTRIBUTORS MAKE NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
THE MATERIAL. THE CONTRIBUTORS DO NOT MAKE ANY WARRANTY OF ANY KIND WITH
RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
Released under a BSD license, please see the LICENSE file distributed with
this Software or contact <EMAIL> for full terms.
Created, in part, with funding and support from the United States
Government. (see Acknowledgments.txt file).
This program includes and/or can make use of certain third party source
code, object code, documentation and other files ("Third Party Software").
See LICENSE file for more details.
*/
//------------------------------------------------------------------------------
// LAGraph_rand: return a random number, contributed by <NAME>, Texas A&M.
// Modified from the POSIX-1.2001 example of rand.
// A simple thread-safe random number generator that returns a random number
// between 0 and LAGRAPH_RAND_MAX. The quality of the random values it
// generates is very low, but this is not important. This method is used to
// create random test matrices, which must be identical on any operating
// system.
#include "LAGraph_internal.h"
uint64_t LAGraph_rand (uint64_t *seed)
{
(*seed) = (*seed) * 1103515245 + 12345 ;
return (((*seed)/65536) % (LAGRAPH_RAND_MAX + 1)) ;
}
|
szarnyasg/pygraphblas | pygraphblas/cdef/LAGraph/LAgraph_1_to_n.c | <gh_stars>0
#include "LAGraph_internal.h"
#define LAGRAPH_FREE_ALL \
{ \
GrB_free (&v) ; \
LAGRAPH_FREE (I) ; \
LAGRAPH_FREE (X) ; \
}
GrB_Info LAGraph_1_to_n // create an integer vector v = 1:n
(
GrB_Vector *v_handle, // vector to create
GrB_Index n // size of vector to create
)
{
GrB_Info info ;
GrB_Vector v = NULL ;
int nthreads = LAGraph_get_nthreads ( ) ;
nthreads = LAGRAPH_MIN (n / 4096, nthreads) ;
nthreads = LAGRAPH_MAX (nthreads, 1) ;
// allocate workspace
GrB_Index *I = LAGraph_malloc (n, sizeof (GrB_Index)) ;
// create a 32-bit or 64-bit integer vector 1:n
if (n > INT32_MAX)
{
int64_t *X = LAGraph_malloc (n, sizeof (int64_t)) ;
if (I == NULL || X == NULL)
{
LAGRAPH_FREE_ALL ;
return (GrB_OUT_OF_MEMORY) ;
}
#pragma omp parallel for num_threads(nthreads) schedule(static)
for (int64_t k = 0 ; k < n ; k++)
{
I [k] = k ;
X [k] = k+1 ;
}
LAGRAPH_OK (GrB_Vector_new (&v, GrB_INT64, n)) ;
LAGRAPH_OK (GrB_Vector_build (v, I, X, n, GrB_PLUS_INT64)) ;
LAGRAPH_FREE (X) ;
}
else
{
int32_t *X = LAGraph_malloc (n, sizeof (int32_t)) ;
if (I == NULL || X == NULL)
{
LAGRAPH_FREE_ALL ;
return (GrB_OUT_OF_MEMORY) ;
}
#pragma omp parallel for num_threads(nthreads) schedule(static)
for (int64_t k = 0 ; k < n ; k++)
{
I [k] = k ;
X [k] = k+1 ;
}
LAGRAPH_OK (GrB_Vector_new (&v, GrB_INT32, n)) ;
LAGRAPH_OK (GrB_Vector_build (v, I, X, n, GrB_PLUS_INT32)) ;
LAGRAPH_FREE (X) ;
}
LAGRAPH_FREE (I) ;
// return result
(*v_handle) = v ;
return (GrB_SUCCESS) ;
}
|
szarnyasg/pygraphblas | pygraphblas/cdef/LAGraph/LAGraph_binwrite.c | <filename>pygraphblas/cdef/LAGraph/LAGraph_binwrite.c
//------------------------------------------------------------------------------
// LAGraph_binwrite: write a matrix to a binary file
//------------------------------------------------------------------------------
/*
LAGraph: graph algorithms based on GraphBLAS
Copyright 2019 LAGraph Contributors.
(see Contributors.txt for a full list of Contributors; see
ContributionInstructions.txt for information on how you can Contribute to
this project).
All Rights Reserved.
NO WARRANTY. THIS MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. THE LAGRAPH
CONTRIBUTORS MAKE NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
THE MATERIAL. THE CONTRIBUTORS DO NOT MAKE ANY WARRANTY OF ANY KIND WITH
RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
Released under a BSD license, please see the LICENSE file distributed with
this Software or contact <EMAIL> for full terms.
Created, in part, with funding and support from the United States
Government. (see Acknowledgments.txt file).
This program includes and/or can make use of certain third party source
code, object code, documentation and other files ("Third Party Software").
See LICENSE file for more details.
*/
//------------------------------------------------------------------------------
// LAGraph_binwrite: write a matrix to a binary file
// Contributed by <NAME>, Texas A&M.
// Writes a matrix to a file in a binary format.
#include "LAGraph_internal.h"
#define LAGRAPH_FREE_ALL \
{ \
GrB_free (A) ; \
LAGRAPH_FREE (Ap) ; \
LAGRAPH_FREE (Ah) ; \
LAGRAPH_FREE (Ai) ; \
LAGRAPH_FREE (Ax) ; \
}
#define FWRITE(p,s,n) \
{ \
size_t result = fwrite (p, s, n, f) ; \
if (result != n) \
{ \
fclose (f) ; \
LAGRAPH_ERROR ("File I/O error", GrB_INVALID_VALUE) ; \
} \
}
//------------------------------------------------------------------------------
// LAGraph_binwrite
//------------------------------------------------------------------------------
GrB_Info LAGraph_binwrite
(
GrB_Matrix *A, // matrix to write to the file
char *filename, // file to write it to
const char *comments // comments to add to the file, up to 220 characters
// in length, not including the terminating null
// byte. Ignored if NULL. Characters past
// the 220 limit are silently ignored.
)
{
GrB_Index *Ap = NULL, *Ai = NULL, *Ah = NULL ;
void *Ax = NULL ;
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
GrB_Info info ;
if (A == NULL || *A == NULL || filename == NULL)
{
// input arguments invalid
LAGRAPH_ERROR ("LAGraph_binwrite: invalid inputs\n", GrB_NULL_POINTER) ;
}
FILE *f = fopen (filename, "w") ;
if (f == NULL)
{
LAGRAPH_ERROR ("LAGraph_binwrite: file cannot be opened",
GrB_INVALID_VALUE) ;
}
GrB_Index ignore ;
LAGRAPH_OK (GrB_Matrix_nvals (&ignore, *A)) ;
//--------------------------------------------------------------------------
// determine the basic matrix properties
//--------------------------------------------------------------------------
GxB_Format_Value fmt = -999 ;
LAGRAPH_OK (GxB_get (*A, GxB_FORMAT, &fmt)) ;
bool is_hyper ;
LAGRAPH_OK (GxB_get (*A, GxB_IS_HYPER, &is_hyper)) ;
// kind == 3 reserved for dense matrices
int32_t kind = is_hyper ? 1 : 0 ;
double hyper = -999 ;
LAGRAPH_OK (GxB_get (*A, GxB_HYPER, &hyper)) ;
//--------------------------------------------------------------------------
// export the matrix
//--------------------------------------------------------------------------
GrB_Type type ;
GrB_Index nrows, ncols, nvals, nvec ;
size_t typesize ;
int64_t nonempty ;
char *fmt_string ;
if (fmt == GxB_BY_COL && !is_hyper)
{
// standard CSC
LAGRAPH_OK (GxB_Matrix_export_CSC (A, &type, &nrows, &ncols, &nvals,
&nonempty, &Ap, &Ai, &Ax, NULL)) ;
nvec = ncols ;
fmt_string = "CSC " ;
}
else if (fmt == GxB_BY_ROW && !is_hyper)
{
// standard CSR
LAGRAPH_OK (GxB_Matrix_export_CSR (A, &type, &nrows, &ncols, &nvals,
&nonempty, &Ap, &Ai, &Ax, NULL)) ;
nvec = nrows ;
fmt_string = "CSR " ;
}
else if (fmt == GxB_BY_COL && is_hyper)
{
// hypersparse CSC
LAGRAPH_OK (GxB_Matrix_export_HyperCSC (A, &type, &nrows, &ncols,
&nvals, &nonempty, &nvec, &Ah, &Ap, &Ai, &Ax, NULL)) ;
fmt_string = "HCSC" ;
}
else if (fmt == GxB_BY_ROW && is_hyper)
{
// hypersparse CSR
LAGRAPH_OK (GxB_Matrix_export_HyperCSR (A, &type, &nrows, &ncols,
&nvals, &nonempty, &nvec, &Ah, &Ap, &Ai, &Ax, NULL)) ;
fmt_string = "HCSR" ;
}
else
{
LAGRAPH_ERROR ("unknown", GrB_INVALID_VALUE) ;
}
LAGRAPH_OK (GxB_Type_size (&typesize, type)) ;
#define LEN LAGRAPH_BIN_HEADER
char typename [LEN] ;
int32_t typecode ;
if (type == GrB_BOOL )
{
snprintf (typename, LEN, "GrB_BOOL ") ;
typecode = 0 ;
}
else if (type == GrB_INT8 )
{
snprintf (typename, LEN, "GrB_INT8 ") ;
typecode = 1 ;
}
else if (type == GrB_INT16 )
{
snprintf (typename, LEN, "GrB_INT16 ") ;
typecode = 2 ;
}
else if (type == GrB_INT32 )
{
snprintf (typename, LEN, "GrB_INT32 ") ;
typecode = 3 ;
}
else if (type == GrB_INT64 )
{
snprintf (typename, LEN, "GrB_INT64 ") ;
typecode = 4 ;
}
else if (type == GrB_UINT8 )
{
snprintf (typename, LEN, "GrB_UINT8 ") ;
typecode = 5 ;
}
else if (type == GrB_UINT16)
{
snprintf (typename, LEN, "GrB_UINT16") ;
typecode = 6 ;
}
else if (type == GrB_UINT32)
{
snprintf (typename, LEN, "GrB_UINT32") ;
typecode = 7 ;
}
else if (type == GrB_UINT64)
{
snprintf (typename, LEN, "GrB_UINT64") ;
typecode = 8 ;
}
else if (type == GrB_FP32 )
{
snprintf (typename, LEN, "GrB_FP32 ") ;
typecode = 9 ;
}
else if (type == GrB_FP64 )
{
snprintf (typename, LEN, "GrB_FP64 ") ;
typecode = 10 ;
}
else if (type == LAGraph_Complex)
{
snprintf (typename, LEN, "USER ") ;
typecode = 11 ;
}
else
{
LAGRAPH_ERROR ("Type not supported", GrB_INVALID_VALUE) ;
}
typename [72] = '\0' ;
//--------------------------------------------------------------------------
// write the header in ascii
//--------------------------------------------------------------------------
// The header is informational only, for "head" command, so the file can
// be visually inspected.
char version [LEN] ;
snprintf (version, LEN, "%d.%d.%d (LAGraph DRAFT)",
GxB_IMPLEMENTATION_MAJOR,
GxB_IMPLEMENTATION_MINOR,
GxB_IMPLEMENTATION_SUB) ;
version [25] = '\0' ;
char user [LEN] ;
for (int k = 0 ; k < LEN ; k++) user [k] = ' ' ;
user [0] = '\n' ;
if (comments != NULL)
{
strncpy (user, comments, 220) ;
}
user [220] = '\0' ;
char header [LAGRAPH_BIN_HEADER] ;
int32_t len = snprintf (header, LAGRAPH_BIN_HEADER,
"SuiteSparse:GraphBLAS matrix\nv%-25s\n"
"nrows: %-18" PRIu64 "\n"
"ncols: %-18" PRIu64 "\n"
"nvec: %-18" PRIu64 "\n"
"nvals: %-18" PRIu64 "\n"
"format: %-8s\n"
"size: %-18" PRIu64 "\n"
"type: %-72s\n"
"%-220s\n\n",
version, nrows, ncols, nvec, nvals, fmt_string, (uint64_t) typesize,
typename, user) ;
// printf ("header len %d\n", len) ;
for (int32_t k = len ; k < LAGRAPH_BIN_HEADER ; k++) header [k] = ' ' ;
header [LAGRAPH_BIN_HEADER-1] = '\0' ;
FWRITE (header, sizeof (char), LAGRAPH_BIN_HEADER) ;
//--------------------------------------------------------------------------
// write the scalar content
//--------------------------------------------------------------------------
FWRITE (&fmt, sizeof (GxB_Format_Value), 1) ;
FWRITE (&kind, sizeof (int32_t), 1) ;
FWRITE (&hyper, sizeof (double), 1) ;
FWRITE (&nrows, sizeof (GrB_Index), 1) ;
FWRITE (&ncols, sizeof (GrB_Index), 1) ;
FWRITE (&nonempty, sizeof (int64_t), 1) ;
FWRITE (&nvec, sizeof (GrB_Index), 1) ;
FWRITE (&nvals, sizeof (GrB_Index), 1) ;
FWRITE (&typecode, sizeof (int32_t), 1) ;
FWRITE (&typesize, sizeof (size_t), 1) ;
//--------------------------------------------------------------------------
// write the array content
//--------------------------------------------------------------------------
FWRITE (Ap, sizeof (GrB_Index), nvec+1) ;
if (is_hyper)
{
FWRITE (Ah, sizeof (GrB_Index), nvec) ;
}
FWRITE (Ai, sizeof (GrB_Index), nvals) ;
FWRITE (Ax, typesize, nvals) ;
fclose (f) ;
//--------------------------------------------------------------------------
// re-import the matrix
//--------------------------------------------------------------------------
if (fmt == GxB_BY_COL && !is_hyper)
{
// standard CSC
LAGRAPH_OK (GxB_Matrix_import_CSC (A, type, nrows, ncols, nvals,
nonempty, &Ap, &Ai, &Ax, NULL)) ;
}
else if (fmt == GxB_BY_ROW && !is_hyper)
{
// standard CSR
LAGRAPH_OK (GxB_Matrix_import_CSR (A, type, nrows, ncols, nvals,
nonempty, &Ap, &Ai, &Ax, NULL)) ;
}
else if (fmt == GxB_BY_COL && is_hyper)
{
// hypersparse CSC
LAGRAPH_OK (GxB_Matrix_import_HyperCSC (A, type, nrows, ncols, nvals,
nonempty, nvec, &Ah, &Ap, &Ai, &Ax, NULL)) ;
}
else if (fmt == GxB_BY_ROW && is_hyper)
{
// hypersparse CSR
LAGRAPH_OK (GxB_Matrix_import_HyperCSR (A, type, nrows, ncols, nvals,
nonempty, nvec, &Ah, &Ap, &Ai, &Ax, NULL)) ;
}
else
{
LAGRAPH_ERROR ("unknown", GrB_INVALID_VALUE) ;
}
LAGRAPH_OK (GxB_set (*A, GxB_HYPER, hyper)) ;
return (GrB_SUCCESS) ;
}
|
szarnyasg/pygraphblas | pygraphblas/cdef/LAGraph/LAGraph_prune_diag.c | //------------------------------------------------------------------------------
// LAGraph_prune_diag: remove diagonal entries from a matrix
//------------------------------------------------------------------------------
/*
LAGraph: graph algorithms based on GraphBLAS
Copyright 2019 LAGraph Contributors.
(see Contributors.txt for a full list of Contributors; see
ContributionInstructions.txt for information on how you can Contribute to
this project).
All Rights Reserved.
NO WARRANTY. THIS MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. THE LAGRAPH
CONTRIBUTORS MAKE NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
THE MATERIAL. THE CONTRIBUTORS DO NOT MAKE ANY WARRANTY OF ANY KIND WITH
RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
Released under a BSD license, please see the LICENSE file distributed with
this Software or contact <EMAIL> for full terms.
Created, in part, with funding and support from the United States
Government. (see Acknowledgments.txt file).
This program includes and/or can make use of certain third party source
code, object code, documentation and other files ("Third Party Software").
See LICENSE file for more details.
*/
//------------------------------------------------------------------------------
// LAGraph_prune_diag: contributed by <NAME>. Removes all diagonal entries
// from a matrix.
//------------------------------------------------------------------------------
#define LAGRAPH_FREE_ALL GrB_free (&M)
#include "LAGraph_internal.h"
GrB_Info LAGraph_prune_diag // remove all entries from the diagonal
(
GrB_Matrix A
)
{
GrB_Info info ;
GrB_Matrix M = NULL ;
GrB_Index m, n ;
LAGRAPH_OK (GrB_Matrix_nrows (&m, A)) ;
LAGRAPH_OK (GrB_Matrix_nrows (&n, A)) ;
int64_t k = LAGRAPH_MIN (m, n) ;
// M = diagonal mask matrix
LAGRAPH_OK (GrB_Matrix_new (&M, GrB_BOOL, m, n)) ;
for (int64_t i = 0 ; i < k ; i++)
{
// M(i,i) = true ;
LAGRAPH_OK (GrB_Matrix_setElement (M, (bool) true, i, i)) ;
}
// remove self edges (via M)
LAGRAPH_OK (GrB_assign (A, M, NULL, A, GrB_ALL, m, GrB_ALL, n,
LAGraph_desc_oocr)) ;
GrB_free (&M) ;
return (GrB_SUCCESS) ;
}
|
szarnyasg/pygraphblas | pygraphblas/cdef/LAGraph/LAGraph_toc.c | //------------------------------------------------------------------------------
// LAGraph_toc: a portable timer for accurate performance measurements
//------------------------------------------------------------------------------
/*
LAGraph: graph algorithms based on GraphBLAS
Copyright 2019 LAGraph Contributors.
(see Contributors.txt for a full list of Contributors; see
ContributionInstructions.txt for information on how you can Contribute to
this project).
All Rights Reserved.
NO WARRANTY. THIS MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. THE LAGRAPH
CONTRIBUTORS MAKE NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
THE MATERIAL. THE CONTRIBUTORS DO NOT MAKE ANY WARRANTY OF ANY KIND WITH
RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
Released under a BSD license, please see the LICENSE file distributed with
this Software or contact <EMAIL> for full terms.
Created, in part, with funding and support from the United States
Government. (see Acknowledgments.txt file).
This program includes and/or can make use of certain third party source
code, object code, documentation and other files ("Third Party Software").
See LICENSE file for more details.
*/
//------------------------------------------------------------------------------
// LAGraph_toc: return the time since the last LAGraph_tic
// Contributed by <NAME>, Texas A&M
#include "LAGraph_internal.h"
double LAGraph_toc // returns time since last LAGraph_tic
(
const double tic [2] // tic from last call to LAGraph_tic
)
{
double toc [2] ;
LAGraph_tic (toc) ;
return ((toc [0] - tic [0]) + 1e-9 * (toc [1] - tic [1])) ;
}
|
szarnyasg/pygraphblas | pygraphblas/cdef/LAGraph/LAGraph_log.c | //------------------------------------------------------------------------------
// LAGraph_log: log a test result for LAGraph
//------------------------------------------------------------------------------
/*
LAGraph: graph algorithms based on GraphBLAS
Copyright 2019 LAGraph Contributors.
(see Contributors.txt for a full list of Contributors; see
ContributionInstructions.txt for information on how you can Contribute to
this project).
All Rights Reserved.
NO WARRANTY. THIS MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. THE LAGRAPH
CONTRIBUTORS MAKE NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
THE MATERIAL. THE CONTRIBUTORS DO NOT MAKE ANY WARRANTY OF ANY KIND WITH
RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
Released under a BSD license, please see the LICENSE file distributed with
this Software or contact <EMAIL> for full terms.
Created, in part, with funding and support from the United States
Government. (see Acknowledgments.txt file).
This program includes and/or can make use of certain third party source
code, object code, documentation and other files ("Third Party Software").
See LICENSE file for more details.
*/
//------------------------------------------------------------------------------
// LAGraph_log: log a result from LAGraph, contributed by <NAME>, Texas A&M
#define LAGRAPH_FREE_ALL
#include "LAGraph_internal.h"
#include <time.h>
static void delete_newline (char *p)
{
for ( ; *p ; p++)
{
if (*p == '\n')
{
*p = '\0' ;
return ;
}
}
}
GrB_Info LAGraph_log
(
char *caller, // calling function
char *message1, // message to include (may be NULL)
char *message2, // message to include (may be NULL)
int nthreads, // # of threads used
double t // time taken by the test
)
{
GrB_Info info ;
// try to get the hostname and cpu type
char hostname [1024] ;
hostname [0] = '\0' ;
FILE *host = fopen ("/etc/hostname", "r") ;
if (host != NULL)
{
// get the hostname
if (!fgets (hostname, 1000, host)) hostname [0] = '\0' ;
// delete the newline
delete_newline (hostname) ;
fclose (host) ;
}
char filename [2048] ;
snprintf (filename, 2000, "log_%s.txt", hostname) ;
FILE *f = fopen (filename, "a") ;
if (f == NULL)
{
LAGRAPH_ERROR ("cannot open logfile", GrB_INVALID_VALUE) ;
}
time_t now = time (NULL) ;
fprintf (f, "\nFrom: %s\nDate: %s", caller, ctime (&now)) ;
FILE *cpuinfo = fopen ("/proc/cpuinfo", "r") ;
if (cpuinfo != NULL)
{
while (1)
{
// get the line
char line [2048] ;
if (!fgets (line, 2000, cpuinfo))
{
break ;
}
// find the colon
bool found = false ;
char *p = line ;
for ( ; (*p) ; p++)
{
if (*p == ':')
{
*p = '\0' ;
p++ ;
if (strncmp (line, "model name", 10) == 0)
{
delete_newline (p) ;
fprintf (f, "CPU: %s\n", p) ;
found = true ;
break ;
}
}
}
if (found) break ;
}
}
fprintf (f, "max # of threads: %d\n", LAGraph_get_nthreads ( )) ;
#ifdef GxB_SUITESPARSE_GRAPHBLAS
char *library_date ;
GxB_get (GxB_LIBRARY_DATE, &library_date) ;
fprintf (f, "SuiteSparse:GraphBLAS %s\n", library_date) ;
#endif
fprintf (f, "Message: %s : %s\n# threads used: %d time: %g\n",
(message1 == NULL) ? "" : message1,
(message2 == NULL) ? "" : message2,
nthreads, t) ;
fclose (f) ;
return (GrB_SUCCESS) ;
}
|
szarnyasg/pygraphblas | pygraphblas/cdef/la_a6fcf0_cdef.h | <reponame>szarnyasg/pygraphblas
//------------------------------------------------------------------------------
// LAGraph.h: include file for user applications that use LAGraph
//------------------------------------------------------------------------------
/*
LAGraph: graph algorithms based on GraphBLAS
Copyright 2019 LAGraph Contributors.
(see Contributors.txt for a full list of Contributors; see
ContributionInstructions.txt for information on how you can Contribute to
this project).
All Rights Reserved.
NO WARRANTY. THIS MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. THE LAGRAPH
CONTRIBUTORS MAKE NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
THE MATERIAL. THE CONTRIBUTORS DO NOT MAKE ANY WARRANTY OF ANY KIND WITH
RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
Released under a BSD license, please see the LICENSE file distributed with
this Software or contact <EMAIL> for full terms.
Created, in part, with funding and support from the United States
Government. (see Acknowledgments.txt file).
This program includes and/or can make use of certain third party source
code, object code, documentation and other files ("Third Party Software").
See LICENSE file for more details.
*/
//------------------------------------------------------------------------------
// TODO: add more comments to this file.
//------------------------------------------------------------------------------
// include files and global #defines
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// memory management functions
//------------------------------------------------------------------------------
// use the ANSI C functions by default (or mx* functions if the #ifdef
// above redefines them). See Source/Utility/LAGraph_malloc.c.
extern GrB_Type LAGraph_Complex ;
extern GrB_BinaryOp
// binary operators to test for symmetry, skew-symmetry
// and Hermitian property
LAGraph_EQ_Complex ,
LAGraph_SKEW_INT8 ,
LAGraph_SKEW_INT16 ,
LAGraph_SKEW_INT32 ,
LAGraph_SKEW_INT64 ,
LAGraph_SKEW_FP32 ,
LAGraph_SKEW_FP64 ,
LAGraph_SKEW_Complex ,
LAGraph_Hermitian ,
LAGraph_LOR_UINT32 ,
LAGraph_LOR_INT64 ;
extern GrB_UnaryOp
// unary operators to check if the entry is equal to 1
LAGraph_ISONE_INT8 ,
LAGraph_ISONE_INT16 ,
LAGraph_ISONE_INT32 ,
LAGraph_ISONE_INT64 ,
LAGraph_ISONE_UINT8 ,
LAGraph_ISONE_UINT16 ,
LAGraph_ISONE_UINT32 ,
LAGraph_ISONE_UINT64 ,
LAGraph_ISONE_FP32 ,
LAGraph_ISONE_FP64 ,
LAGraph_ISONE_Complex ,
// unary operators to check if the entry is equal to 2
LAGraph_ISTWO_UINT32 ,
LAGraph_ISTWO_INT64 ,
// unary operators that decrement by 1
LAGraph_DECR_INT32 ,
LAGraph_DECR_INT64 ,
// unary operators for lcc
LAGraph_COMB_DIR_FP64 ,
LAGraph_COMB_UNDIR_FP64 ,
// unary ops to check if greater than zero
LAGraph_GT0_FP32 ,
LAGraph_GT0_FP64 ,
// unary YMAX ops for DNN
LAGraph_YMAX_FP32 ,
LAGraph_YMAX_FP64 ,
// unary operators that return 1
LAGraph_ONE_UINT32 ,
LAGraph_ONE_INT64 ,
LAGraph_ONE_FP64 ,
LAGraph_TRUE_BOOL ,
LAGraph_TRUE_BOOL_Complex ;
// monoids and semirings
extern GrB_Monoid
LAGraph_PLUS_INT64_MONOID ,
LAGraph_MAX_INT32_MONOID ,
LAGraph_LAND_MONOID ,
LAGraph_LOR_MONOID ,
LAGraph_MIN_INT32_MONOID ,
LAGraph_MIN_INT64_MONOID ,
LAGraph_PLUS_UINT32_MONOID ,
LAGraph_PLUS_FP32_MONOID ,
LAGraph_PLUS_FP64_MONOID ,
LAGraph_DIV_FP64_MONOID ;
extern GrB_Semiring
LAGraph_LOR_LAND_BOOL ,
LAGraph_LOR_SECOND_BOOL ,
LAGraph_LOR_FIRST_BOOL ,
LAGraph_MIN_SECOND_INT32 ,
LAGraph_MIN_FIRST_INT32 ,
LAGraph_MIN_SECOND_INT64 ,
LAGraph_MIN_FIRST_INT64 ,
LAGraph_PLUS_TIMES_UINT32 ,
LAGraph_PLUS_TIMES_INT64 ,
LAGraph_PLUS_TIMES_FP64 ,
LAGraph_PLUS_PLUS_FP64 ,
LAGraph_PLUS_TIMES_FP32 ,
LAGraph_PLUS_PLUS_FP32 ;
// all 16 descriptors
// syntax: 4 characters define the following. 'o' is the default:
// 1: o or t: A transpose
// 2: o or t: B transpose
// 3: o or c: complemented mask
// 4: o or r: replace
extern GrB_Descriptor
LAGraph_desc_oooo , // default (NULL)
LAGraph_desc_ooor , // replace
LAGraph_desc_ooco , // compl mask
LAGraph_desc_oocr , // compl mask, replace
LAGraph_desc_tooo , // A'
LAGraph_desc_toor , // A', replace
LAGraph_desc_toco , // A', compl mask
LAGraph_desc_tocr , // A', compl mask, replace
LAGraph_desc_otoo , // B'
LAGraph_desc_otor , // B', replace
LAGraph_desc_otco , // B', compl mask
LAGraph_desc_otcr , // B', compl mask, replace
LAGraph_desc_ttoo , // A', B'
LAGraph_desc_ttor , // A', B', replace
LAGraph_desc_ttco , // A', B', compl mask
LAGraph_desc_ttcr ; // A', B', compl mask, replace
typedef void (*LAGraph_binary_function) (void *, const void *, const void *) ;
GrB_Info LAGraph_init (void) ; // start LAGraph
GrB_Info LAGraph_xinit // start LAGraph (alternative method)
(
// pointers to memory management functions
void * (* user_malloc_function ) (size_t),
void * (* user_calloc_function ) (size_t, size_t),
void * (* user_realloc_function ) (void *, size_t),
void (* user_free_function ) (void *),
bool user_malloc_is_thread_safe
) ;
GrB_Info LAGraph_finalize (void) ; // end LAGraph
GrB_Info LAGraph_mmread
(
GrB_Matrix *A, // handle of matrix to create
FILE *f // file to read from, already open
) ;
GrB_Info LAGraph_mmwrite
(
GrB_Matrix A, // matrix to write to the file
FILE *f // file to write it to
// TODO , FILE *fcomments // optional file with extra comments
) ;
// ascii header prepended to all *.grb files
#define LAGRAPH_BIN_HEADER ...
GrB_Info LAGraph_binwrite
(
GrB_Matrix *A, // matrix to write to the file
char *filename, // file to write it to
const char *comments // comments to add to the file, up to 220 characters
// in length, not including the terminating null
// byte. Ignored if NULL. Characters past
// the 220 limit are silently ignored.
) ;
GrB_Info LAGraph_binread
(
GrB_Matrix *A, // matrix to read from the file
char *filename // file to read it from
) ;
GrB_Info LAGraph_tsvread // returns GrB_SUCCESS if successful
(
GrB_Matrix *Chandle, // C, created on output
FILE *f, // file to read from (already open)
GrB_Type type, // the type of C to create
GrB_Index nrows, // C is nrows-by-ncols
GrB_Index ncols
) ;
GrB_Info LAGraph_ispattern // return GrB_SUCCESS if successful
(
bool *result, // true if A is all one, false otherwise
GrB_Matrix A,
GrB_UnaryOp userop // for A with arbitrary user-defined type.
// Ignored if A and B are of built-in types or
// LAGraph_Complex.
) ;
GrB_Info LAGraph_pattern // return GrB_SUCCESS if successful
(
GrB_Matrix *C, // a boolean matrix with the pattern of A
GrB_Matrix A,
GrB_Type T // return type for C
) ;
GrB_Info LAGraph_isequal // return GrB_SUCCESS if successful
(
bool *result, // true if A == B, false if A != B or error
GrB_Matrix A,
GrB_Matrix B,
GrB_BinaryOp userop // for A and B with arbitrary user-defined types.
// Ignored if A and B are of built-in types or
// LAGraph_Complex.
) ;
GrB_Info LAGraph_Vector_isequal // return GrB_SUCCESS if successful
(
bool *result, // true if A == B, false if A != B or error
GrB_Vector A,
GrB_Vector B,
GrB_BinaryOp userop // for A and B with arbitrary user-defined types.
// Ignored if A and B are of built-in types or
// LAGraph_Complex.
) ;
GrB_Info LAGraph_isall // return GrB_SUCCESS if successful
(
bool *result, // true if A == B, false if A != B or error
GrB_Matrix A,
GrB_Matrix B,
GrB_BinaryOp op // GrB_EQ_<type>, for the type of A and B,
// to check for equality. Or use any desired
// operator. The operator should return GrB_BOOL.
) ;
GrB_Info LAGraph_Vector_isall // return GrB_SUCCESS if successful
(
bool *result, // true if A == B, false if A != B or error
GrB_Vector A,
GrB_Vector B,
GrB_BinaryOp op // GrB_EQ_<type>, for the type of A and B,
// to check for equality. Or use any desired
// operator. The operator should return GrB_BOOL.
) ;
uint64_t LAGraph_rand (uint64_t *seed) ;
uint64_t LAGraph_rand64 (uint64_t *seed) ;
double LAGraph_randx (uint64_t *seed) ;
GrB_Info LAGraph_random // create a random matrix
(
GrB_Matrix *A, // handle of matrix to create
GrB_Type type, // built-in type, or LAGraph_Complex
GrB_Index nrows, // number of rows
GrB_Index ncols, // number of columns
GrB_Index nvals, // number of values
bool make_pattern, // if true, A is a pattern
bool make_symmetric, // if true, A is symmetric
bool make_skew_symmetric, // if true, A is skew-symmetric
bool make_hermitian, // if trur, A is hermitian
bool no_diagonal, // if true, A has no entries on the diagonal
uint64_t *seed // random number seed; modified on return
) ;
GrB_Info LAGraph_alloc_global (void) ;
GrB_Info LAGraph_free_global (void) ;
GrB_Info LAGraph_prune_diag // remove all entries from the diagonal
(
GrB_Matrix A
) ;
GrB_Info LAGraph_Vector_to_dense
(
GrB_Vector *vdense, // output vector
GrB_Vector v, // input vector
void *id // pointer to value to fill vdense with
) ;
GrB_Info LAGraph_1_to_n // create an integer vector v = 1:n
(
GrB_Vector *v_handle, // vector to create
GrB_Index n // size of vector to create
) ;
|
szarnyasg/pygraphblas | pygraphblas/cdef/LAGraph/LAGraph_set_nthreads.c | <reponame>szarnyasg/pygraphblas<filename>pygraphblas/cdef/LAGraph/LAGraph_set_nthreads.c
//------------------------------------------------------------------------------
// LAGraph_set_nthreads: set the # of threads to use
//------------------------------------------------------------------------------
/*
LAGraph: graph algorithms based on GraphBLAS
Copyright 2019 LAGraph Contributors.
(see Contributors.txt for a full list of Contributors; see
ContributionInstructions.txt for information on how you can Contribute to
this project).
All Rights Reserved.
NO WARRANTY. THIS MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. THE LAGRAPH
CONTRIBUTORS MAKE NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
THE MATERIAL. THE CONTRIBUTORS DO NOT MAKE ANY WARRANTY OF ANY KIND WITH
RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
Released under a BSD license, please see the LICENSE file distributed with
this Software or contact <EMAIL> for full terms.
Created, in part, with funding and support from the United States
Government. (see Acknowledgments.txt file).
This program includes and/or can make use of certain third party source
code, object code, documentation and other files ("Third Party Software").
See LICENSE file for more details.
*/
//------------------------------------------------------------------------------
// LAGraph_set_nthreads: set # of threads to use
// contributed by <NAME>, Texas A&M
// See LAGraph_get_nthreads for details on what this function does.
#include "LAGraph_internal.h"
int LAGraph_set_nthreads // returns # threads set, 0 if nothing done
(
int nthreads
)
{
#if defined ( GxB_SUITESPARSE_GRAPHBLAS )
GxB_set (GxB_NTHREADS, nthreads) ;
#elif defined ( _OPENMP )
omp_set_num_threads (nthreads) ;
#else
// nothing to do ...
nthreads = 0 ;
#endif
return (nthreads) ;
}
|
szarnyasg/pygraphblas | pygraphblas/cdef/LAGraph/LAGraph_tsvread.c | <filename>pygraphblas/cdef/LAGraph/LAGraph_tsvread.c
//------------------------------------------------------------------------------
// LAGraph_tsvread: read a tsv file
//------------------------------------------------------------------------------
/*
LAGraph: graph algorithms based on GraphBLAS
Copyright 2019 LAGraph Contributors.
(see Contributors.txt for a full list of Contributors; see
ContributionInstructions.txt for information on how you can Contribute to
this project).
All Rights Reserved.
NO WARRANTY. THIS MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. THE LAGRAPH
CONTRIBUTORS MAKE NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
THE MATERIAL. THE CONTRIBUTORS DO NOT MAKE ANY WARRANTY OF ANY KIND WITH
RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
Released under a BSD license, please see the LICENSE file distributed with
this Software or contact <EMAIL> for full terms.
Created, in part, with funding and support from the United States
Government. (see Acknowledgments.txt file).
This program includes and/or can make use of certain third party source
code, object code, documentation and other files ("Third Party Software").
See LICENSE file for more details.
*/
//------------------------------------------------------------------------------
// LAGraph_tsvread: read a tsv file. Contributed by <NAME>, Texas A&M
// University.
// Reads a tsv file. Each line in the file specifies a single entry: i, j, x.
// The indices i and j are assumed to be one-based. The dimensions of the
// matrix must be provided by the caller. This format is used for matrices at
// http://graphchallenge.org. The Matrix Market format is recommended instead;
// it is more flexible and easier to use, since that format includes the matrix
// type and size in the file itself. See LAGraph_mmread and LAGraph_mmwrite.
// #include "LAGraph.h"
#define LAGRAPH_FREE_ALL GrB_free (Chandle) ;
GrB_Info LAGraph_tsvread // returns GrB_SUCCESS if successful
(
GrB_Matrix *Chandle, // C, created on output
FILE *f, // file to read from (already open)
GrB_Type type, // the type of C to create
GrB_Index nrows, // C is nrows-by-ncols
GrB_Index ncols
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
if (Chandle == NULL || f == NULL)
{
return (GrB_NULL_POINTER) ;
}
//--------------------------------------------------------------------------
// create the output matrix
//--------------------------------------------------------------------------
GrB_Info info ;
GrB_Matrix C = NULL ;
(*Chandle) = NULL ;
LAGRAPH_OK (GrB_Matrix_new (&C, type, nrows, ncols)) ;
//--------------------------------------------------------------------------
// read the entries
//--------------------------------------------------------------------------
GrB_Index i, j ;
if (type == GrB_INT64)
{
//----------------------------------------------------------------------
// read the entries as int64
//----------------------------------------------------------------------
int64_t x ;
while (fscanf (f, "%"PRIu64"%"PRIu64"%"PRId64"\n", &i, &j, &x) != EOF)
{
LAGRAPH_OK (GrB_Matrix_setElement (C, x, i-1, j-1)) ;
}
}
else if (type == GrB_UINT64)
{
//----------------------------------------------------------------------
// read the entries as uint64
//----------------------------------------------------------------------
uint64_t x ;
while (fscanf (f, "%"PRIu64"%"PRIu64"%"PRIu64"\n", &i, &j, &x) != EOF)
{
LAGRAPH_OK (GrB_Matrix_setElement (C, x, i-1, j-1)) ;
}
}
else
{
//----------------------------------------------------------------------
// read the entries as double, and typecast to the matrix type
//----------------------------------------------------------------------
double x ;
while (fscanf (f, "%"PRIu64"%"PRIu64"%lg\n", &i, &j, &x) != EOF)
{
LAGRAPH_OK (GrB_Matrix_setElement (C, x, i-1, j-1)) ;
}
}
//--------------------------------------------------------------------------
// finalize the matrix and return the result
//--------------------------------------------------------------------------
GrB_Index ignore ;
LAGRAPH_OK (GrB_Matrix_nvals (&ignore, C)) ;
(*Chandle) = C ;
return (GrB_SUCCESS) ;
}
|
rupello/ClockTHREEjr | arduino/libraries/ClockTHREE/examples/ClockTHREEjr/hebrew_v1.h | <reponame>rupello/ClockTHREEjr<filename>arduino/libraries/ClockTHREE/examples/ClockTHREEjr/hebrew_v1.h
/*
* ClockTHREEjr faceplate file.
* Autogenerated from Hebrew_v1.wtf
*
* Author:
* Licence:
* Description:
*
*
*/
static uint8_t WORDS[] PROGMEM = {
48, // # words
4, 5, 4, 10, 6, 5, 11, 5, 1, 7, 5, 1, // words
15, 6, 1, 8, 5, 3, 0, 6, 4, 4, 6, 1, // words
5, 6, 5, 0, 5, 5, 12, 5, 4, 5, 4, 4, // words
1, 4, 4, 0, 4, 4, 5, 4, 4, 10, 4, 6, // words
5, 4, 4, 10, 4, 6, 0, 3, 4, 5, 2, 3, // words
8, 2, 4, 11, 2, 4, 11, 3, 4, 8, 3, 3, // words
7, 3, 2, 5, 3, 3, 4, 1, 5, 1, 1, 3, // words
1, 2, 3, 0, 2, 4, 5, 2, 3, 0, 2, 4, // words
8, 2, 4, 9, 1, 2, 12, 1, 4, 6, 0, 3, // words
2, 0, 3, 1, 0, 4, 6, 0, 3, 11, 0, 5, // words
6, 0, 4, 11, 0, 5, 0, 0, 0, 0, 0, 0, // words
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // words
};
static uint8_t DISPLAYS[] PROGMEM = {
6, // number of bytes per state
// ב
// בוקר
// אחר
// ה
// ב
// ב
// צהרים
// בערב
//
//
//
//
// ועשרים
// וחמש
// עשרה
// ועשר
// וחמש
// דקות
// בלילה
// לפנות
//
//
//
//
// חמש
// ארבע
// שלוש
// שתים
// אחת
// וחצי
// ועשרים
// וחמש
//
//
//
//
// עשרה
// אחת
// עשרה
// עשר
// תשע
// שמונה
// שבע
// שש
//
//
//
//
// עשרים
// חמש
// עשרה
// עשר
// חמש
// דקות
// ל-
// שתים
//
//
//
//
//
//
//
//
//
//
// עשרים
// וחמש
//
//
//
//
0b00000000, 0b00000010, 0b00000000, 0b10000000, 0b00000001, 0b00000000,
0b00000000, 0b00001110, 0b00000000, 0b10000000, 0b00001001, 0b00000000,
0b00000000, 0b00010110, 0b00000000, 0b10000000, 0b00000001, 0b00000000,
0b00000000, 0b01100110, 0b00000000, 0b10000000, 0b00000001, 0b00000000,
0b00000000, 0b10000110, 0b00000000, 0b10000000, 0b00000001, 0b00000000,
0b00000000, 0b00000110, 0b00000011, 0b10000000, 0b00000001, 0b00000000,
0b00000000, 0b00000010, 0b00000100, 0b10000000, 0b00000001, 0b00000000,
0b00000000, 0b00000010, 0b00001000, 0b00000000, 0b00000110, 0b00000011,
0b00000000, 0b00000010, 0b00001000, 0b00000000, 0b10000110, 0b00000000,
0b00000000, 0b00000010, 0b00001000, 0b00000000, 0b01100110, 0b00000000,
0b00000000, 0b00000010, 0b00001000, 0b00000000, 0b00010110, 0b00000000,
0b00000000, 0b00000010, 0b00001000, 0b00000000, 0b00001110, 0b00000000,
0b00000000, 0b00000010, 0b00001000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00001110, 0b00001000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00010110, 0b00001000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b01100110, 0b00001000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b10000110, 0b00001000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000110, 0b00001011, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000010, 0b00001100, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000010, 0b00010000, 0b00000000, 0b00000110, 0b00000011,
0b00000000, 0b00000010, 0b00010000, 0b00000000, 0b10000110, 0b00000000,
0b00000000, 0b00000010, 0b00010000, 0b00000000, 0b01100110, 0b00000000,
0b00000000, 0b00000010, 0b00010000, 0b00000000, 0b00010110, 0b00000000,
0b00000000, 0b00000010, 0b00010000, 0b00000000, 0b00001110, 0b00000000,
0b00000000, 0b00000010, 0b00010000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00001110, 0b00010000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00010110, 0b00010000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b01100110, 0b00010000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b10000110, 0b00010000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000110, 0b00010011, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000010, 0b00010100, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00000001, 0b00100000, 0b00000000, 0b00000110, 0b00000011,
0b01000000, 0b00000001, 0b00100000, 0b00000000, 0b10000110, 0b00000000,
0b01000000, 0b00000001, 0b00100000, 0b00000000, 0b01100110, 0b00000000,
0b01000000, 0b00000001, 0b00100000, 0b00000000, 0b00010110, 0b00000000,
0b01000000, 0b00000001, 0b00100000, 0b00000000, 0b00001110, 0b00000000,
0b01000000, 0b00000001, 0b00100000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00001101, 0b00100000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00010101, 0b00100000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b01100101, 0b00100000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b10000101, 0b00100000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00000101, 0b00100011, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00000001, 0b00100100, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00000001, 0b01000000, 0b00000000, 0b00000110, 0b00000011,
0b01000000, 0b00000001, 0b01000000, 0b00000000, 0b10000110, 0b00000000,
0b01000000, 0b00000001, 0b01000000, 0b00000000, 0b01100110, 0b00000000,
0b01000000, 0b00000001, 0b01000000, 0b00000000, 0b00010110, 0b00000000,
0b01000000, 0b00000001, 0b01000000, 0b00000000, 0b00001110, 0b00000000,
0b01000000, 0b00000001, 0b01000000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00001101, 0b01000000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00010101, 0b01000000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b01100101, 0b01000000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b10000101, 0b01000000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00000101, 0b01000011, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00000001, 0b01000100, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00000001, 0b10000000, 0b00000000, 0b00000110, 0b00000011,
0b01000000, 0b00000001, 0b10000000, 0b00000000, 0b10000110, 0b00000000,
0b01000000, 0b00000001, 0b10000000, 0b00000000, 0b01100110, 0b00000000,
0b01000000, 0b00000001, 0b10000000, 0b00000000, 0b00010110, 0b00000000,
0b01000000, 0b00000001, 0b10000000, 0b00000000, 0b00001110, 0b00000000,
0b01000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00001101, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00010101, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b01100101, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b10000101, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00000101, 0b10000011, 0b00000000, 0b00000000, 0b00000000,
0b01000000, 0b00000001, 0b10000100, 0b00000000, 0b00000000, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000001, 0b00000110, 0b00000011,
0b11000000, 0b00000000, 0b00000000, 0b00000001, 0b10000110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000001, 0b01100110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000001, 0b00010110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000001, 0b00001110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000001, 0b00000000, 0b00000000,
0b11000000, 0b00001100, 0b00000000, 0b00000001, 0b00000000, 0b00000000,
0b11000000, 0b00010100, 0b00000000, 0b00000001, 0b00000000, 0b00000000,
0b11000000, 0b01100100, 0b00000000, 0b00000001, 0b00000000, 0b00000000,
0b11000000, 0b10000100, 0b00000000, 0b00000001, 0b00000000, 0b00000000,
0b11000000, 0b00000100, 0b00000011, 0b00000001, 0b00000000, 0b00000000,
0b11000000, 0b00000000, 0b00000100, 0b00000001, 0b00000000, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000010, 0b00000110, 0b00000011,
0b11000000, 0b00000000, 0b00000000, 0b00000010, 0b10000110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000010, 0b01100110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000010, 0b00010110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000010, 0b00001110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000010, 0b00000000, 0b00000000,
0b11000000, 0b00001100, 0b00000000, 0b00000010, 0b00000000, 0b00000000,
0b11000000, 0b00010100, 0b00000000, 0b00000010, 0b00000000, 0b00000000,
0b11000000, 0b01100100, 0b00000000, 0b00000010, 0b00000000, 0b00000000,
0b11000000, 0b10000100, 0b00000000, 0b00000010, 0b00000000, 0b00000000,
0b11000000, 0b00000100, 0b00000011, 0b00000010, 0b00000000, 0b00000000,
0b11000000, 0b00000000, 0b00000100, 0b00000010, 0b00000000, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000100, 0b00000110, 0b00000011,
0b11000000, 0b00000000, 0b00000000, 0b00000100, 0b10000110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000100, 0b01100110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000100, 0b00010110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000100, 0b00001110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00000100, 0b00000000, 0b00000000,
0b11000000, 0b00001100, 0b00000000, 0b00000100, 0b00000000, 0b00000000,
0b11000000, 0b00010100, 0b00000000, 0b00000100, 0b00000000, 0b00000000,
0b11000000, 0b01100100, 0b00000000, 0b00000100, 0b00000000, 0b00000000,
0b11000000, 0b10000100, 0b00000000, 0b00000100, 0b00000000, 0b00000000,
0b11000000, 0b00000100, 0b00000011, 0b00000100, 0b00000000, 0b00000000,
0b11000000, 0b00000000, 0b00000100, 0b00000100, 0b00000000, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00001000, 0b00000110, 0b00000011,
0b11000000, 0b00000000, 0b00000000, 0b00001000, 0b10000110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00001000, 0b01100110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00001000, 0b00010110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00001000, 0b00001110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00001000, 0b00000000, 0b00000000,
0b11000000, 0b00001100, 0b00000000, 0b00001000, 0b00000000, 0b00000000,
0b11000000, 0b00010100, 0b00000000, 0b00001000, 0b00000000, 0b00000000,
0b11000000, 0b01100100, 0b00000000, 0b00001000, 0b00000000, 0b00000000,
0b11000000, 0b10000100, 0b00000000, 0b00001000, 0b00000000, 0b00000000,
0b11000000, 0b00000100, 0b00000011, 0b00001000, 0b00000000, 0b00000000,
0b11000000, 0b00000000, 0b00000100, 0b00001000, 0b00000000, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00010000, 0b00000110, 0b00000011,
0b11000000, 0b00000000, 0b00000000, 0b00010000, 0b10000110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00010000, 0b01100110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00010000, 0b00010110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00010000, 0b00001110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b00010000, 0b00000000, 0b00000000,
0b11000000, 0b00001100, 0b00000000, 0b00010000, 0b00000000, 0b00000000,
0b11000000, 0b00010100, 0b00000000, 0b00010000, 0b00000000, 0b00000000,
0b11000000, 0b01100100, 0b00000000, 0b00010000, 0b00000000, 0b00000000,
0b11000000, 0b10000100, 0b00000000, 0b00010000, 0b00000000, 0b00000000,
0b11000000, 0b00000100, 0b00000011, 0b00010000, 0b00000000, 0b00000000,
0b11000000, 0b00000000, 0b00000100, 0b00010000, 0b00000000, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b01100000, 0b00000110, 0b00000011,
0b11000000, 0b00000000, 0b00000000, 0b01100000, 0b10000110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b01100000, 0b01100110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b01100000, 0b00010110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b01100000, 0b00001110, 0b00000000,
0b11000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
0b11000000, 0b00001100, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
0b11000000, 0b00010100, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
0b11000000, 0b01100100, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
0b11000000, 0b10000100, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
0b11000000, 0b00000100, 0b00000011, 0b01100000, 0b00000000, 0b00000000,
0b11000000, 0b00000000, 0b00000100, 0b01100000, 0b00000000, 0b00000000,
0b00000110, 0b00000000, 0b00000000, 0b10000000, 0b00000111, 0b00000011,
0b00000110, 0b00000000, 0b00000000, 0b10000000, 0b10000111, 0b00000000,
0b00000110, 0b00000000, 0b00000000, 0b10000000, 0b01100111, 0b00000000,
0b00000110, 0b00000000, 0b00000000, 0b10000000, 0b00010111, 0b00000000,
0b00000110, 0b00000000, 0b00000000, 0b10000000, 0b00001111, 0b00000000,
0b00000110, 0b00000000, 0b00000000, 0b10000000, 0b00000001, 0b00000000,
0b00001010, 0b00001100, 0b00000000, 0b10000000, 0b00000001, 0b00000000,
0b00001010, 0b00010100, 0b00000000, 0b10000000, 0b00000001, 0b00000000,
0b00001010, 0b01100100, 0b00000000, 0b10000000, 0b00000001, 0b00000000,
0b00001010, 0b10000100, 0b00000000, 0b10000000, 0b00000001, 0b00000000,
0b00001010, 0b00000100, 0b00000011, 0b10000000, 0b00000001, 0b00000000,
0b00000110, 0b00000000, 0b00000100, 0b10000000, 0b00000001, 0b00000000,
0b00000110, 0b00000000, 0b00001000, 0b00000000, 0b00000110, 0b00000011,
0b00000110, 0b00000000, 0b00001000, 0b00000000, 0b10000110, 0b00000000,
0b00000110, 0b00000000, 0b00001000, 0b00000000, 0b01100110, 0b00000000,
0b00000110, 0b00000000, 0b00001000, 0b00000000, 0b00010110, 0b00000000,
0b00000110, 0b00000000, 0b00001000, 0b00000000, 0b00001110, 0b00000000,
0b00000110, 0b00000000, 0b00001000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b00001100, 0b00001000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b00010100, 0b00001000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b01100100, 0b00001000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b10000100, 0b00001000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b00000100, 0b00001011, 0b00000000, 0b00000000, 0b00000000,
0b00000110, 0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000,
0b00000110, 0b00000000, 0b00010000, 0b00000000, 0b00000110, 0b00000011,
0b00000110, 0b00000000, 0b00010000, 0b00000000, 0b10000110, 0b00000000,
0b00000110, 0b00000000, 0b00010000, 0b00000000, 0b01100110, 0b00000000,
0b00000110, 0b00000000, 0b00010000, 0b00000000, 0b00010110, 0b00000000,
0b00000110, 0b00000000, 0b00010000, 0b00000000, 0b00001110, 0b00000000,
0b00000110, 0b00000000, 0b00010000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b00001100, 0b00010000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b00010100, 0b00010000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b01100100, 0b00010000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b10000100, 0b00010000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b00000100, 0b00010011, 0b00000000, 0b00000000, 0b00000000,
0b00000110, 0b00000000, 0b00010100, 0b00000000, 0b00000000, 0b00000000,
0b00000110, 0b00000000, 0b00100000, 0b00000000, 0b00000110, 0b00000011,
0b00000110, 0b00000000, 0b00100000, 0b00000000, 0b10000110, 0b00000000,
0b00000110, 0b00000000, 0b00100000, 0b00000000, 0b01100110, 0b00000000,
0b00000110, 0b00000000, 0b00100000, 0b00000000, 0b00010110, 0b00000000,
0b00000110, 0b00000000, 0b00100000, 0b00000000, 0b00001110, 0b00000000,
0b00000110, 0b00000000, 0b00100000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b00001100, 0b00100000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b00010100, 0b00100000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b01100100, 0b00100000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b10000100, 0b00100000, 0b00000000, 0b00000000, 0b00000000,
0b00001010, 0b00000100, 0b00100011, 0b00000000, 0b00000000, 0b00000000,
0b00000110, 0b00000000, 0b00100100, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b00000000, 0b01000000, 0b00000000, 0b00000110, 0b00000011,
0b00110010, 0b00000000, 0b01000000, 0b00000000, 0b10000110, 0b00000000,
0b00110010, 0b00000000, 0b01000000, 0b00000000, 0b01100110, 0b00000000,
0b00110010, 0b00000000, 0b01000000, 0b00000000, 0b00010110, 0b00000000,
0b00110010, 0b00000000, 0b01000000, 0b00000000, 0b00001110, 0b00000000,
0b00110010, 0b00000000, 0b01000000, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b00001100, 0b01000000, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b00010100, 0b01000000, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b01100100, 0b01000000, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b10000100, 0b01000000, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b00000100, 0b01000011, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b00000000, 0b01000100, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b00000000, 0b10000000, 0b00000000, 0b00000110, 0b00000011,
0b00110010, 0b00000000, 0b10000000, 0b00000000, 0b10000110, 0b00000000,
0b00110010, 0b00000000, 0b10000000, 0b00000000, 0b01100110, 0b00000000,
0b00110010, 0b00000000, 0b10000000, 0b00000000, 0b00010110, 0b00000000,
0b00110010, 0b00000000, 0b10000000, 0b00000000, 0b00001110, 0b00000000,
0b00110010, 0b00000000, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b00001100, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b00010100, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b01100100, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b10000100, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b00000100, 0b10000011, 0b00000000, 0b00000000, 0b00000000,
0b00110010, 0b00000000, 0b10000100, 0b00000000, 0b00000000, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000001, 0b00000110, 0b00000011,
0b00000001, 0b00000000, 0b00000000, 0b00000001, 0b10000110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000001, 0b01100110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000001, 0b00010110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000001, 0b00001110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000001, 0b00000000, 0b00000000,
0b00000001, 0b00001100, 0b00000000, 0b00000001, 0b00000000, 0b00000000,
0b00000001, 0b00010100, 0b00000000, 0b00000001, 0b00000000, 0b00000000,
0b00000001, 0b01100100, 0b00000000, 0b00000001, 0b00000000, 0b00000000,
0b00000001, 0b10000100, 0b00000000, 0b00000001, 0b00000000, 0b00000000,
0b00000001, 0b00000100, 0b00000011, 0b00000001, 0b00000000, 0b00000000,
0b00000001, 0b00000000, 0b00000100, 0b00000001, 0b00000000, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000010, 0b00000110, 0b00000011,
0b00000001, 0b00000000, 0b00000000, 0b00000010, 0b10000110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000010, 0b01100110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000010, 0b00010110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000010, 0b00001110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000010, 0b00000000, 0b00000000,
0b00000001, 0b00001100, 0b00000000, 0b00000010, 0b00000000, 0b00000000,
0b00000001, 0b00010100, 0b00000000, 0b00000010, 0b00000000, 0b00000000,
0b00000001, 0b01100100, 0b00000000, 0b00000010, 0b00000000, 0b00000000,
0b00000001, 0b10000100, 0b00000000, 0b00000010, 0b00000000, 0b00000000,
0b00000001, 0b00000100, 0b00000011, 0b00000010, 0b00000000, 0b00000000,
0b00000001, 0b00000000, 0b00000100, 0b00000010, 0b00000000, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000100, 0b00000110, 0b00000011,
0b00000001, 0b00000000, 0b00000000, 0b00000100, 0b10000110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000100, 0b01100110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000100, 0b00010110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000100, 0b00001110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00000100, 0b00000000, 0b00000000,
0b00000001, 0b00001100, 0b00000000, 0b00000100, 0b00000000, 0b00000000,
0b00000001, 0b00010100, 0b00000000, 0b00000100, 0b00000000, 0b00000000,
0b00000001, 0b01100100, 0b00000000, 0b00000100, 0b00000000, 0b00000000,
0b00000001, 0b10000100, 0b00000000, 0b00000100, 0b00000000, 0b00000000,
0b00000001, 0b00000100, 0b00000011, 0b00000100, 0b00000000, 0b00000000,
0b00000001, 0b00000000, 0b00000100, 0b00000100, 0b00000000, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00001000, 0b00000110, 0b00000011,
0b00000001, 0b00000000, 0b00000000, 0b00001000, 0b10000110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00001000, 0b01100110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00001000, 0b00010110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00001000, 0b00001110, 0b00000000,
0b00000001, 0b00000000, 0b00000000, 0b00001000, 0b00000000, 0b00000000,
0b00000001, 0b00001100, 0b00000000, 0b00001000, 0b00000000, 0b00000000,
0b00000001, 0b00010100, 0b00000000, 0b00001000, 0b00000000, 0b00000000,
0b00000001, 0b01100100, 0b00000000, 0b00001000, 0b00000000, 0b00000000,
0b00000001, 0b10000100, 0b00000000, 0b00001000, 0b00000000, 0b00000000,
0b00000001, 0b00000100, 0b00000011, 0b00001000, 0b00000000, 0b00000000,
0b00000001, 0b00000000, 0b00000100, 0b00001000, 0b00000000, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b00010000, 0b00000110, 0b00000011,
0b00000000, 0b00000010, 0b00000000, 0b00010000, 0b10000110, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b00010000, 0b01100110, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b00010000, 0b00010110, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b00010000, 0b00001110, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b00010000, 0b00000000, 0b00000000,
0b00000000, 0b00001110, 0b00000000, 0b00010000, 0b00000000, 0b00000000,
0b00000000, 0b00010110, 0b00000000, 0b00010000, 0b00000000, 0b00000000,
0b00000000, 0b01100110, 0b00000000, 0b00010000, 0b00000000, 0b00000000,
0b00000000, 0b10000110, 0b00000000, 0b00010000, 0b00000000, 0b00000000,
0b00000000, 0b00000110, 0b00000011, 0b00010000, 0b00000000, 0b00000000,
0b00000000, 0b00000010, 0b00000100, 0b00010000, 0b00000000, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b01100000, 0b00000110, 0b00000011,
0b00000000, 0b00000010, 0b00000000, 0b01100000, 0b10000110, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b01100000, 0b01100110, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b01100000, 0b00010110, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b01100000, 0b00001110, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
0b00000000, 0b00001110, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
0b00000000, 0b00010110, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
0b00000000, 0b01100110, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
0b00000000, 0b10000110, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
0b00000000, 0b00000110, 0b00000011, 0b01100000, 0b00000000, 0b00000000,
0b00000000, 0b00000010, 0b00000100, 0b01100000, 0b00000000, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b10000000, 0b00000111, 0b00000011,
0b00000000, 0b00000010, 0b00000000, 0b10000000, 0b10000111, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b10000000, 0b01100111, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b10000000, 0b00010111, 0b00000000,
0b00000000, 0b00000010, 0b00000000, 0b10100000, 0b00001111, 0b00000000,
};
// Minutes hack constants
static uint32_t MINUTE_LEDS[] PROGMEM = {
// n_minute_state, n_minute_led, led0, led2, led3, led4...
20, 16,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
};
static uint32_t MINUTES_HACK[] PROGMEM = {
0b0000000000000000,
0b1000000000000000,
0b1100000000000000,
0b1110000000000000,
0b1111000000000000,
0b0111100000000000,
0b0011110000000000,
0b0001111000000000,
0b0000111100000000,
0b0000011110000000,
0b0000001111000000,
0b0000000111100000,
0b0000000011110000,
0b0000000001111000,
0b0000000000111100,
0b0000000000011110,
0b0000000000001111,
0b0000000000000111,
0b0000000000000011,
0b0000000000000001,
};
|
rupello/ClockTHREEjr | arduino/libraries/ClockTHREE/examples/ClockTHREEjr/english_v0.h | /*
* ClockTHREEjr faceplate file.
* Autogenerated from English_v0.csv
*
* Author: FlorinC
* Licence: CC BY SA
* Description:
* Faceplate from C3jr v1 English
*
*/
static uint8_t WORDS[] PROGMEM = {
32, // # words
1, 0, 2, 4, 0, 2, 1, 2, 4, 7, 0, 3, // words
0, 1, 7, 7, 1, 6, 1, 2, 4, 10, 0, 4, // words
0, 3, 4, 3, 3, 2, 8, 3, 3, 6, 3, 3, // words
0, 4, 5, 0, 5, 4, 4, 5, 4, 10, 4, 3, // words
8, 5, 5, 10, 3, 5, 12, 5, 4, 13, 4, 3, // words
4, 4, 6, 0, 6, 6, 7, 6, 6, 14, 6, 2, // words
0, 7, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, // words
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // words
};
static uint8_t DISPLAYS[] PROGMEM = {
4, // number of bytes per state
// q
// tu ote
// wa f t cwl es
// hfer f ifh p lee nie
// aintti svorto a olvtigv
// lvteevii ieuewnts acveenhe p
// feyrnest x reoeot mkennetn m
0b00000011, 0b00000001, 0b11100000, 0b00000000,
0b00000111, 0b00000001, 0b10100000, 0b00000000,
0b00001011, 0b00000001, 0b10100000, 0b00000000,
0b00010011, 0b00000001, 0b10100000, 0b00000000,
0b00100011, 0b00000001, 0b10100000, 0b00000000,
0b01100011, 0b00000001, 0b10100000, 0b00000000,
0b10000011, 0b00000001, 0b10100000, 0b00000000,
0b01100011, 0b00000110, 0b10000000, 0b00000000,
0b00100011, 0b00000110, 0b10000000, 0b00000000,
0b00010011, 0b00000110, 0b10000000, 0b00000000,
0b00001011, 0b00000110, 0b10000000, 0b00000000,
0b00000111, 0b00000110, 0b10000000, 0b00000000,
0b00000011, 0b00000100, 0b11000000, 0b00000000,
0b00000111, 0b00000101, 0b10000000, 0b00000000,
0b00001011, 0b00000101, 0b10000000, 0b00000000,
0b00010011, 0b00000101, 0b10000000, 0b00000000,
0b00100011, 0b00000101, 0b10000000, 0b00000000,
0b01100011, 0b00000101, 0b10000000, 0b00000000,
0b10000011, 0b00000101, 0b10000000, 0b00000000,
0b01100011, 0b00001010, 0b10000000, 0b00000000,
0b00100011, 0b00001010, 0b10000000, 0b00000000,
0b00010011, 0b00001010, 0b10000000, 0b00000000,
0b00001011, 0b00001010, 0b10000000, 0b00000000,
0b00000111, 0b00001000, 0b10000000, 0b00000000,
0b00000011, 0b00001000, 0b11000000, 0b00000000,
0b00000111, 0b00001001, 0b10000000, 0b00000000,
0b00001011, 0b00001001, 0b10000000, 0b00000000,
0b00010011, 0b00001001, 0b10000000, 0b00000000,
0b00100011, 0b00001001, 0b10000000, 0b00000000,
0b01100011, 0b00001001, 0b10000000, 0b00000000,
0b10000011, 0b00001001, 0b10000000, 0b00000000,
0b01100011, 0b00010010, 0b10000000, 0b00000000,
0b00100011, 0b00010010, 0b10000000, 0b00000000,
0b00010011, 0b00010010, 0b10000000, 0b00000000,
0b00001011, 0b00010010, 0b10000000, 0b00000000,
0b00000111, 0b00010010, 0b10000000, 0b00000000,
0b00000011, 0b00010000, 0b11000000, 0b00000000,
0b00000111, 0b00010001, 0b10000000, 0b00000000,
0b00001011, 0b00010001, 0b10000000, 0b00000000,
0b00010011, 0b00010001, 0b10000000, 0b00000000,
0b00100011, 0b00010001, 0b10000000, 0b00000000,
0b01100011, 0b00010001, 0b10000000, 0b00000000,
0b10000011, 0b00010001, 0b10000000, 0b00000000,
0b01100011, 0b00100010, 0b10000000, 0b00000000,
0b00100011, 0b00100010, 0b10000000, 0b00000000,
0b00010011, 0b00100010, 0b10000000, 0b00000000,
0b00001011, 0b00100010, 0b10000000, 0b00000000,
0b00000111, 0b00100010, 0b10000000, 0b00000000,
0b00000011, 0b00100000, 0b11000000, 0b00000000,
0b00000111, 0b00100001, 0b10000000, 0b00000000,
0b00001011, 0b00100001, 0b10000000, 0b00000000,
0b00010011, 0b00100001, 0b10000000, 0b00000000,
0b00100011, 0b00100001, 0b10000000, 0b00000000,
0b01100011, 0b00100001, 0b10000000, 0b00000000,
0b10000011, 0b00100001, 0b10000000, 0b00000000,
0b01100011, 0b01000010, 0b10000000, 0b00000000,
0b00100011, 0b01000010, 0b10000000, 0b00000000,
0b00010011, 0b01000010, 0b10000000, 0b00000000,
0b00001011, 0b01000010, 0b10000000, 0b00000000,
0b00000111, 0b01000010, 0b10000000, 0b00000000,
0b00000011, 0b01000000, 0b11000000, 0b00000000,
0b00000111, 0b01000001, 0b10000000, 0b00000000,
0b00001011, 0b01000001, 0b10000000, 0b00000000,
0b00010011, 0b01000001, 0b10000000, 0b00000000,
0b00100011, 0b01000001, 0b10000000, 0b00000000,
0b01100011, 0b01000001, 0b10000000, 0b00000000,
0b10000011, 0b01000001, 0b10000000, 0b00000000,
0b01100011, 0b10000010, 0b10000000, 0b00000000,
0b00100011, 0b10000010, 0b10000000, 0b00000000,
0b00010011, 0b10000010, 0b10000000, 0b00000000,
0b00001011, 0b10000010, 0b10000000, 0b00000000,
0b00000111, 0b10000010, 0b10000000, 0b00000000,
0b00000011, 0b10000000, 0b11000000, 0b00000000,
0b00000111, 0b10000001, 0b10000000, 0b00000000,
0b00001011, 0b10000001, 0b10000000, 0b00000000,
0b00010011, 0b10000001, 0b10000000, 0b00000000,
0b00100011, 0b10000001, 0b10000000, 0b00000000,
0b01100011, 0b10000001, 0b10000000, 0b00000000,
0b10000011, 0b10000001, 0b10000000, 0b00000000,
0b01100011, 0b00000010, 0b10000001, 0b00000000,
0b00100011, 0b00000010, 0b10000001, 0b00000000,
0b00010011, 0b00000010, 0b10000001, 0b00000000,
0b00001011, 0b00000010, 0b10000001, 0b00000000,
0b00000111, 0b00000010, 0b10000001, 0b00000000,
0b00000011, 0b00000000, 0b11000001, 0b00000000,
0b00000111, 0b00000001, 0b10000001, 0b00000000,
0b00001011, 0b00000001, 0b10000001, 0b00000000,
0b00010011, 0b00000001, 0b10000001, 0b00000000,
0b00100011, 0b00000001, 0b10000001, 0b00000000,
0b01100011, 0b00000001, 0b10000001, 0b00000000,
0b10000011, 0b00000001, 0b10000001, 0b00000000,
0b01100011, 0b00000010, 0b10000010, 0b00000000,
0b00100011, 0b00000010, 0b10000010, 0b00000000,
0b00010011, 0b00000010, 0b10000010, 0b00000000,
0b00001011, 0b00000010, 0b10000010, 0b00000000,
0b00000111, 0b00000010, 0b10000010, 0b00000000,
0b00000011, 0b00000000, 0b11000010, 0b00000000,
0b00000111, 0b00000001, 0b10000010, 0b00000000,
0b00001011, 0b00000001, 0b10000010, 0b00000000,
0b00010011, 0b00000001, 0b10000010, 0b00000000,
0b00100011, 0b00000001, 0b10000010, 0b00000000,
0b01100011, 0b00000001, 0b10000010, 0b00000000,
0b10000011, 0b00000001, 0b10000010, 0b00000000,
0b01100011, 0b00000010, 0b10000100, 0b00000000,
0b00100011, 0b00000010, 0b10000100, 0b00000000,
0b00010011, 0b00000010, 0b10000100, 0b00000000,
0b00001011, 0b00000010, 0b10000100, 0b00000000,
0b00000111, 0b00000010, 0b10000100, 0b00000000,
0b00000011, 0b00000000, 0b11000100, 0b00000000,
0b00000111, 0b00000001, 0b10000100, 0b00000000,
0b00001011, 0b00000001, 0b10000100, 0b00000000,
0b00010011, 0b00000001, 0b10000100, 0b00000000,
0b00100011, 0b00000001, 0b10000100, 0b00000000,
0b01100011, 0b00000001, 0b10000100, 0b00000000,
0b10000011, 0b00000001, 0b10000100, 0b00000000,
0b01100011, 0b00000010, 0b10001000, 0b00000000,
0b00100011, 0b00000010, 0b10001000, 0b00000000,
0b00010011, 0b00000010, 0b10001000, 0b00000000,
0b00001011, 0b00000010, 0b10001000, 0b00000000,
0b00000111, 0b00000010, 0b10001000, 0b00000000,
0b00000011, 0b00000000, 0b11001000, 0b00000000,
0b00000111, 0b00000001, 0b10001000, 0b00000000,
0b00001011, 0b00000001, 0b10001000, 0b00000000,
0b00010011, 0b00000001, 0b10001000, 0b00000000,
0b00100011, 0b00000001, 0b10001000, 0b00000000,
0b01100011, 0b00000001, 0b10001000, 0b00000000,
0b10000011, 0b00000001, 0b10001000, 0b00000000,
0b01100011, 0b00000010, 0b10010000, 0b00000000,
0b00100011, 0b00000010, 0b10010000, 0b00000000,
0b00010011, 0b00000010, 0b10010000, 0b00000000,
0b00001011, 0b00000010, 0b10010000, 0b00000000,
0b00000111, 0b00000010, 0b10010000, 0b00000000,
0b00000011, 0b00000000, 0b11010000, 0b00000000,
0b00000111, 0b00000001, 0b10010000, 0b00000000,
0b00001011, 0b00000001, 0b10010000, 0b00000000,
0b00010011, 0b00000001, 0b10010000, 0b00000000,
0b00100011, 0b00000001, 0b10010000, 0b00000000,
0b01100011, 0b00000001, 0b10010000, 0b00000000,
0b10000011, 0b00000001, 0b10010000, 0b00000000,
0b01100011, 0b00000010, 0b10100000, 0b00000000,
0b00100011, 0b00000010, 0b10100000, 0b00000000,
0b00010011, 0b00000010, 0b10100000, 0b00000000,
0b00001011, 0b00000010, 0b10100000, 0b00000000,
0b00000111, 0b00000010, 0b10100000, 0b00000000,
0b00000011, 0b00000000, 0b01100000, 0b00000001,
0b00000111, 0b00000001, 0b00100000, 0b00000001,
0b00001011, 0b00000001, 0b00100000, 0b00000001,
0b00010011, 0b00000001, 0b00100000, 0b00000001,
0b00100011, 0b00000001, 0b00100000, 0b00000001,
0b01100011, 0b00000001, 0b00100000, 0b00000001,
0b10000011, 0b00000001, 0b00100000, 0b00000001,
0b01100011, 0b00000110, 0b00000000, 0b00000001,
0b00100011, 0b00000110, 0b00000000, 0b00000001,
0b00010011, 0b00000110, 0b00000000, 0b00000001,
0b00001011, 0b00000110, 0b00000000, 0b00000001,
0b00000111, 0b00000110, 0b00000000, 0b00000001,
0b00000011, 0b00000100, 0b01000000, 0b00000001,
0b00000111, 0b00000101, 0b00000000, 0b00000001,
0b00001011, 0b00000101, 0b00000000, 0b00000001,
0b00010011, 0b00000101, 0b00000000, 0b00000001,
0b00100011, 0b00000101, 0b00000000, 0b00000001,
0b01100011, 0b00000101, 0b00000000, 0b00000001,
0b10000011, 0b00000101, 0b00000000, 0b00000001,
0b01100011, 0b00001010, 0b00000000, 0b00000001,
0b00100011, 0b00001010, 0b00000000, 0b00000001,
0b00010011, 0b00001010, 0b00000000, 0b00000001,
0b00001011, 0b00001010, 0b00000000, 0b00000001,
0b00000111, 0b00001010, 0b00000000, 0b00000001,
0b00000011, 0b00001000, 0b01000000, 0b00000001,
0b00000111, 0b00001001, 0b00000000, 0b00000001,
0b00001011, 0b00001001, 0b00000000, 0b00000001,
0b00010011, 0b00001001, 0b00000000, 0b00000001,
0b00100011, 0b00001001, 0b00000000, 0b00000001,
0b01100011, 0b00001001, 0b00000000, 0b00000001,
0b10000011, 0b00001001, 0b00000000, 0b00000001,
0b01100011, 0b00010010, 0b00000000, 0b00000001,
0b00100011, 0b00010010, 0b00000000, 0b00000001,
0b00010011, 0b00010010, 0b00000000, 0b00000001,
0b00001011, 0b00010010, 0b00000000, 0b00000001,
0b00000111, 0b00010010, 0b00000000, 0b00000001,
0b00000011, 0b00010000, 0b01000000, 0b00000001,
0b00000111, 0b00010001, 0b00000000, 0b00000001,
0b00001011, 0b00010001, 0b00000000, 0b00000001,
0b00010011, 0b00010001, 0b00000000, 0b00000001,
0b00100011, 0b00010001, 0b00000000, 0b00000001,
0b01100011, 0b00010001, 0b00000000, 0b00000001,
0b10000011, 0b00010001, 0b00000000, 0b00000001,
0b01100011, 0b00100010, 0b00000000, 0b00000001,
0b00100011, 0b00100010, 0b00000000, 0b00000001,
0b00010011, 0b00100010, 0b00000000, 0b00000001,
0b00001011, 0b00100010, 0b00000000, 0b00000001,
0b00000111, 0b00100010, 0b00000000, 0b00000001,
0b00000011, 0b00100000, 0b01000000, 0b00000001,
0b00000111, 0b00100001, 0b00000000, 0b00000001,
0b00001011, 0b00100001, 0b00000000, 0b00000001,
0b00010011, 0b00100001, 0b00000000, 0b00000001,
0b00100011, 0b00100001, 0b00000000, 0b00000001,
0b01100011, 0b00100001, 0b00000000, 0b00000001,
0b10000011, 0b00100001, 0b00000000, 0b00000001,
0b01100011, 0b01000010, 0b00000000, 0b00000001,
0b00100011, 0b01000010, 0b00000000, 0b00000001,
0b00010011, 0b01000010, 0b00000000, 0b00000001,
0b00001011, 0b01000010, 0b00000000, 0b00000001,
0b00000111, 0b01000010, 0b00000000, 0b00000001,
0b00000011, 0b01000000, 0b01000000, 0b00000001,
0b00000111, 0b01000001, 0b00000000, 0b00000001,
0b00001011, 0b01000001, 0b00000000, 0b00000001,
0b00010011, 0b01000001, 0b00000000, 0b00000001,
0b00100011, 0b01000001, 0b00000000, 0b00000001,
0b01100011, 0b01000001, 0b00000000, 0b00000001,
0b10000011, 0b01000001, 0b00000000, 0b00000001,
0b01100011, 0b10000010, 0b00000000, 0b00000001,
0b00100011, 0b10000010, 0b00000000, 0b00000001,
0b00010011, 0b10000010, 0b00000000, 0b00000001,
0b00001011, 0b10000010, 0b00000000, 0b00000001,
0b00000111, 0b10000010, 0b00000000, 0b00000001,
0b00000011, 0b10000000, 0b01000000, 0b00000001,
0b00000111, 0b10000001, 0b00000000, 0b00000001,
0b00001011, 0b10000001, 0b00000000, 0b00000001,
0b00010011, 0b10000001, 0b00000000, 0b00000001,
0b00100011, 0b10000001, 0b00000000, 0b00000001,
0b01100011, 0b10000001, 0b00000000, 0b00000001,
0b10000011, 0b10000001, 0b00000000, 0b00000001,
0b01100011, 0b00000010, 0b00000001, 0b00000001,
0b00100011, 0b00000010, 0b00000001, 0b00000001,
0b00010011, 0b00000010, 0b00000001, 0b00000001,
0b00001011, 0b00000010, 0b00000001, 0b00000001,
0b00000111, 0b00000010, 0b00000001, 0b00000001,
0b00000011, 0b00000000, 0b01000001, 0b00000001,
0b00000111, 0b00000001, 0b00000001, 0b00000001,
0b00001011, 0b00000001, 0b00000001, 0b00000001,
0b00010011, 0b00000001, 0b00000001, 0b00000001,
0b00100011, 0b00000001, 0b00000001, 0b00000001,
0b01100011, 0b00000001, 0b00000001, 0b00000001,
0b10000011, 0b00000001, 0b00000001, 0b00000001,
0b01100011, 0b00000010, 0b00000010, 0b00000001,
0b00100011, 0b00000010, 0b00000010, 0b00000001,
0b00010011, 0b00000010, 0b00000010, 0b00000001,
0b00001011, 0b00000010, 0b00000010, 0b00000001,
0b00000111, 0b00000010, 0b00000010, 0b00000001,
0b00000011, 0b00000000, 0b01000010, 0b00000001,
0b00000111, 0b00000001, 0b00000010, 0b00000001,
0b00001011, 0b00000001, 0b00000010, 0b00000001,
0b00010011, 0b00000001, 0b00000010, 0b00000001,
0b00100011, 0b00000001, 0b00000010, 0b00000001,
0b01100011, 0b00000001, 0b00000010, 0b00000001,
0b10000011, 0b00000001, 0b00000010, 0b00000001,
0b01100011, 0b00000010, 0b00000100, 0b00000001,
0b00100011, 0b00000010, 0b00000100, 0b00000001,
0b00010011, 0b00000010, 0b00000100, 0b00000001,
0b00001011, 0b00000010, 0b00000100, 0b00000001,
0b00000111, 0b00000010, 0b00000100, 0b00000001,
0b00000011, 0b00000000, 0b01000100, 0b00000001,
0b00000111, 0b00000001, 0b00000100, 0b00000001,
0b00001011, 0b00000001, 0b00000100, 0b00000001,
0b00010011, 0b00000001, 0b00000100, 0b00000001,
0b00100011, 0b00000001, 0b00000100, 0b00000001,
0b01100011, 0b00000001, 0b00000100, 0b00000001,
0b10000011, 0b00000001, 0b00000100, 0b00000001,
0b01100011, 0b00000010, 0b00001000, 0b00000001,
0b00100011, 0b00000010, 0b00001000, 0b00000001,
0b00010011, 0b00000010, 0b00001000, 0b00000001,
0b00001011, 0b00000010, 0b00001000, 0b00000001,
0b00000111, 0b00000010, 0b00001000, 0b00000001,
0b00000011, 0b00000000, 0b01001000, 0b00000001,
0b00000111, 0b00000001, 0b00001000, 0b00000001,
0b00001011, 0b00000001, 0b00001000, 0b00000001,
0b00010011, 0b00000001, 0b00001000, 0b00000001,
0b00100011, 0b00000001, 0b00001000, 0b00000001,
0b01100011, 0b00000001, 0b00001000, 0b00000001,
0b10000011, 0b00000001, 0b00001000, 0b00000001,
0b01100011, 0b00000010, 0b00010000, 0b00000001,
0b00100011, 0b00000010, 0b00010000, 0b00000001,
0b00010011, 0b00000010, 0b00010000, 0b00000001,
0b00001011, 0b00000010, 0b00010000, 0b00000001,
0b00000111, 0b00000010, 0b00010000, 0b00000001,
0b00000011, 0b00000000, 0b01010000, 0b00000001,
0b00000111, 0b00000001, 0b00010000, 0b00000001,
0b00001011, 0b00000001, 0b00010000, 0b00000001,
0b00010011, 0b00000001, 0b00010000, 0b00000001,
0b00100011, 0b00000001, 0b00010000, 0b00000001,
0b01100011, 0b00000001, 0b00010000, 0b00000001,
0b10000011, 0b00000001, 0b00010000, 0b00000001,
0b01100011, 0b00000010, 0b00100000, 0b00000001,
0b00100011, 0b00000010, 0b00100000, 0b00000001,
0b00010011, 0b00000010, 0b00100000, 0b00000001,
0b00001011, 0b00000010, 0b00100000, 0b00000001,
0b00000111, 0b00000010, 0b00100000, 0b00000001,
};
// Minutes hack constants
static uint32_t MINUTE_LEDS[] PROGMEM = {
// n_minute_state, n_minute_led, led0, led2, led3, led4...
5, 3,
0x0f, 0x1f, 0x2f,
};
static uint32_t MINUTES_HACK[] PROGMEM = {
0b000,
0b100,
0b010,
0b110,
0b111,
};
|
rupello/ClockTHREEjr | arduino/libraries/ClockTHREE/mem_font.h | #ifndef MEM_FONT_H
#define MEM_FONT_H
#include <avr/pgmspace.h>
const uint8_t N_CHAR = 128;
class MemFont{
public:
/*
Place character into output buffer out in selected color.
*/
void getChar(char letter, uint8_t color, uint32_t* out);
private:
};
#endif
|
rupello/ClockTHREEjr | arduino/libraries/ClockTHREE/examples/ClockTHREEjr/dutch_v1.h | <filename>arduino/libraries/ClockTHREE/examples/ClockTHREEjr/dutch_v1.h
/*
* ClockTHREEjr faceplate file.
* Autogenerated from Dutch_v1.wtf
*
* Author:
* Licence: CC BY SA
* Description:
*
*
*/
static uint8_t WORDS[] PROGMEM = {
32, // # words
0, 0, 3, 4, 0, 2, 7, 0, 4, 12, 0, 4, // words
0, 1, 5, 4, 1, 7, 12, 1, 4, 0, 2, 4, // words
5, 2, 4, 12, 2, 3, 10, 2, 4, 0, 3, 4, // words
4, 3, 4, 8, 3, 4, 12, 3, 3, 0, 4, 5, // words
9, 4, 4, 4, 4, 5, 12, 4, 4, 0, 5, 3, // words
3, 5, 6, 10, 5, 3, 14, 5, 2, 8, 7, 6, // words
0, 6, 8, 8, 6, 7, 2, 7, 6, 0, 0, 0, // words
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // words
};
static uint8_t DISPLAYS[] PROGMEM = {
4, // number of bytes per state
// o
// mc
// t n t aih
// wk z a w n vdt
// oviwtv e vvdt h c a tea ode
// vonaii h vziirwea h uaeigc nan
// eoirejie eejeieel t'ulleeh dgd
// rrgtnfst nsfreenf ssrffnnt sss
0b00000011, 0b00000000, 0b11110000, 0b00000000,
0b10000111, 0b00000000, 0b11010000, 0b00000000,
0b10001011, 0b00000000, 0b11010000, 0b00000000,
0b10010011, 0b00000000, 0b11010000, 0b00000000,
0b10100011, 0b00000000, 0b11010000, 0b00000000,
0b01000111, 0b00000011, 0b11000000, 0b00000000,
0b00000011, 0b00000011, 0b11000000, 0b00000000,
0b10000111, 0b00000011, 0b11000000, 0b00000000,
0b10001011, 0b00000011, 0b11000000, 0b00000000,
0b01010011, 0b00000010, 0b11000000, 0b00000000,
0b01001011, 0b00000010, 0b11000000, 0b00000000,
0b01000111, 0b00000010, 0b11000000, 0b00000000,
0b00000011, 0b00000010, 0b11100000, 0b00000000,
0b10000111, 0b00000010, 0b11000000, 0b00000000,
0b10001011, 0b00000010, 0b11000000, 0b00000000,
0b10010011, 0b00000010, 0b11000000, 0b00000000,
0b10100011, 0b00000010, 0b11000000, 0b00000000,
0b01000111, 0b00000101, 0b11000000, 0b00000000,
0b00000011, 0b00000101, 0b11000000, 0b00000000,
0b10000111, 0b00000101, 0b11000000, 0b00000000,
0b10001011, 0b00000101, 0b11000000, 0b00000000,
0b01010011, 0b00000100, 0b11000000, 0b00000000,
0b01001011, 0b00000100, 0b11000000, 0b00000000,
0b01000111, 0b00000100, 0b11000000, 0b00000000,
0b00000011, 0b00000100, 0b11100000, 0b00000000,
0b10000111, 0b00000100, 0b11000000, 0b00000000,
0b10001011, 0b00000100, 0b11000000, 0b00000000,
0b10010011, 0b00000100, 0b11000000, 0b00000000,
0b10100011, 0b00000100, 0b11000000, 0b00000000,
0b01000111, 0b00001001, 0b11000000, 0b00000000,
0b00000011, 0b00001001, 0b11000000, 0b00000000,
0b10000111, 0b00001001, 0b11000000, 0b00000000,
0b10001011, 0b00001001, 0b11000000, 0b00000000,
0b01010011, 0b00001000, 0b11000000, 0b00000000,
0b01001011, 0b00001000, 0b11000000, 0b00000000,
0b01000111, 0b00001000, 0b11000000, 0b00000000,
0b00000011, 0b00001000, 0b11100000, 0b00000000,
0b10000111, 0b00001000, 0b11000000, 0b00000000,
0b10001011, 0b00001000, 0b11000000, 0b00000000,
0b10010011, 0b00001000, 0b11000000, 0b00000000,
0b10100011, 0b00001000, 0b11000000, 0b00000000,
0b01000111, 0b00010001, 0b11000000, 0b00000000,
0b00000011, 0b00010001, 0b11000000, 0b00000000,
0b10000111, 0b00010001, 0b11000000, 0b00000000,
0b10001011, 0b00010001, 0b11000000, 0b00000000,
0b01010011, 0b00010000, 0b11000000, 0b00000000,
0b01001011, 0b00010000, 0b11000000, 0b00000000,
0b01000111, 0b00010000, 0b11000000, 0b00000000,
0b00000011, 0b00010000, 0b11100000, 0b00000000,
0b10000111, 0b00010000, 0b11000000, 0b00000000,
0b10001011, 0b00010000, 0b11000000, 0b00000000,
0b10010011, 0b00010000, 0b11000000, 0b00000000,
0b10100011, 0b00010000, 0b11000000, 0b00000000,
0b01000111, 0b00100001, 0b11000000, 0b00000000,
0b00000011, 0b00100001, 0b11000000, 0b00000000,
0b10000111, 0b00100001, 0b11000000, 0b00000000,
0b10001011, 0b00100001, 0b11000000, 0b00000000,
0b01010011, 0b00100000, 0b11000000, 0b00000000,
0b01001011, 0b00100000, 0b11000000, 0b00000000,
0b01000111, 0b00100000, 0b11000000, 0b00000000,
0b00000011, 0b00100000, 0b11100000, 0b00000000,
0b10000111, 0b00100000, 0b11000000, 0b00000000,
0b10001011, 0b00100000, 0b11000000, 0b00000000,
0b10010011, 0b00100000, 0b11000000, 0b00000000,
0b10100011, 0b00100000, 0b11000000, 0b00000000,
0b01000111, 0b01000001, 0b11000000, 0b00000000,
0b00000011, 0b01000001, 0b11000000, 0b00000000,
0b10000111, 0b01000001, 0b11000000, 0b00000000,
0b10001011, 0b01000001, 0b11000000, 0b00000000,
0b01010011, 0b01000000, 0b11000000, 0b00000000,
0b01001011, 0b01000000, 0b11000000, 0b00000000,
0b01000111, 0b01000000, 0b11000000, 0b00000000,
0b00000011, 0b01000000, 0b01100000, 0b00000001,
0b10000111, 0b01000000, 0b01000000, 0b00000001,
0b10001011, 0b01000000, 0b01000000, 0b00000001,
0b10010011, 0b01000000, 0b01000000, 0b00000001,
0b10100011, 0b01000000, 0b01000000, 0b00000001,
0b01000111, 0b10000001, 0b01000000, 0b00000001,
0b00000011, 0b10000001, 0b01000000, 0b00000001,
0b10000111, 0b10000001, 0b01000000, 0b00000001,
0b10001011, 0b10000001, 0b01000000, 0b00000001,
0b01010011, 0b10000000, 0b01000000, 0b00000001,
0b01001011, 0b10000000, 0b01000000, 0b00000001,
0b01000111, 0b10000000, 0b01000000, 0b00000001,
0b00000011, 0b10000000, 0b01100000, 0b00000001,
0b10000111, 0b10000000, 0b01000000, 0b00000001,
0b10001011, 0b10000000, 0b01000000, 0b00000001,
0b10010011, 0b10000000, 0b01000000, 0b00000001,
0b10100011, 0b10000000, 0b01000000, 0b00000001,
0b01000111, 0b00000001, 0b01000001, 0b00000001,
0b00000011, 0b00000001, 0b01000001, 0b00000001,
0b10000111, 0b00000001, 0b01000001, 0b00000001,
0b10001011, 0b00000001, 0b01000001, 0b00000001,
0b01010011, 0b00000000, 0b01000001, 0b00000001,
0b01001011, 0b00000000, 0b01000001, 0b00000001,
0b01000111, 0b00000000, 0b01000001, 0b00000001,
0b00000011, 0b00000000, 0b01100001, 0b00000001,
0b10000111, 0b00000000, 0b01000001, 0b00000001,
0b10001011, 0b00000000, 0b01000001, 0b00000001,
0b10010011, 0b00000000, 0b01000001, 0b00000001,
0b10100011, 0b00000000, 0b01000001, 0b00000001,
0b01000111, 0b00000001, 0b01000010, 0b00000001,
0b00000011, 0b00000001, 0b01000010, 0b00000001,
0b10000111, 0b00000001, 0b01000010, 0b00000001,
0b10001011, 0b00000001, 0b01000010, 0b00000001,
0b01010011, 0b00000000, 0b01000010, 0b00000001,
0b01001011, 0b00000000, 0b01000010, 0b00000001,
0b01000111, 0b00000000, 0b01000010, 0b00000001,
0b00000011, 0b00000000, 0b01100010, 0b00000001,
0b10000111, 0b00000000, 0b01000010, 0b00000001,
0b10001011, 0b00000000, 0b01000010, 0b00000001,
0b10010011, 0b00000000, 0b01000010, 0b00000001,
0b10100011, 0b00000000, 0b01000010, 0b00000001,
0b01000111, 0b00000001, 0b01000100, 0b00000001,
0b00000011, 0b00000001, 0b01000100, 0b00000001,
0b10000111, 0b00000001, 0b01000100, 0b00000001,
0b10001011, 0b00000001, 0b01000100, 0b00000001,
0b01010011, 0b00000000, 0b01000100, 0b00000001,
0b01001011, 0b00000000, 0b01000100, 0b00000001,
0b01000111, 0b00000000, 0b01000100, 0b00000001,
0b00000011, 0b00000000, 0b01100100, 0b00000001,
0b10000111, 0b00000000, 0b01000100, 0b00000001,
0b10001011, 0b00000000, 0b01000100, 0b00000001,
0b10010011, 0b00000000, 0b01000100, 0b00000001,
0b10100011, 0b00000000, 0b01000100, 0b00000001,
0b01000111, 0b00000001, 0b01001000, 0b00000001,
0b00000011, 0b00000001, 0b01001000, 0b00000001,
0b10000111, 0b00000001, 0b01001000, 0b00000001,
0b10001011, 0b00000001, 0b01001000, 0b00000001,
0b01010011, 0b00000000, 0b01001000, 0b00000001,
0b01001011, 0b00000000, 0b01001000, 0b00000001,
0b01000111, 0b00000000, 0b01001000, 0b00000001,
0b00000011, 0b00000000, 0b01101000, 0b00000001,
0b10000111, 0b00000000, 0b01001000, 0b00000001,
0b10001011, 0b00000000, 0b01001000, 0b00000001,
0b10010011, 0b00000000, 0b01001000, 0b00000001,
0b10100011, 0b00000000, 0b01001000, 0b00000001,
0b01000111, 0b00000001, 0b01010000, 0b00000001,
0b00000011, 0b00000001, 0b01010000, 0b00000001,
0b10000111, 0b00000001, 0b01010000, 0b00000001,
0b10001011, 0b00000001, 0b01010000, 0b00000001,
0b01010011, 0b00000000, 0b01010000, 0b00000001,
0b01001011, 0b00000000, 0b01010000, 0b00000001,
0b01000111, 0b00000000, 0b01010000, 0b00000001,
0b00000011, 0b00000000, 0b01110000, 0b00000010,
0b10000111, 0b00000000, 0b01010000, 0b00000010,
0b10001011, 0b00000000, 0b01010000, 0b00000010,
0b10010011, 0b00000000, 0b01010000, 0b00000010,
0b10100011, 0b00000000, 0b01010000, 0b00000010,
0b01000111, 0b00000011, 0b01000000, 0b00000010,
0b00000011, 0b00000011, 0b01000000, 0b00000010,
0b10000111, 0b00000011, 0b01000000, 0b00000010,
0b10001011, 0b00000011, 0b01000000, 0b00000010,
0b01010011, 0b00000010, 0b01000000, 0b00000010,
0b01001011, 0b00000010, 0b01000000, 0b00000010,
0b01000111, 0b00000010, 0b01000000, 0b00000010,
0b00000011, 0b00000010, 0b01100000, 0b00000010,
0b10000111, 0b00000010, 0b01000000, 0b00000010,
0b10001011, 0b00000010, 0b01000000, 0b00000010,
0b10010011, 0b00000010, 0b01000000, 0b00000010,
0b10100011, 0b00000010, 0b01000000, 0b00000010,
0b01000111, 0b00000101, 0b01000000, 0b00000010,
0b00000011, 0b00000101, 0b01000000, 0b00000010,
0b10000111, 0b00000101, 0b01000000, 0b00000010,
0b10001011, 0b00000101, 0b01000000, 0b00000010,
0b01010011, 0b00000100, 0b01000000, 0b00000010,
0b01001011, 0b00000100, 0b01000000, 0b00000010,
0b01000111, 0b00000100, 0b01000000, 0b00000010,
0b00000011, 0b00000100, 0b01100000, 0b00000010,
0b10000111, 0b00000100, 0b01000000, 0b00000010,
0b10001011, 0b00000100, 0b01000000, 0b00000010,
0b10010011, 0b00000100, 0b01000000, 0b00000010,
0b10100011, 0b00000100, 0b01000000, 0b00000010,
0b01000111, 0b00001001, 0b01000000, 0b00000010,
0b00000011, 0b00001001, 0b01000000, 0b00000010,
0b10000111, 0b00001001, 0b01000000, 0b00000010,
0b10001011, 0b00001001, 0b01000000, 0b00000010,
0b01010011, 0b00001000, 0b01000000, 0b00000010,
0b01001011, 0b00001000, 0b01000000, 0b00000010,
0b01000111, 0b00001000, 0b01000000, 0b00000010,
0b00000011, 0b00001000, 0b01100000, 0b00000010,
0b10000111, 0b00001000, 0b01000000, 0b00000010,
0b10001011, 0b00001000, 0b01000000, 0b00000010,
0b10010011, 0b00001000, 0b01000000, 0b00000010,
0b10100011, 0b00001000, 0b01000000, 0b00000010,
0b01000111, 0b00010001, 0b01000000, 0b00000010,
0b00000011, 0b00010001, 0b01000000, 0b00000010,
0b10000111, 0b00010001, 0b01000000, 0b00000010,
0b10001011, 0b00010001, 0b01000000, 0b00000010,
0b01010011, 0b00010000, 0b01000000, 0b00000010,
0b01001011, 0b00010000, 0b01000000, 0b00000010,
0b01000111, 0b00010000, 0b01000000, 0b00000010,
0b00000011, 0b00010000, 0b01100000, 0b00000010,
0b10000111, 0b00010000, 0b01000000, 0b00000010,
0b10001011, 0b00010000, 0b01000000, 0b00000010,
0b10010011, 0b00010000, 0b01000000, 0b00000010,
0b10100011, 0b00010000, 0b01000000, 0b00000010,
0b01000111, 0b00100001, 0b01000000, 0b00000010,
0b00000011, 0b00100001, 0b01000000, 0b00000010,
0b10000111, 0b00100001, 0b01000000, 0b00000010,
0b10001011, 0b00100001, 0b01000000, 0b00000010,
0b01010011, 0b00100000, 0b01000000, 0b00000010,
0b01001011, 0b00100000, 0b01000000, 0b00000010,
0b01000111, 0b00100000, 0b01000000, 0b00000010,
0b00000011, 0b00100000, 0b01100000, 0b00000010,
0b10000111, 0b00100000, 0b01000000, 0b00000010,
0b10001011, 0b00100000, 0b01000000, 0b00000010,
0b10010011, 0b00100000, 0b01000000, 0b00000010,
0b10100011, 0b00100000, 0b01000000, 0b00000010,
0b01000111, 0b01000001, 0b01000000, 0b00000010,
0b00000011, 0b01000001, 0b01000000, 0b00000010,
0b10000111, 0b01000001, 0b01000000, 0b00000010,
0b10001011, 0b01000001, 0b01000000, 0b00000010,
0b01010011, 0b01000000, 0b01000000, 0b00000010,
0b01001011, 0b01000000, 0b01000000, 0b00000010,
0b01000111, 0b01000000, 0b01000000, 0b00000010,
0b00000011, 0b01000000, 0b01100000, 0b00000100,
0b10000111, 0b01000000, 0b01000000, 0b00000100,
0b10001011, 0b01000000, 0b01000000, 0b00000100,
0b10010011, 0b01000000, 0b01000000, 0b00000100,
0b10100011, 0b01000000, 0b01000000, 0b00000100,
0b01000111, 0b10000001, 0b01000000, 0b00000100,
0b00000011, 0b10000001, 0b01000000, 0b00000100,
0b10000111, 0b10000001, 0b01000000, 0b00000100,
0b10001011, 0b10000001, 0b01000000, 0b00000100,
0b01010011, 0b10000000, 0b01000000, 0b00000100,
0b01001011, 0b10000000, 0b01000000, 0b00000100,
0b01000111, 0b10000000, 0b01000000, 0b00000100,
0b00000011, 0b10000000, 0b01100000, 0b00000100,
0b10000111, 0b10000000, 0b01000000, 0b00000100,
0b10001011, 0b10000000, 0b01000000, 0b00000100,
0b10010011, 0b10000000, 0b01000000, 0b00000100,
0b10100011, 0b10000000, 0b01000000, 0b00000100,
0b01000111, 0b00000001, 0b01000001, 0b00000100,
0b00000011, 0b00000001, 0b01000001, 0b00000100,
0b10000111, 0b00000001, 0b01000001, 0b00000100,
0b10001011, 0b00000001, 0b01000001, 0b00000100,
0b01010011, 0b00000000, 0b01000001, 0b00000100,
0b01001011, 0b00000000, 0b01000001, 0b00000100,
0b01000111, 0b00000000, 0b01000001, 0b00000100,
0b00000011, 0b00000000, 0b01100001, 0b00000100,
0b10000111, 0b00000000, 0b01000001, 0b00000100,
0b10001011, 0b00000000, 0b01000001, 0b00000100,
0b10010011, 0b00000000, 0b01000001, 0b00000100,
0b10100011, 0b00000000, 0b01000001, 0b00000100,
0b01000111, 0b00000001, 0b01000010, 0b00000100,
0b00000011, 0b00000001, 0b01000010, 0b00000100,
0b10000111, 0b00000001, 0b01000010, 0b00000100,
0b10001011, 0b00000001, 0b01000010, 0b00000100,
0b01010011, 0b00000000, 0b01000010, 0b00000100,
0b01001011, 0b00000000, 0b01000010, 0b00000100,
0b01000111, 0b00000000, 0b01000010, 0b00000100,
0b00000011, 0b00000000, 0b01100010, 0b00000100,
0b10000111, 0b00000000, 0b01000010, 0b00000100,
0b10001011, 0b00000000, 0b01000010, 0b00000100,
0b10010011, 0b00000000, 0b01000010, 0b00000100,
0b10100011, 0b00000000, 0b01000010, 0b00000100,
0b01000111, 0b00000001, 0b01000100, 0b00000100,
0b00000011, 0b00000001, 0b01000100, 0b00000100,
0b10000111, 0b00000001, 0b01000100, 0b00000100,
0b10001011, 0b00000001, 0b01000100, 0b00000100,
0b01010011, 0b00000000, 0b01000100, 0b00000100,
0b01001011, 0b00000000, 0b01000100, 0b00000100,
0b01000111, 0b00000000, 0b01000100, 0b00000100,
0b00000011, 0b00000000, 0b01100100, 0b00000100,
0b10000111, 0b00000000, 0b01000100, 0b00000100,
0b10001011, 0b00000000, 0b01000100, 0b00000100,
0b10010011, 0b00000000, 0b01000100, 0b00000100,
0b10100011, 0b00000000, 0b01000100, 0b00000100,
0b01000111, 0b00000001, 0b01001000, 0b00000100,
0b00000011, 0b00000001, 0b01001000, 0b00000100,
0b10000111, 0b00000001, 0b01001000, 0b00000100,
0b10001011, 0b00000001, 0b01001000, 0b00000100,
0b01010011, 0b00000000, 0b01001000, 0b00000100,
0b01001011, 0b00000000, 0b01001000, 0b00000100,
0b01000111, 0b00000000, 0b01001000, 0b00000100,
0b00000011, 0b00000000, 0b01101000, 0b00000100,
0b10000111, 0b00000000, 0b01001000, 0b00000100,
0b10001011, 0b00000000, 0b01001000, 0b00000100,
0b10010011, 0b00000000, 0b01001000, 0b00000100,
0b10100011, 0b00000000, 0b01001000, 0b00000100,
0b01000111, 0b00000001, 0b01010000, 0b00000100,
0b00000011, 0b00000001, 0b01010000, 0b00000100,
0b10000111, 0b00000001, 0b01010000, 0b00000100,
0b10001011, 0b00000001, 0b01010000, 0b00000100,
0b01010011, 0b00000000, 0b01010000, 0b00000100,
0b01001011, 0b00000000, 0b01010000, 0b00000100,
0b01000111, 0b00000000, 0b01010000, 0b00000100,
};
// Minutes hack constants
static uint32_t MINUTE_LEDS[] PROGMEM = {
// n_minute_state, n_minute_led, led0, led2, led3, led4...
0, 0,
};
static uint32_t MINUTES_HACK[] PROGMEM = {
};
|
rupello/ClockTHREEjr | arduino/libraries/ClockTHREE/ClockTHREE.h | <reponame>rupello/ClockTHREEjr
/*
ClockTHREE.h -- ClockTHREE RGB LED Matrix library for Arduino
<NAME>
The hardware and software for ClockTHREE have been enabled by the
open souce Peggy2. Thanks to the Evil Mad Science Team for making them
available.
LIBRARY VERSION: 0.01, DATED 26/11/2010
Licenced under Creative Commons Attribution.
Attribution 3.0 Unported
This license is acceptable for Free Cultural Works.
You are free:
* to Share — to copy, distribute and transmit the work
* to Remix — to adapt the work
*
Under the following conditions:
*
Attribution — You must attribute the work in the manner specified by
the author or licensor (but not in any way that suggests that they endorse
you or your use of the work).
Attribute this work:
Information
What does "Attribute this work" mean?
The page you came from contained embedded licensing metadata, including
how the creator wishes to be attributed for re-use. You can use the HTML here
to cite the work. Doing so will also include metadata on your page so that
others can find the original work as well.
With the understanding that:
* Waiver — Any of the above conditions can be waived if you get permission
from the copyright holder.
* Public Domain — Where the work or any of its elements is in the public
domain under applicable law, that status is in no way affected by the
license.
* Other Rights — In no way are any of the following rights affected by the
license:
o Your fair dealing or fair use rights, or other applicable copyright
exceptions and limitations;
o The author's moral rights;
o Rights other persons may have either in the work itself or in how
the work is used, such as publicity or privacy rights.
* Notice — For any reuse or distribution, you must make clear to others
the license terms of this work. The best way to do this is with a link
to this web page.
*/
#ifndef ClockTHREE_h
#define ClockTHREE_h
#define CLOCKTHREEJR // uncomment this line for ClockTHREEjr
// #define PEGGY2 // uncomment this line for Peggy2
// Arduino 1.0 compatibility
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#define WIRE_READ Wire.read();
#else
#include "WProgram.h"
#define WIRE_READ Wire.receive()
#endif
#include <inttypes.h>
#include "SPI.h"
#include "rtcBOB.h"
// #include "Screen.h"
#ifdef CLOCKTHREEJR
const int N_ROW = 8;
const int N_RGB_ROW = 0;
const int N_COL = 16;
const int N_COLOR = 2;
#elif defined PEGGY2
const int N_ROW = 25;
const int N_RGB_ROW = 0;
const int N_COL = 25;
const int N_COLOR = 2;
#else
const int N_ROW = 12;
const int N_RGB_ROW = 10;
const int N_COL = 16;
const int N_COLOR = 9;
#endif
const unsigned long BAUDRATE = 112500;
const int COL_DRIVER_ENABLE = 17;
const int SPEAKER_PIN = 10;
const int DBG = 16;
const int MODE_PIN = 2;
const int INC_PIN = 3;
const int DEC_PIN = 15;
const int ENTER_PIN = 8;
const int LDR_PIN = 0;
// bitmasks for the colors
const unsigned long RGBW_MASKS[] = {
0b001001001001001001001001001001, // RED
0b010010010010010010010010010010, // GREEN
0b100100100100100100100100100100, // BLUE
0b001111111111111111111111111111 // WHITE
};
const uint8_t DARK = 0b000;
const uint8_t RED = 0b001;
const uint8_t GREEN = 0b010;
const uint8_t BLUE = 0b100;
const uint8_t GREENBLUE = GREEN | BLUE;
const uint8_t REDGREEN = RED | GREEN;
const uint8_t REDBLUE = RED | BLUE;
const uint8_t WHITE = 0b111;
// not a real color, use temperature for color;
const uint8_t TEMPERATURE_COLOR = 8;
const uint8_t BLUE_TEMP_C = 15;
const uint8_t WHITE_TEMP_C = 33;
const uint8_t MONO = BLUE;
// cold to warm
const uint8_t COLORS[9] = {
DARK,
BLUE,
GREENBLUE,
GREEN,
REDBLUE,
REDGREEN,
RED,
WHITE,
TEMPERATURE_COLOR // hidden color for temperature control
};
class ClockTHREE {//:public Screen{
public:
ClockTHREE();
// Hardware initialization
void init();
// Scan current display 1 time (if display is not NULL)
void refresh();
// Scan current display n times (if display is not NULL)
void refresh(int n);
void refresh_old(int n);
// Gradually change display to new_display in over "steps" screens
// return pointer to old display
uint32_t *fadeto(uint32_t *new_display, uint32_t steps);
// Interleave two images at specified duty cycle.
void blend(uint32_t *new_display,
uint8_t k,
uint8_t n,
uint32_t cycles);
// Clears the display: LEDs set to OFF
void clear(void);
/*
* Set the hold time between column writes defaults to 50
* (my_delay = # of times noop is called)
*/
void set_column_hold(uint16_t _my_delay);
void setcol(uint8_t xpos, uint32_t col);
uint32_t getcol(uint8_t xpos);
// Turn a pixel to color (0 == off)
void setPixel(uint8_t xpos, uint8_t ypos, uint8_t color);
// Determine color value of pixel at xpos, ypos
uint8_t getPixel(uint8_t xpos, uint8_t ypos);
//Draw a line from (x1,y1) to (x2,y2)
void line(double x1, double y1, double x2, double y2, uint8_t color);
// Draw an ellipse centered at x, y with radius rx in the x direction and
// ry in the y direction
void ellipsalArc(double cx, double cy,
double sma, double smi, double orientation,
uint8_t color);
/*
* Draw an arc of an ellipse centered at x, y with
* semi-major axis sma
* semi-minor axis smi
* with semimajor axis oriented by orientation angle in radians
* orient = 0 => sma oriented along x axis
* orient = pi / 2 => sma oriented along x axis
*/
void ellipse(double cx, double cy,
double sma, double smi, double orientation,
uint8_t color);
// Draw a circle centered at x, y with radius r
void circle(double x, double y, double r, uint8_t color);
// Draw a rectangle
//Set cursor position to (xpos,ypos)
void moveto(int8_t xpos, int8_t ypos);
//Draw line from cursor position to (xpos,ypos)
// updating cursor position
void lineto(int8_t xpos, int8_t ypos, uint8_t color);
// Replace current display buffer, return pointer to old buffer
uint32_t *setdisplay(uint32_t *display);
/*
Fill in a horizontal line of LEDs from start to start + n_char.
n_char = # characters.
*/
void horizontal_line(uint8_t row,
uint8_t start,
uint8_t n_char,
uint8_t color);
// Fill the display with single color
void displayfill(uint8_t color);
// turn display off
void off();
// play a note
void note(uint16_t freq);
void note(uint16_t freq, uint16_t duration_ms);
void nonote();
/*
* Uses RTC if available or INT if not.
*/
uint32_t* display;
uint8_t dim;
uint8_t xpos;
uint8_t ypos;
uint16_t my_delay;
uint8_t n_disp_col; // number of columns in the display data (at least N_COL, may be more)
private:
};
uint8_t getColor(uint8_t color);
void _delay(unsigned int n);
#endif
|
wilson100hong/CarND-Path-Planning-Project | src/planner.h | <reponame>wilson100hong/CarND-Path-Planning-Project<filename>src/planner.h
#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <utility>
#include <vector>
#include "helpers.h"
#include "spline.h"
using std::map;
using std::tuple;
using std::vector;
// Map waypoints in x, y, s, dx and dy.
struct MapData {
vector<double> xs;
vector<double> ys;
vector<double> ss;
vector<double> dxs;
vector<double> dys;
};
// Vehicle state.
struct Pose {
double x; // m
double y; // m
double yaw; // rad
double s;
double d;
double speed; // m/s
};
// Point on x-y plane.
struct Point {
double x;
double y;
};
// Gets distance between points |p1| and |p2|.
double Distance(const Point& p1, const Point& p2) {
return distance(p1.x, p1.y, p2.x, p2.y);
}
// Get angle in rad from point |p1| to |p2|.
double Angle(const Point& p1, const Point& p2) {
return atan2(p2.y - p1.y, p2.x - p1.x);
}
// Transforms point |p| from world coordinate into |ref_pose| coordinate.
Point ToRefCoord(const Point& p, const Pose& ref_pose) {
const double yaw = ref_pose.yaw;
const double shift_x = p.x - ref_pose.x;
const double shift_y = p.y - ref_pose.y;
return {
shift_x*cos(-yaw) - shift_y*sin(-yaw), // x
shift_x*sin(-yaw) + shift_y*cos(-yaw) // y
};
}
// Transforms point |p| from |ref_pose| coordinate back to world coordinate.
Point FromRefCoord(const Point& p, const Pose& ref_pose) {
const double yaw = ref_pose.yaw;
const double rot_x = p.x*cos(yaw) - p.y*sin(yaw);
const double rot_y = p.x*sin(yaw) + p.y*cos(yaw);
return {
rot_x + ref_pose.x, // x
rot_y + ref_pose.y // y
};
}
using Polyline = vector<Point>;
// Converts vectors of x-values and y-values in to a Polyline.
Polyline XYVectorsToPolyline(const vector<double>& xs, const vector<double>& ys) {
Polyline line;
for (int i=0; i<xs.size(); ++i) {
line.push_back({xs[i], ys[i]});
}
return line;
}
// Converts a Polyline into vectors of x-values and y-values.
std::pair<vector<double>, vector<double>> PolylineToXYVectors(const Polyline& line) {
vector<double> xs;
vector<double> ys;
for (const auto& point : line) {
xs.push_back(point.x);
ys.push_back(point.y);
}
return std::make_pair(xs, ys);
}
// Class to generate trajectory.
class Planner {
// Planner state.
enum class State {
KEEP_LANE,
LANE_CHANGING
};
public:
Planner(const MapData& map_data, double max_s, int track_lane = 1)
: map_data_(map_data), MAX_S(max_s), track_lane_(track_lane), state_(State::KEEP_LANE) {}
Polyline Plan(const Polyline& input_prev_path, const Pose &ego_car, const std::map<int, Pose>& vehicles);
private:
// Normalize Frenet s-value in range [0, MAX_S].
double NormalizeS(double s) {
while (s > MAX_S) { s -= MAX_S; }
while (s < 0) { s += MAX_S; }
return s;
}
// Returns true if |s1| is further than |s2| (Frenet s-value).
// Lap wrap is considered.
bool IsFurtherInS(double s1, double s2) {
s1 = NormalizeS(s1);
s2 = NormalizeS(s2);
if (std::abs(s1 - s2) > MAX_S * 0.5) {
if (s1 < s2) {
s1 += MAX_S;
} else if (s1 > s2) {
s2 += MAX_S;
}
}
return s1 > s2;
}
// Returns the distance between two Frenet s-values.
// Lap wrap is considered.
double DistanceInS(double s1, double s2) {
s1 = NormalizeS(s1);
s2 = NormalizeS(s2);
double dist = std::abs(s1 - s2);
if (dist > MAX_S * 0.5) {
dist = MAX_S - dist;
}
return dist;
}
// Converts |lane| to Frenet d-value.
double LaneToD(int lane) {
return lane * 4.0 + 2.0;
}
bool InLane(const Pose& ego_car, int lane) {
double target_d = LaneToD(lane);
return std::abs(ego_car.d - target_d) < 0.5;
}
// Converts Frenet to Cartesian Point.
Point FrenetToXY(double s, double d) {
s = NormalizeS(s);
auto waypt = getXY(s, d, map_data_.ss, map_data_.xs, map_data_.ys);
return {waypt[0], waypt[1]};
}
// Converts Cartesian |x|, |y| and |theta| to Frenet.
vector<double> XYToFrenet(double x, double y, double theta) {
return getFrenet(x, y, theta, map_data_.xs, map_data_.ys);
}
// Creates a feasible trajectory with target lane and speed.
Polyline CreateTrajectory(
const Polyline& prev_path, const Pose& ego_car,
int target_lane, double target_speed);
// Gets maximum feasible speed at |lane| without colliding vehicle in front.
double GetTargetSpeed(int lane, const Pose& ego_car, const std::map<int, Pose>& vehicles);
// Returns true if ego car change to |lane| without collision.
bool CanChangeLane(int lane, const Pose& ego_car, const std::map<int, Pose>& vehicles);
// Cost function of a lane - trajectory. The smaller the better.
double GetCost(int lane, const Polyline& trajectory, const Pose& ego_car);
MapData map_data_;
State state_;
// The lane ego car trying to track.
int track_lane_;
// Constants used in planner.
// The max s value before wrapping around the track back to 0.
double MAX_S = 6945.554;
double MAX_SPEED = 21.5; // 22 m/s = 49.21 mph
double MIN_SPEED = 20.5;
double MAX_ACCEL = 10; // 10 m/s/s
double MAX_JERK = 10; // 10 m/s/s/s
// Delta time between each point in trajectory.
double DELTA_T = 0.02; // second
size_t TRAJECTORY_SIZE = 50; // 50 * 0.02 ms = 1 sec
// Number of points stiched from previous path.
size_t STITCH_SIZE = 50;
size_t NUM_LANE = 3;
// Vehicle dimension.
double VEHICLE_WIDTH = 0.75;
// Number of steps extended for refernce line and step distance (in s-value).
size_t NUM_REF_STEP = 3;
double REF_STEP_S = 30.0;
};
Polyline Planner::Plan(
const Polyline& input_prev_path,
const Pose& ego_car,
const std::map<int, Pose>& vehicles) {
// Truncate prev_path to STITCH_SIZE.
Polyline prev_path(input_prev_path.begin(),
input_prev_path.begin() + std::min(input_prev_path.size(), STITCH_SIZE));
// Generate trajectory on |track_lane_|.
const double target_speed = GetTargetSpeed(track_lane_, ego_car, vehicles);
Polyline trajectory = CreateTrajectory(prev_path, ego_car, track_lane_, target_speed);
if (state_ == State::LANE_CHANGING) {
// In LANE_CHANGING, just finish ongoing lane changing.
if (InLane(ego_car, track_lane_)) {
// Transit to KEEP_LANE once ego car d-value is closest to lane center enough.
state_ = State::KEEP_LANE;
}
return trajectory;
}
// Return the trajectory is speed is acceptable.
if (target_speed >= MIN_SPEED) {
return trajectory;
}
std::cout << "need to change lane" << std::endl;
// If speed is too low, try to find better candidate trajectoies.
map<int, Polyline> lane_trajectories;
lane_trajectories.emplace(track_lane_, std::move(trajectory));
for (int lane_change = -1; lane_change <= 1; lane_change+=2) {
const int cand_lane = track_lane_ + lane_change;
if (cand_lane < 0 || cand_lane >= NUM_LANE) {
continue;
}
if (!CanChangeLane(cand_lane, ego_car, vehicles)) {
// Too danger to make lange chagne, skipped.
continue;
}
const double cand_speed = GetTargetSpeed(cand_lane, ego_car, vehicles);
Polyline cand_trajectory = CreateTrajectory(prev_path, ego_car, cand_lane, cand_speed);
lane_trajectories.emplace(cand_lane, std::move(cand_trajectory));
}
// Pick the best trajectory with lowest cost.
int best_lane;
double best_cost = std::numeric_limits<double>::max();
for (const auto& entry : lane_trajectories) {
const double lane = entry.first;
const Polyline& trajectory = entry.second;
const double cost = GetCost(lane, trajectory, ego_car);
if (cost < best_cost) {
best_cost = cost;
best_lane = lane;
}
}
if (best_lane != track_lane_) {
// Change lane.
state_ = State::LANE_CHANGING;
track_lane_ = best_lane;
}
return lane_trajectories[best_lane];
}
Polyline Planner::CreateTrajectory(
const Polyline& prev_path, const Pose& ego_car,
int target_lane, double target_speed) {
// Pose at the end of |prev_path|.
Pose end_pose;
Polyline ref_line;
// Initialize reference line ahd refernce pose (pose at previous path last point)
// from the previous path's last two waypoints.
const int prev_size = prev_path.size();
if (prev_size < 2) {
end_pose = ego_car;
ref_line.push_back({
end_pose.x - cos(end_pose.yaw), // x
end_pose.y - sin(end_pose.yaw) // y
});
} else {
const Point& last_point = prev_path[prev_size - 1];
const Point& last2_point = prev_path[prev_size - 2];
ref_line.push_back(last2_point);
const double yaw = Angle(last2_point, last_point);
const auto end_frenet = XYToFrenet(last_point.x, last_point.y, yaw);
end_pose = {
last_point.x,
last_point.y,
yaw, // yaw
end_frenet[0], // s
end_frenet[1], // d
Distance(last_point, last2_point) / DELTA_T // speed
};
}
ref_line.push_back({end_pose.x, end_pose.y});
// Append more points along s to refernce line.
const double target_d = LaneToD(target_lane);
for (int i=1; i<=NUM_REF_STEP; ++i) {
const double target_s = end_pose.s + i * REF_STEP_S;
const Point waypoint = FrenetToXY(target_s, target_d);
ref_line.push_back(waypoint);
}
// Transform reference line points to coordinates orginated at |end_pose|.
for (int i = 0; i < ref_line.size(); ++i) {
ref_line[i] = ToRefCoord(ref_line[i], end_pose);
}
// Fit refernce line to a spline.
tk::spline spline;
vector<double> ref_xs;
vector<double> ref_ys;
std::tie(ref_xs, ref_ys) = PolylineToXYVectors(ref_line);
spline.set_points(ref_xs, ref_ys);
// Max x distance traveled in next second.
double horizon_x = MAX_SPEED * 1.0;
double horizon_y = spline(horizon_x);
double horizon_angle = atan2(horizon_y, horizon_x);
// Initialize trajectolry by stiching points from previous path.
Polyline trajectory(prev_path.begin(), prev_path.end());
// Add waypoints to trajectory without violating speed and acceleration limit.
double speed = end_pose.speed;
Point spline_point = {0.0, 0.0};
while (trajectory.size() < TRAJECTORY_SIZE) {
spline_point.x += DELTA_T * speed * cos(horizon_angle);
spline_point.y = spline(spline_point.x);
Point traj_point = FromRefCoord(spline_point, end_pose);
trajectory.push_back(traj_point);
// Use 70% of acceleration.
if (speed < target_speed) {
speed += std::min(target_speed - speed, MAX_ACCEL * DELTA_T * 0.7);
} else if (speed > target_speed) {
speed -= std::min(speed - target_speed, MAX_ACCEL * DELTA_T * 0.7);
}
}
return trajectory;
}
double Planner::GetTargetSpeed(
int lane, const Pose& ego_car, const std::map<int, Pose>& vehicles) {
const double target_d = LaneToD(lane);
double target_speed = MAX_SPEED;
double min_s_dist= std::numeric_limits<double>::max();
for (const auto& entry : vehicles) {
const auto& vehicle = entry.second;
const double s_dist = DistanceInS(vehicle.s, ego_car.s);
if (abs(vehicle.d - target_d) > VEHICLE_WIDTH) continue;
if (IsFurtherInS(vehicle.s, ego_car.s) &&
s_dist < MAX_SPEED * 2.0) {
if (s_dist < min_s_dist) {
min_s_dist = s_dist;
target_speed = std::min(target_speed, vehicle.speed);
}
}
}
return target_speed;
}
bool Planner::CanChangeLane(int lane, const Pose& ego_car, const std::map<int, Pose>& vehicles) {
const double target_d = LaneToD(lane);
int fail_reason = -1;
for (const auto& entry : vehicles) {
const auto& vehicle = entry.second;
if (abs(vehicle.d - target_d) > VEHICLE_WIDTH) continue;
const double s_dist = DistanceInS(vehicle.s, ego_car.s);
if (IsFurtherInS(vehicle.s, ego_car.s)) {
if (ego_car.speed > vehicle.speed && s_dist < 20.0) fail_reason = 1;
if (ego_car.speed <= vehicle.speed && s_dist < 8.0) fail_reason = 2;
} else { // Ego car in front of vehicle
if (ego_car.speed > vehicle.speed && s_dist < 6.0) fail_reason = 3;
if (ego_car.speed <= vehicle.speed && s_dist < 10.0) fail_reason = 4;
}
if (fail_reason != -1) {
// DEBUG
std::cout << "[CanChagneLane] cannot CL to " << lane << " because of " << fail_reason << std::endl;
return false;
}
}
return true;
}
double Planner::GetCost(int lane, const Polyline& trajectory, const Pose& ego_car) {
// Compute the cost of speed.
const int traj_size = trajectory.size();
const Point& last_point = trajectory[traj_size - 1];
const Point& last2_point = trajectory[traj_size - 2];
const double speed = Distance(last_point, last2_point) / DELTA_T;
const double speed_cost = MAX_SPEED - speed;
// Compute the cost of distance traveled.
const auto end_frenet = XYToFrenet(last_point.x, last_point.y, Angle(last2_point, last_point));
const double end_s = end_frenet[0];
// Compensate s drecrease due to crossing the lap end.
const double s_traveled = DistanceInS(end_s, ego_car.s);
const double dist_cost = MAX_SPEED * 2.0 - s_traveled;
// Compute the cost of lane (prefer center lane).
const double lane_cost = std::abs(1 - lane);
return speed_cost + dist_cost;
}
|
somnisoft/head | test/seams.c | /**
* @file
* @brief Test seams
* @author <NAME> (<EMAIL>)
*
* This software has been placed into the public domain using CC0.
*/
#include <errno.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include "test.h"
/**
* Error counter for @ref test_seam_fclose.
*/
int g_test_seam_err_ctr_fclose = -1;
/**
* Error counter for @ref test_seam_ferror.
*/
int g_test_seam_err_ctr_ferror = -1;
/**
* Error counter for @ref test_seam_fwrite.
*/
int g_test_seam_err_ctr_fwrite = -1;
/**
* Error counter for @ref test_seam_getline.
*/
int g_test_seam_err_ctr_getline = -1;
/**
* Error counter for @ref test_seam_printf.
*/
int g_test_seam_err_ctr_printf = -1;
/**
* Error counter for @ref test_seam_putchar.
*/
int g_test_seam_err_ctr_putchar = -1;
/**
* Decrement an error counter until it reaches -1.
*
* After a counter reaches -1, it will return a true response. This gets
* used by the test suite to denote when to cause a function to fail. For
* example, the unit test might need to cause the malloc() function to fail
* after calling it a third time. In that case, the counter should initially
* get set to 2 and will get decremented every time this function gets called.
*
* @param[in,out] err_ctr Error counter to decrement.
* @retval true The counter has reached -1.
* @retval false The counter has been decremented, but did not reach
* -1 yet.
*/
static bool
test_seam_dec_err_ctr(int *const err_ctr){
bool reached_end;
reached_end = false;
if(*err_ctr >= 0){
*err_ctr -= 1;
if(*err_ctr < 0){
reached_end = true;
}
}
return reached_end;
}
/**
* Control when fclose() fails.
*
* @param[in,out] stream File pointer.
* @retval 0 Successfully closed file.
* @retval EOF Failed to close file.
*/
int
test_seam_fclose(FILE *stream){
int rc;
if(test_seam_dec_err_ctr(&g_test_seam_err_ctr_fclose)){
rc = EOF;
errno = EBADF;
}
else{
rc = fclose(stream);
}
return rc;
}
/**
* Control when ferror() fails.
*
* @param[in] stream File pointer.
* @retval 0 File error indicator not set.
* @retval !0 File error indicator set.
*/
int
test_seam_ferror(FILE *stream){
int rc;
if(test_seam_dec_err_ctr(&g_test_seam_err_ctr_ferror)){
rc = 1;
}
else{
rc = ferror(stream);
}
return rc;
}
/**
* Control when fwrite() fails.
*
* @param[in] ptr Data to write to @p stream.
* @param[in] size Size of each element in @p nitems.
* @param[in] nitems Number of items to write.
* @param[in,out] stream File pointer to write to.
* @return Number of @p items written to @p stream.
*/
size_t
test_seam_fwrite(const void *ptr,
size_t size,
size_t nitems,
FILE *stream){
size_t nwrite;
if(test_seam_dec_err_ctr(&g_test_seam_err_ctr_fwrite)){
nwrite = 0;
errno = EPIPE;
}
else{
nwrite = fwrite(ptr, size, nitems, stream);
}
return nwrite;
}
/**
* Control when getline() fails.
*
* @param[in,out] lineptr Line buffer that may get reallocated.
* @param[in,out] n Number of bytes allocated in @p lineptr.
* @param[in,out] stream File pointer to read from.
* @retval >=0 Number of bytes read.
* @retval -1 Error occurred.
*/
ssize_t
test_seam_getline(char **lineptr,
size_t *n,
FILE *stream){
ssize_t linelen;
if(test_seam_dec_err_ctr(&g_test_seam_err_ctr_getline)){
linelen = -1;
errno = ENOMEM;
}
else{
linelen = getline(lineptr, n, stream);
}
return linelen;
}
/**
* Control when printf() fails.
*
* @param[in] format Format argument list to print.
* @retval >=0 Number of bytes written.
* @retval <0 Output error.
*/
int
test_seam_printf(const char *format, ...){
int bytes_written;
va_list ap;
if(test_seam_dec_err_ctr(&g_test_seam_err_ctr_printf)){
bytes_written = -1;
errno = ENOMEM;
}
else{
va_start(ap, format);
bytes_written = vprintf(format, ap);
va_end(ap);
}
return bytes_written;
}
/**
* Control when putchar() fails.
*
* @param[in] c Byte to write.
* @retval c Successfully wrote @p c.
* @retval EOF Error occurred.
*/
int
test_seam_putchar(int c){
int byte_written;
if(test_seam_dec_err_ctr(&g_test_seam_err_ctr_putchar)){
byte_written = EOF;
errno = ENOMEM;
}
else{
byte_written = putchar(c);
}
return byte_written;
}
|
somnisoft/head | src/head.c | /**
* @file
* @brief head utility
* @author <NAME> (<EMAIL>)
*
* This software has been placed into the public domain using CC0.
*/
#include <err.h>
#include <errno.h>
#include <inttypes.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef TEST
/**
* Declare some functions with extern linkage, allowing the test suite to call
* those functions.
*/
# define LINKAGE extern
# include "../test/seams.h"
#else /* !(TEST) */
/**
* Define all functions as static when not testing.
*/
# define LINKAGE static
#endif /* TEST */
/**
* Default number of lines to print if -n argument unspecified.
*/
#define HEAD_DEFAULT_LINES (10)
/**
* Head utility context.
*/
struct head{
/**
* Exit status set to one of the following values.
* - EXIT_SUCCESS
* - EXIT_FAILURE
*/
int status_code;
/**
* Padding for alignment.
*/
char pad[4];
/**
* Number of initial lines to write in each file.
*
* Corresponds to the (-n) argument.
*/
uintmax_t nlines;
/**
* getline() line buffer.
*/
char *line;
/**
* Number of bytes allocated in @ref line.
*/
size_t linesize;
};
/**
* Print an error message to STDERR and set an error status code.
*
* @param[in,out] head See @ref head.
* @param[in] errno_msg Include a standard message describing errno.
* @param[in] fmt Format string used by vwarn.
*/
static void
head_warn(struct head *const head,
const bool errno_msg,
const char *const fmt, ...){
va_list ap;
head->status_code = EXIT_FAILURE;
va_start(ap, fmt);
if(errno_msg){
vwarn(fmt, ap);
}
else{
vwarnx(fmt, ap);
}
va_end(ap);
}
/**
* Print head lines from file pointer.
*
* @param[in,out] head See @ref head.
* @param[in,out] fp File pointer to read from.
*/
static void
head_fp(struct head *const head,
FILE *fp){
uintmax_t i;
ssize_t linelen;
size_t nmemb;
for(i = 0; i < head->nlines; i++){
errno = 0;
linelen = getline(&head->line, &head->linesize, fp);
if(linelen < 0){
if(errno != 0){
head_warn(head, true, "getline");
}
break;
}
/* linelen >= 0 */
nmemb = (size_t)linelen;
if(fwrite(head->line, sizeof(*head->line), nmemb, stdout) != nmemb){
head_warn(head, true, "fwrite: %s", &head->line);
break;
}
}
if(ferror(fp) || ferror(stdout)){
head_warn(head, true, "ferror: file error indicator set");
}
}
/**
* Open a file path and call @ref head_fp.
*
* @param[in,out] head See @ref head.
* @param[in] path File path.
*/
static void
head_path(struct head *const head,
const char *const path){
FILE *fp;
fp = fopen(path, "r");
if(fp == NULL){
head_warn(head, true, "fopen: %s", path);
}
else{
head_fp(head, fp);
if(fclose(fp) != 0){
head_warn(head, true, "fclose: %s", path);
}
}
}
/**
* Parse number of lines to print.
*
* Corresponds to the (-n) argument.
*
* @param[in,out] head See @ref head.
* @param[in] s String to parse.
*/
static void
head_parse_nlines(struct head *const head,
const char *const s){
char *ep;
errno = 0;
head->nlines = strtoumax(s, &ep, 10);
if(s[0] == '\0' || *ep != '\0'){
head_warn(head, false, "not a number: %s", s);
}
else if(head->nlines == UINTMAX_MAX && errno == ERANGE){
head_warn(head, true, "out of range: %s", s);
}
}
/**
* Main entry point for head program.
*
* Usage:
* head [-n number] [file...]
*
* @param[in] argc Number of arguments in @p argv.
* @param[in,out] argv Argument list.
* @retval EXIT_SUCCESS Successful.
* @retval EXIT_FAILURE Error occurred.
*/
LINKAGE int
head_main(int argc,
char *argv[]){
int c;
int i;
struct head head;
memset(&head, 0, sizeof(head));
head.nlines = HEAD_DEFAULT_LINES;
while((c = getopt(argc, argv, "n:")) != -1){
switch(c){
case 'n':
head_parse_nlines(&head, optarg);
break;
default:
head.status_code = EXIT_FAILURE;
break;
}
}
argc -= optind;
argv += optind;
if(head.status_code == 0){
if(argc < 1){
head_fp(&head, stdin);
}
else{
for(i = 0; i < argc; i++){
if(argc > 1){
if(i > 0){
if(putchar('\n') != '\n'){
head_warn(&head, true, "putchar: <NL>");
}
}
if(printf("==> %s <==\n", argv[i]) < 0){
head_warn(&head, true, "printf: file header");
}
}
head_path(&head, argv[i]);
}
}
free(head.line);
}
return head.status_code;
}
#ifndef TEST
/**
* Main program entry point.
*
* @param[in] argc See @ref head_main.
* @param[in,out] argv See @ref head_main.
* @return See @ref head_main.
*/
int
main(int argc,
char *argv[]){
return head_main(argc, argv);
}
#endif /* TEST */
|
somnisoft/head | test/seams.h | <filename>test/seams.h
/**
* @file
* @brief Test seams
* @author <NAME> (<EMAIL>)
*
* This software has been placed into the public domain using CC0.
*/
#ifndef HEAD_TEST_SEAMS_H
#define HEAD_TEST_SEAMS_H
#include "test.h"
/*
* Redefine these functions to internal test seams.
*/
#undef fclose
#undef ferror
#undef fwrite
#undef getline
#undef printf
#undef putchar
/**
* Inject a test seam to replace fclose().
*/
#define fclose test_seam_fclose
/**
* Inject a test seam to replace ferror().
*/
#define ferror test_seam_ferror
/**
* Inject a test seam to replace fwrite().
*/
#define fwrite test_seam_fwrite
/**
* Inject a test seam to replace getline().
*/
#define getline test_seam_getline
/**
* Inject a test seam to replace printf().
*/
#define printf test_seam_printf
/**
* Inject a test seam to replace putchar().
*/
#define putchar test_seam_putchar
#endif /* HEAD_TEST_SEAMS_H */
|
somnisoft/head | test/test.c | /**
* @file
* @brief Test suite
* @author <NAME> (<EMAIL>)
*
* This software has been placed into the public domain using CC0.
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "test.h"
/**
* Generate the output of the head command to this file.
*/
#define PATH_TMP_FILE "build/test-head.txt"
/**
* Number of arguments in @ref g_argv.
*/
static int
g_argc;
/**
* Argument list to pass to utility.
*/
static char **
g_argv;
/**
* Call @ref head_main with the given arguments.
*
* @param[in] nlines Number of initial lines to write.
* @param[in] stdin_bytes Transmit these bytes to STDIN of child
* process.
* @param[in] stdin_bytes_len Number of bytes in @p stdin_bytes.
* @param[in] expect_ref_file Reference file containing expected head
* output.
* @param[in] expect_exit_status Expected exit status code.
* @param[in] file_list List of files to print.
*/
static void
test_head_main(const char *const nlines,
const char *const stdin_bytes,
const size_t stdin_bytes_len,
const char *const expect_ref_file,
const int expect_exit_status,
const char *const file_list, ...){
va_list ap;
const char *file;
ssize_t bytes_written;
int exit_status;
pid_t pid;
FILE *new_stdout;
int status;
int cmp_exit_status;
int pipe_stdin[2];
char cmp_cmd[1000];
g_argc = 1;
if(nlines){
strcpy(g_argv[g_argc++], "-n");
strcpy(g_argv[g_argc++], nlines);
}
va_start(ap, file_list);
for(file = file_list; file; file = va_arg(ap, const char *const)){
strcpy(g_argv[g_argc++], file);
}
va_end(ap);
errno = 0;
assert(remove(PATH_TMP_FILE) == 0 || errno == ENOENT);
if(stdin_bytes){
assert(pipe(pipe_stdin) == 0);
}
pid = fork();
assert(pid >= 0);
if(pid == 0){
if(stdin_bytes){
assert(close(pipe_stdin[1]) == 0);
assert(dup2(pipe_stdin[0], STDIN_FILENO) >= 0);
assert(close(pipe_stdin[0]) == 0);
}
new_stdout = freopen(PATH_TMP_FILE, "w", stdout);
assert(new_stdout);
exit_status = head_main(g_argc, g_argv);
exit(exit_status);
}
if(stdin_bytes){
assert(close(pipe_stdin[0]) == 0);
bytes_written = write(pipe_stdin[1], stdin_bytes, stdin_bytes_len);
assert(bytes_written >= 0 && (size_t)bytes_written == stdin_bytes_len);
assert(close(pipe_stdin[1]) == 0);
}
assert(waitpid(pid, &status, 0) == pid);
assert(WIFEXITED(status));
assert(WEXITSTATUS(status) == expect_exit_status);
if(expect_ref_file){
sprintf(cmp_cmd, "cmp '%s' '%s'", PATH_TMP_FILE, expect_ref_file);
cmp_exit_status = system(cmp_cmd);
assert(cmp_exit_status == 0);
}
}
/**
* Test different failure scenarios.
*/
static void
test_all_errors(void){
int i;
/* Invalid argument. */
test_head_main(NULL, NULL, 0, NULL, EXIT_FAILURE, "-z", NULL);
/* Blank nlines. */
test_head_main("", NULL, 0, NULL, EXIT_FAILURE, NULL);
/* Invalid nlines character. */
test_head_main("9f", NULL, 0, NULL, EXIT_FAILURE, NULL);
/* nlines too large (assume unsigned 64 bit). */
test_head_main("18446744073709551616", NULL, 0, NULL, EXIT_FAILURE, NULL);
/* File does not exist. */
test_head_main(NULL, NULL, 0, NULL, EXIT_FAILURE, "/noexist.txt", NULL);
/* Failed to getline. */
g_test_seam_err_ctr_getline = 0;
test_head_main(NULL, NULL, 0, NULL, EXIT_FAILURE, "README.md", NULL);
g_test_seam_err_ctr_getline = -1;
/* Failed to fwrite file. */
g_test_seam_err_ctr_fwrite = 0;
test_head_main(NULL, NULL, 0, NULL, EXIT_FAILURE, "README.md", NULL);
g_test_seam_err_ctr_fwrite = -1;
/* File error indicator set. */
for(i = 0; i < 2; i++){
g_test_seam_err_ctr_ferror = i;
test_head_main(NULL, NULL, 0, NULL, EXIT_FAILURE, "README.md", NULL);
g_test_seam_err_ctr_ferror = -1;
}
/* Failed to fclose file. */
g_test_seam_err_ctr_fclose = 0;
test_head_main(NULL, NULL, 0, NULL, EXIT_FAILURE, "README.md", NULL);
g_test_seam_err_ctr_fclose = -1;
/* Failed to print banner. */
g_test_seam_err_ctr_printf = 0;
test_head_main(NULL,
NULL,
0,
NULL,
EXIT_FAILURE,
"README.md",
"README.md",
NULL);
g_test_seam_err_ctr_printf = -1;
/* Failed to print newline before banner. */
g_test_seam_err_ctr_putchar = 0;
test_head_main(NULL,
NULL,
0,
NULL,
EXIT_FAILURE,
"README.md",
"README.md",
NULL);
g_test_seam_err_ctr_putchar = -1;
/* First file does not exist. */
test_head_main(NULL,
NULL,
0,
"test/files/comb-noexist-1.txt",
EXIT_FAILURE,
"/noexist.txt",
"test/files/1.txt",
NULL);
/* Second file does not exist. */
test_head_main(NULL,
NULL,
0,
"test/files/comb-1-noexist.txt",
EXIT_FAILURE,
"test/files/1.txt",
"/noexist.txt",
NULL);
}
/**
* Run test cases where we send data through STDIN.
*/
static void
test_all_stdin(void){
const char *const stdin_bytes =
"1: line 1\n"
"2: line 2\n"
"3: line 3\n"
"4: line 4\n"
"5: line 5\n";
size_t stdin_bytes_len;
stdin_bytes_len = strlen(stdin_bytes);
/* Use STDIN. */
test_head_main(NULL,
stdin_bytes,
stdin_bytes_len,
"test/files/5.txt",
EXIT_SUCCESS,
NULL);
/* Fail to read from STDIN. */
g_test_seam_err_ctr_getline = 0;
test_head_main(NULL,
stdin_bytes,
stdin_bytes_len,
NULL,
EXIT_FAILURE,
NULL);
g_test_seam_err_ctr_getline = -1;
}
/**
* Run all test cases for the head utility.
*/
static void
test_all(void){
test_head_main(NULL,
NULL,
0,
"test/files/10.txt",
EXIT_SUCCESS,
"test/files/10.txt",
NULL);
test_head_main(NULL,
NULL,
0,
"test/files/comb-5-1.txt",
EXIT_SUCCESS,
"test/files/5.txt",
"test/files/1.txt",
NULL);
test_head_main(NULL,
NULL,
0,
"test/files/comb-1-10-1.txt",
EXIT_SUCCESS,
"test/files/1.txt",
"test/files/10.txt",
"test/files/1.txt",
NULL);
/* Print out 5 out of 10 lines in the input file. */
test_head_main("5",
NULL,
0,
"test/files/5.txt",
EXIT_SUCCESS,
"test/files/10.txt",
NULL);
/* Print 0 lines from the input file. */
test_head_main("0",
NULL,
0,
"test/files/0.txt",
EXIT_SUCCESS,
"test/files/10.txt",
NULL);
/* Print only 10 lines with higer nlimit. */
test_head_main("100",
NULL,
0,
"test/files/10.txt",
EXIT_SUCCESS,
"test/files/10.txt",
NULL);
/* Combine two 5-line outputs from 10 line file. */
test_head_main("5",
NULL,
0,
"test/files/comb-10-10_5.txt",
EXIT_SUCCESS,
"test/files/10.txt",
"test/files/10.txt",
NULL);
/* 98 lines from random file. */
test_head_main("98",
NULL,
0,
"build/test-rand.txt.98",
EXIT_SUCCESS,
"build/test-rand.txt",
NULL);
/* Maximum allowed nlines value (assume unsigned 64 bit). */
test_head_main("18446744073709551615",
NULL,
0,
"build/test-rand.txt",
EXIT_SUCCESS,
"build/test-rand.txt",
NULL);
/* File without ending newline. */
test_head_main(NULL,
NULL,
0,
"test/files/5-no-eol.txt",
EXIT_SUCCESS,
"test/files/5-no-eol.txt",
NULL);
test_all_stdin();
test_all_errors();
}
/**
* Test head utility.
*
* Usage: test
*
* @retval 0 All tests passed.
*/
int
main(void){
const size_t MAX_ARGS = 20;
const size_t MAX_ARG_LEN = 255;
size_t i;
g_argv = malloc(MAX_ARGS * sizeof(g_argv));
assert(g_argv);
for(i = 0; i < MAX_ARGS; i++){
g_argv[i] = malloc(MAX_ARG_LEN * sizeof(*g_argv));
assert(g_argv[i]);
}
g_argc = 0;
strcpy(g_argv[g_argc++], "head");
test_all();
for(i = 0; i < MAX_ARGS; i++){
free(g_argv[i]);
}
free(g_argv);
return 0;
}
|
somnisoft/head | test/test.h | /**
* @file
* @brief Test suite
* @author <NAME> (<EMAIL>)
*
* This software has been placed into the public domain using CC0.
*/
#ifndef HEAD_TEST_H
#define HEAD_TEST_H
#include <stdio.h>
int
head_main(int argc,
char *argv[]);
int
test_seam_fclose(FILE *stream);
int
test_seam_ferror(FILE *stream);
size_t
test_seam_fwrite(const void *ptr,
size_t size,
size_t nitems,
FILE *stream);
ssize_t
test_seam_getline(char **lineptr,
size_t *n,
FILE *stream);
int
test_seam_printf(const char *format, ...);
int
test_seam_putchar(int c);
extern int g_test_seam_err_ctr_fclose;
extern int g_test_seam_err_ctr_ferror;
extern int g_test_seam_err_ctr_fwrite;
extern int g_test_seam_err_ctr_getline;
extern int g_test_seam_err_ctr_printf;
extern int g_test_seam_err_ctr_putchar;
#endif /* HEAD_TEST_H */
|
Aveek-Saha/snek-qr | snek.c | #include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <conio.h>
#define height 20
#define width 40
char map[height][width], key;
int snake_len=0, block_list[height*width][2], x1=1, y1=0, alive=1;
void draw();
void move();
void spawnFood();
void controls();
void goToXY(int column, int line);
void change(int add_block);
int main() {
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = FALSE;
SetConsoleCursorInfo(consoleHandle, &info);
int x, y;
for (y = 0; y < height; ++y) {
for (x = 0; x < width; ++x) {
if (y == 0 || y == height - 1 || x == 0 || x == width - 1) {
map[y][x] = '#';
} else {
map[y][x] = ' ';
}
}
}
map[y][x] = 'O';
block_list[0][0] = height/2;
block_list[0][1] = width/2;
spawnFood();
while (alive) {
Sleep(150);
controls();
move();
draw();
}
}
void controls() {
if (_kbhit()) {
key = _getch();
}
if (key == 72) {
x1 = 0;
y1 = -1;
} else if (key == 80) {
x1 = 0;
y1 = 1;
} else if (key == 75) {
x1 = -1;
y1 = 0;
} else if (key == 77) {
x1 = 1;
y1 = 0;
}
}
void spawnFood() {
int x = rand() % (width - 3) + 1;
int y = rand() % (height - 3) + 1;
if (map[y][x] != 'O' && map[y][x] != 'o') {
map[y][x] = '*';
return;
}
}
void draw() {
int x, y;
for (y = 0; y < height; y++) {
goToXY(width/2, y);
for (x = 0; x < width; x++) {
printf("%c", map[y][x]);
}
printf("\n");
}
}
void change(int add_block) {
if (add_block)
snake_len++;
else
map[block_list[snake_len][0]][block_list[snake_len][1]] = ' ';
for (int i = snake_len; i >= 1; --i) {
block_list[i][0] = block_list[i-1][0];
block_list[i][1] = block_list[i-1][1];
}
block_list[0][0] += y1;
block_list[0][1] += x1;
map[block_list[0][0]][block_list[0][1]] = 'O';
}
void move() {
int y=block_list[0][0], x=block_list[0][1];
if (map[y + y1][x + x1] == ' ') {
change(0);
return;
} else if (map[y + y1][x + x1] == '*') {
map[y + y1][x + x1] = ' ';
change(0);
change(1);
spawnFood();
return;
} else if (map[y + y1][x + x1] == '#' || map[y + y1][x + x1] == 'O') {
alive = 0;
}
}
void goToXY(int column, int line) {
COORD coord;
coord.X = column;
coord.Y = line;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsole, coord);
} |
mozre/MegEngine | src/core/include/megbrain/utils/thread_pool.h | /**
* \file src/core/include/megbrain/utils/thread_pool.h
* MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
*
* Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
#pragma once
#include "megbrain/common.h"
#include "megbrain/system.h"
#include "megbrain/comp_node.h"
#include <atomic>
#include <condition_variable>
#include <functional>
#include <mutex>
#include <queue>
#include <thread>
#include <vector>
namespace mgb {
using MultiThreadingTask = thin_function<void(size_t, size_t)>;
using AffinityCallBack = thin_function<void(size_t)>;
/**
* \brief task element
*/
struct TaskElem {
//! the task to be execute
MultiThreadingTask task;
//! number of the parallelism
size_t nr_parallelism;
};
/**
* \brief Worker and related flag
*/
struct Worker {
public:
Worker(thin_function<void()>&& run) : thread{run} {}
~Worker() {
thread.join();
}
//! Worker thread
std::thread thread;
//! Indicate whether the Worker thread need run
std::atomic_bool work_flag{false};
//! Indicate whether the Worker thread have binding core
bool affinity_flag{false};
};
#if MGB_HAVE_THREAD
/**
* \brief ThreadPool execute the task in multi-threads(nr_threads>1) mode , it
* will fallback to single-thread mode if nr_thread is 1.
*/
class ThreadPool : public NonCopyableObj {
public:
//! Create thread-pool nr_threads thread_pool
ThreadPool(size_t nr_threads);
//! The main thread set the task, parallelism and worker flag to
//! notify other thread.
void add_task(const TaskElem& task_elem);
size_t nr_threads() const;
//! Set the affinity of all the threads
void set_affinity(AffinityCallBack affinity_cb);
void sync();
//! wake up all the threads from cv.wait(), when the thread pool is not
//! active, all the threads will go to sleep.
void active();
//! all the threads go to sleep which will reduce CPU occupation
void deactive();
~ThreadPool();
private:
size_t m_nr_threads = 1;
//! Indicate whether the main thread have binding
bool m_main_affinity_flag;
//! The callback binding the threads to cores
AffinityCallBack m_core_binding_function{nullptr};
//! All the sub task number
size_t m_nr_parallelism = 0;
std::atomic_bool m_stop{false};
std::atomic_bool m_active{false};
//! The executable funcition pointer
MultiThreadingTask m_task;
std::vector<Worker*> m_workers;
//! The task iter, when finished one, the m_all_task_iter sub 1
std::atomic_int m_task_iter{0};
//! The cv and mutex for threading activity
std::condition_variable m_cv;
std::mutex m_mutex;
std::mutex m_mutex_task;
};
#else
/**
* \brief ThreadPool execute the task in single thread mode
*/
class ThreadPool : public NonCopyableObj {
public:
ThreadPool(size_t) {}
void add_task(const TaskElem& task_elem);
void set_affinity(AffinityCallBack affinity_cb);
void active() {}
void deactive() {}
void sync() {}
~ThreadPool() {}
size_t nr_threads() const { return 1_z; }
};
#endif
} // namespace mgb
// vim: syntax=cpp.doxygen
|
sstamoulis/framework-esp8266-rtos-sdk-idf-platformio | examples/sdkconfig.h | <reponame>sstamoulis/framework-esp8266-rtos-sdk-idf-platformio<gh_stars>0
/*
*
* Automatically generated file; DO NOT EDIT.
* Espressif IoT Development Framework Configuration
*
*/
//#define TEST_CASE(...)
#define CONFIG_ESP_WIFI_SSID "wifi"
#define CONFIG_ESP_WIFI_PASSWORD "<PASSWORD>"
#define CONFIG_MAX_STA_CONN 4
#define CONFIG_USING_ESP_VFS 1
#define CONFIG_USING_SPIFFS 1
#define CONFIG_SPIFFS_USE_MAGIC_LENGTH 1
#define CONFIG_SPIFFS_MAX_PARTITIONS 3
#define CONFIG_SPIFFS_OBJ_NAME_LEN 32
#define CONFIG_SPIFFS_PAGE_SIZE 256
#define CONFIG_SPIFFS_GC_MAX_RUNS 10
//#define CONFIG_SPIFFS_CACHE_WR 1
//#define CONFIG_SPIFFS_CACHE 1
#define CONFIG_SPIFFS_META_LENGTH 4
#define CONFIG_SPIFFS_USE_MAGIC 1
#define CONFIG_SPIFFS_PAGE_CHECK 1
#define CONFIG_SPIFFS_USE_MTIME 1
#define CONFIG_FREERTOS_IDLE_TASK_STACKSIZE 1024
#define CONFIG_ESP8266_PHY_MAX_WIFI_TX_POWER 20
//#define CONFIG_ENABLE_PTHREAD 1
//#define CONFIG_ENABLE_MDNS 1
#define CONFIG_MDNS_MAX_SERVICES 10
#define CONFIG_MDNS_STACKSIZE 2048
//#define CONFIG_LWIP_IPV6 1
#define CONFIG_LWIP_NETIF_LOOPBACK 1
#define CONFIG_LWIP_IPV6_NUM_ADDRESSES 3
#define CONFIG_AWS_IOT_SDK 1
#define CONFIG_AWS_IOT_MQTT_HOST "a3l8rpjg868svp.iot.eu-central-1.amazonaws.com"
#define CONFIG_AWS_IOT_MQTT_PORT 8883
#define CONFIG_AWS_IOT_MQTT_TX_BUF_LEN 512
#define CONFIG_AWS_IOT_MQTT_RX_BUF_LEN 512
#define CONFIG_AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5
#define CONFIG_AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000
#define CONFIG_AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000
#define CONFIG_AWS_IOT_SHADOW_MAX_SIZE_OF_THING_NAME 20
#define CONFIG_AWS_IOT_SHADOW_MAX_JSON_TOKEN_EXPECTED 120
#define CONFIG_AWS_IOT_SHADOW_MAX_SIMULTANEOUS_ACKS 10
#define CONFIG_AWS_IOT_SHADOW_MAX_SIMULTANEOUS_THINGNAMES 10
#define CONFIG_AWS_IOT_SHADOW_MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 60
#define CONFIG_HTTPD_MAX_REQ_HDR_LEN 512
#define CONFIG_HTTPD_MAX_URI_LEN 512
#define CONFIG_ENABLE_BOOT_CHECK_SUM 1
#define CONFIG_IDF_TARGET_ESP8266 1
#define CONFIG_MBEDTLS_XTEA_C 1
#define CONFIG_TCP_RECVMBOX_SIZE 6
#define CONFIG_TCP_WND_DEFAULT 5840
#define CONFIG_PARTITION_TABLE_OFFSET 0x8000
#define CONFIG_TCPIP_ADAPTER_GLOBAL_DATA_LINK_IRAM 1
#define CONFIG_ESPTOOLPY_FLASHSIZE_4MB 1
#define CONFIG_FREERTOS_GLOBAL_DATA_LINK_IRAM 1
#define CONFIG_MQTT_RECV_BUFFER 2048
#define CONFIG_ESPTOOLPY_FLASHFREQ "40m"
#define CONFIG_MBEDTLS_KEY_EXCHANGE_RSA 1
#define CONFIG_CRYSTAL_USED_26MHZ 1
#define CONFIG_UDP_RECVMBOX_SIZE 6
#define CONFIG_MBEDTLS_AES_C 1
#define CONFIG_MBEDTLS_RSA_BITLEN_MIN 2048
#define CONFIG_ESPTOOLPY_FLASHSIZE "4MB"
#define CONFIG_LOG_DEFAULT_LEVEL_VERBOSE 1
#define CONFIG_LWIP_ICMP 1
#define CONFIG_MBEDTLS_SSL_PROTO_TLS1 1
#define CONFIG_SPI_FLASH_MODE 0x0
#define CONFIG_ESPTOOLPY_FLASHFREQ_40M 1
#define CONFIG_ESP_WIFI_IS_STATION 1
#define CONFIG_DEFAULT_MQTT_SECURITY 0
#define CONFIG_MBEDTLS_PEM_WRITE_C 1
#define CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN 4096
#define CONFIG_IP_LOST_TIMER_INTERVAL 120
#define CONFIG_APP1_SIZE 0xF0000
#define CONFIG_LWIP_GLOBAL_DATA_LINK_IRAM 1
#define CONFIG_CONSOLE_UART_BAUDRATE 74880
#define CONFIG_LWIP_MAX_SOCKETS 10
#define CONFIG_BOOTLOADER_CHECK_APP_SUM 1
#define CONFIG_SSL_USING_MBEDTLS 1
#define CONFIG_MONITOR_BAUD_74880B 1
#define CONFIG_NEWLIB_LIBRARY_LEVEL_NANO 1
#define CONFIG_TCP_MSS 1460
#define CONFIG_LWIP_RECV_BUFSIZE_DEFAULT 11680
#define CONFIG_ESP_UDP_SYNC_RETRY_MAX 5
#define CONFIG_ESP8266_CORE_GLOBAL_DATA_LINK_IRAM 1
#define CONFIG_LWIP_MAX_UDP_PCBS 4
#define CONFIG_ESPTOOLPY_BAUD 921600
#define CONFIG_ESPTOOLPY_AFTER_RESET 1
#define CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED 1
#define CONFIG_LWIP_DHCPS_MAX_STATION_NUM 8
#define CONFIG_TOOLPREFIX "xtensa-lx106-elf-"
#define CONFIG_MBEDTLS_RC4_DISABLED 1
#define CONFIG_CONSOLE_UART_NUM 0
#define CONFIG_APP1_OFFSET 0x10000
#define CONFIG_MQTT_USERNAME "espressif"
#define CONFIG_TCP_OVERSIZE_MSS 1
#define CONFIG_CONSOLE_UART_DEFAULT 1
#define CONFIG_MBEDTLS_X509_CRL_PARSE_C 1
#define CONFIG_SPI_FLASH_SIZE 0x400000
#define CONFIG_LWIP_DHCPS_LEASE_UNIT 60
#define CONFIG_TCPIP_TASK_STACK_SIZE 2048
#define CONFIG_TASK_WDT 1
#define CONFIG_MAIN_TASK_STACK_SIZE 3584
#define CONFIG_LWIP_MAX_ACTIVE_TCP 5
#define CONFIG_TASK_WDT_TIMEOUT_S 15
#define CONFIG_ESPTOOLPY_FLASHMODE "dio"
#define CONFIG_MBEDTLS_DHM_C 1
#define CONFIG_LWIP_ARP_TABLE_SIZE 10
#define CONFIG_ESPTOOLPY_BEFORE "default_reset"
#define CONFIG_LOG_DEFAULT_LEVEL 5
#define CONFIG_MAKE_WARN_UNDEFINED_VARIABLES 1
#define CONFIG_NO_TLS 1
#define CONFIG_V3_1 1
#define CONFIG_MAX_STA_CONN 4
#define CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE 1
#define CONFIG_BOOTLOADER_INIT_SPI_FLASH 1
#define CONFIG_LIBSODIUM_USE_MBEDTLS_SHA 1
#define CONFIG_TCP_SYNMAXRTX 6
#define CONFIG_LWIP_IGMP 1
#define CONFIG_PYTHON "python"
#define CONFIG_ESPTOOLPY_COMPRESSED 1
#define CONFIG_MBEDTLS_RSA_BITLEN_2048 1
#define CONFIG_PARTITION_TABLE_FILENAME "partitions_singleapp.csv"
#define CONFIG_TCP_SND_BUF_DEFAULT 2920
#define CONFIG_LWIP_DHCP_MAX_NTP_SERVERS 1
#define CONFIG_FREERTOS_TIMER_STACKSIZE 2048
#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_1 1
#define CONFIG_LWIP_SO_REUSE_RXTOALL 1
#define CONFIG_PARTITION_TABLE_SINGLE_APP 1
#define CONFIG_MBEDTLS_X509_CSR_PARSE_C 1
#define CONFIG_CLEAN_SESSION 1
#define CONFIG_DEFAULT_MQTT_VERSION 3
#define CONFIG_USING_NEW_ETS_VPRINTF 1
#define CONFIG_FLASHMODE_QIO 1
#define CONFIG_MQTT_KEEP_ALIVE 30
#define CONFIG_LWIP_DHCP_DOES_ARP_CHECK 1
#define CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE 1
#define CONFIG_ESPTOOLPY_ENABLE_TIME 1
#define CONFIG_TASK_WDT_TIMEOUT_15N 1
#define CONFIG_MBEDTLS_PEM_PARSE_C 1
#define CONFIG_LWIP_SOCKET_MULTITHREAD 1
#define CONFIG_TASK_SWITCH_FASTER 1
#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_2 1
#define CONFIG_LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT 10000
#define CONFIG_APP_UPDATE_CHECK_APP_SUM 1
#define CONFIG_FREERTOS_HZ 100
//#define CONFIG_LOG_COLORS 1
#define CONFIG_STACK_CHECK_NONE 1
#define CONFIG_LOG_BOOTLOADER_LEVEL 5
#define CONFIG_MBEDTLS_TLS_ENABLED 1
#define CONFIG_LWIP_MAX_RAW_PCBS 4
#define CONFIG_ESPTOOLPY_BEFORE_RESET 1
#define CONFIG_MQTT_SEND_CYCLE 30000
#define CONFIG_ESP_FILENAME_MACRO_NO_PATH 1
#define CONFIG_ESPTOOLPY_BAUD_OTHER_VAL 115200
#define CONFIG_MQTT_SEND_BUFFER 2048
#define CONFIG_SCAN_AP_MAX 32
#define CONFIG_ESP_UDP_SYNC_SEND 1
#define CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT 5
#define CONFIG_TCPIP_RECVMBOX_SIZE 32
#define CONFIG_TCP_MAXRTX 12
#define CONFIG_ESPTOOLPY_AFTER "hard_reset"
#define CONFIG_LWIP_SO_REUSE 1
#define CONFIG_LWIP_SO_REUSE 1
#define CONFIG_WIFI_PPT_TASKSTACK_SIZE 2048
#define CONFIG_LWIP_MAX_LISTENING_TCP 8
#define CONFIG_MBEDTLS_TLS_CLIENT 1
#define CONFIG_MONITOR_BAUD 74880
#define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions_singleapp.csv"
#define CONFIG_DEFAULT_MQTT_SESSION 1
#define CONFIG_MBEDTLS_HAVE_TIME 1
#define CONFIG_MBEDTLS_TLS_SERVER 1
#define CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT 1
#define CONFIG_MQTT_CLIENT_ID "espressif_sample"
#define CONFIG_FREERTOS_ISR_STACKSIZE 512
#define CONFIG_LWIP_IP_REASS_MAX_PBUFS 10
#define CONFIG_NEWLIB_ENABLE 1
#define CONFIG_OPENSSL_ASSERT_DO_NOTHING 1
#define CONFIG_SPI_FLASH_FREQ 0x0
#define CONFIG_OPTIMIZATION_LEVEL_DEBUG 1
#define CONFIG_DNS_MAX_SERVERS 2
#define CONFIG_LWIP_ARP_MAXAGE 300
#define CONFIG_LTM_FAST 1
#define CONFIG_MQTT_PING_TIMEOUT 3000
#define CONFIG_ESPTOOLPY_BAUD_921600B 1
#define CONFIG_MQTT_RECV_CYCLE 0
#define CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN 4096
#define CONFIG_MQTT_PASSWORD "<PASSWORD>"
#define CONFIG_RESET_REASON 1
#define CONFIG_FREERTOS_MAX_HOOK 2
#define CONFIG_SOC_IRAM_SIZE 0xC000
#define CONFIG_WIFI_TX_RATE_SEQUENCE_FROM_HIGH 1
#define CONFIG_SET_SOLINGER_DEFAULT 1
#define CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT 3072
#define CONFIG_MONITOR_BAUD_OTHER_VAL 74880
#define CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF 1
#define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0"
#define CONFIG_TASK_WDT_PANIC 1
#define CONFIG_EVENT_LOOP_STACK_SIZE 2048
#define CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS 1 |
orodley/chessboard | src/misc.h | #ifndef MISC_H_
#define MISC_H_
// Miscellaneous stuff
// I'm lazy
typedef unsigned int uint;
// Useful for GTK callbacks
#define IGNORE(x) (void)(x)
#endif // include guard
|
orodley/chessboard | src/chess/game.h | #ifndef GAME_H_
#define GAME_H_
#include "board.h"
#include "moves.h"
// Games are represented as trees where each node has an arbitrary number of
// children. This is to make variations easy to store. Linked lists are used
// to store the children for ease of inserting new elements.
struct Game;
typedef struct Game
{
Move move;
Board *board;
struct Game *parent;
struct Game *children;
struct Game *sibling;
} Game;
Game *new_game();
Game *add_child(Game *game, Move move);
Game *first_child(Game *game);
Game *root_node(Game *game);
Game *last_node(Game *game);
bool has_children(Game *game);
void free_game(Game *game);
#endif // include guard
|
orodley/chessboard | main.c | #include <assert.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
#include "chess/board.h"
#include "chess/game.h"
#include "chess/pgn.h"
#include "board_display.h"
void set_up_gui();
char *piece_svgs = "pieces/merida/";
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GError *err = NULL;
load_svgs(piece_svgs, &err);
if (err != NULL) {
printf("Error loading SVGs:\n%s\n", err->message);
return 1;
}
if (argc > 1) {
// If we get any args, we take them to be a PGN file to open
char *pgn_filename = argv[1];
PGN pgn;
if (!read_pgn(&pgn, pgn_filename, &err)) {
fprintf(stderr, "Failed to load PGN file '%s'", pgn_filename);
if (err == NULL)
putc('\n', stderr);
else
fprintf(stderr, ":\n%s", err->message);
return 1;
}
current_game = pgn.game;
} else {
current_game = new_game();
current_game->board = malloc(sizeof(Board));
bool success = from_fen(current_game->board, start_board_fen);
// This is a fixed string, it should never fail to be parsed
assert(success);
}
set_up_gui();
gtk_main();
return 0;
}
// Support older version of GTK in Travis
#if GTK_MAJOR_VERSION <= 3 && GTK_MINOR_VERSION < 10
GtkBuilder *gtk_builder_new_from_file(const gchar *filename)
{
GtkBuilder *builder = gtk_builder_new();
gtk_builder_add_from_file(builder, filename, NULL);
return builder;
}
#endif
void set_up_gui()
{
GtkBuilder *builder = gtk_builder_new_from_file("chessboard.ui");
GObject *window = gtk_builder_get_object(builder, "main_window");
g_signal_connect(window, "destroy",
G_CALLBACK(gtk_main_quit), NULL);
GObject *open_pgn_item = gtk_builder_get_object(builder, "open_pgn_menu_item");
g_signal_connect(open_pgn_item, "activate",
G_CALLBACK(open_pgn_callback), window);
GObject *flip_button = gtk_builder_get_object(builder, "flip_board_button");
g_signal_connect(flip_button, "clicked",
G_CALLBACK(flip_button_click_callback), NULL);
GObject *go_end_button = gtk_builder_get_object(builder, "go_end_button");
g_signal_connect(go_end_button, "clicked",
G_CALLBACK(go_end_button_click_callback), NULL);
go_next_button = GTK_WIDGET(gtk_builder_get_object(builder, "go_next_button"));
g_signal_connect(G_OBJECT(go_next_button), "clicked",
G_CALLBACK(go_next_button_click_callback), NULL);
go_back_button = GTK_WIDGET(gtk_builder_get_object(builder, "go_back_button"));
g_signal_connect(G_OBJECT(go_back_button), "clicked",
G_CALLBACK(go_back_button_click_callback), NULL);
GObject *go_start_button = gtk_builder_get_object(builder, "go_start_button");
g_signal_connect(go_start_button, "clicked",
G_CALLBACK(go_start_button_click_callback), NULL);
board_display = GTK_WIDGET(gtk_builder_get_object(builder, "board_drawing_area"));
gtk_widget_add_events(board_display,
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK);
g_signal_connect(G_OBJECT(board_display), "draw",
G_CALLBACK(board_draw_callback), NULL);
g_signal_connect(G_OBJECT(board_display), "button-press-event",
G_CALLBACK(board_mouse_down_callback), NULL);
g_signal_connect(G_OBJECT(board_display), "button-release-event",
G_CALLBACK(board_mouse_up_callback), NULL);
g_signal_connect(G_OBJECT(board_display), "motion-notify-event",
G_CALLBACK(board_mouse_move_callback), NULL);
gtk_widget_show_all(GTK_WIDGET(window));
// If we loaded a PGN file, we need to enable the forward button
set_button_sensitivity();
}
|
orodley/chessboard | src/chess/moves.c | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "board.h"
#include "moves.h"
// Assumes the move is legal. This is necessary as the easiest way to test
// whether a move doesn't put the moving player in check (illegal) is to
// perform the move and then test if they are in check.
void perform_move(Board *board, Move move)
{
Square start = START_SQUARE(move);
Square end = END_SQUARE(move);
Piece p = PIECE_AT_SQUARE(board, start);
Piece_type type = PIECE_TYPE(p);
board->half_move_clock++;
if (PLAYER(p) == BLACK)
board->move_number++;
// Check if we're capturing en passant
if (type == PAWN && end == board->en_passant)
PIECE_AT(board, SQUARE_X(end), PLAYER(p) == WHITE ? 4 : 3) = EMPTY;
// Check if this move enables our opponent to perform en passant
uint dy = SQUARE_Y(end) - SQUARE_Y(start);
if (type == PAWN && abs(dy) == 2) {
int en_passant_rank = PLAYER(p) == WHITE ? 2 : 5;
board->en_passant = SQUARE(SQUARE_X(start), en_passant_rank);
} else {
// Otherwise reset en passant
board->en_passant = NULL_SQUARE;
}
// Check if we're castling so we can move the rook too
uint dx = SQUARE_X(end) - SQUARE_X(start);
if (type == KING && abs(dx) > 1) {
uint y = PLAYER(p) == WHITE ? 0 : BOARD_SIZE - 1;
bool kingside = SQUARE_X(end) == 6;
if (kingside) {
PIECE_AT(board, 7, y) = EMPTY;
PIECE_AT(board, 5, y) = PIECE(PLAYER(p), ROOK);
} else {
PIECE_AT(board, 0, y) = EMPTY;
PIECE_AT(board, 3, y) = PIECE(PLAYER(p), ROOK);
}
}
// Check if we're depriving ourself of castling rights
Castling *c = &board->castling[PLAYER(p)];
if (type == KING) {
c->kingside = false;
c->queenside = false;
} else if (type == ROOK) {
if (SQUARE_X(start) == BOARD_SIZE - 1) {
c->kingside = false;
} else if (SQUARE_X(start) == 0) {
c->queenside = false;
}
}
// Check if we should reset the half-move clock
if (type == PAWN || PIECE_AT_SQUARE(board, end) != EMPTY)
board->half_move_clock = 0;
// Update the turn tracker
board->turn = OTHER_PLAYER(board->turn);
PIECE_AT_SQUARE(board, end) = PIECE_AT_SQUARE(board, start);
PIECE_AT_SQUARE(board, start) = EMPTY;
}
bool legal_move(Board *board, Move move, bool check_for_check)
{
Square start = START_SQUARE(move);
Square end = END_SQUARE(move);
int dx = SQUARE_X(end) - SQUARE_X(start);
int dy = SQUARE_Y(end) - SQUARE_Y(start);
Piece p = PIECE_AT_SQUARE(board, start);
Piece_type type = PIECE_TYPE(p);
Piece at_end_square = PIECE_AT_SQUARE(board, end);
// Can't move a piece that isn't there
if (p == EMPTY)
return false;
// Can only move if it's your turn
if (PLAYER(p) != board->turn)
return false;
// Can't capture your own pieces
if (at_end_square != EMPTY && PLAYER(at_end_square) == PLAYER(p))
return false;
// Can't "move" a piece by putting it back onto the same square
if (dx == 0 && dy == 0)
return false;
int ax = abs(dx);
int ay = abs(dy);
int x_direction = ax == 0 ? 0 : dx / ax;
int y_direction = ay == 0 ? 0 : dy / ay;
// Pieces other than knights are blocked by intervening pieces
if (type != KNIGHT) {
uint x = SQUARE_X(start) + x_direction;
uint y = SQUARE_Y(start) + y_direction;
while ((!(x == SQUARE_X(end) && y == SQUARE_Y(end))) &&
x < BOARD_SIZE && y < BOARD_SIZE) {
if (PIECE_AT(board, x, y) != EMPTY)
return false;
x += x_direction;
y += y_direction;
}
}
// Now handle each type of movement
bool legal_movement = false;
switch (type) {
case PAWN:
if ((PLAYER(p) == WHITE && SQUARE_Y(start) == 1) ||
(PLAYER(p) == BLACK && SQUARE_Y(start) == 6)) {
if (ay != 1 && ay != 2) {
legal_movement = false;
break;
}
} else if (ay != 1) {
legal_movement = false;
break;
}
if (y_direction != (PLAYER(p) == WHITE ? 1 : -1)) {
legal_movement = false;
break;
}
if (dx == 0) {
legal_movement = at_end_square == EMPTY;
break;
}
if (dx == 1 || dx == -1) {
legal_movement = (at_end_square != EMPTY &&
PLAYER(at_end_square) != PLAYER(p)) ||
end == board->en_passant;
break;
}
legal_movement = false;
break;
case KNIGHT:
legal_movement = (ax == 1 && ay == 2) || (ax == 2 && ay == 1);
break;
case BISHOP: legal_movement = ax == ay; break;
case ROOK: legal_movement = dx == 0 || dy == 0; break;
case QUEEN: legal_movement = ax == ay || dx == 0 || dy == 0; break;
case KING:
if (ax <= 1 && ay <= 1) {
legal_movement = true;
break;
}
if (SQUARE_Y(end) != (PLAYER(p) == WHITE ? 0 : BOARD_SIZE - 1)) {
legal_movement = false;
break;
}
if (SQUARE_X(end) == 6) {
legal_movement = can_castle_kingside(board, PLAYER(p));
break;
} else if (SQUARE_X(end) == 2) {
legal_movement = can_castle_queenside(board, PLAYER(p));
break;
} else {
legal_movement = false;
break;
}
case EMPTY: legal_movement = false; break;
}
if (!legal_movement)
return false;
// At this point everything looks fine. The only thing left to check is
// whether the move puts us in check. We've checked enough of the move
// that perform_move should be able to handle it.
if (check_for_check)
return !gives_check(board, move, PLAYER(p));
else
return legal_movement;
}
bool gives_check(Board *board, Move move, Player player)
{
Board copy;
copy_board(©, board);
perform_move(©, move);
return in_check(©, player);
}
bool gives_mate(Board *board, Move move, Player player)
{
Board copy;
copy_board(©, board);
perform_move(©, move);
return checkmate(©, player);
}
// Check whether we need to disambiguate between two pieces for a particular
// move. e.g.: there are two rooks that can move to the square. If so, return
// the location of the other piece that is confusing things.
static Square ambiguous_piece(Board *board, Move move)
{
Piece_type type = PIECE_TYPE(PIECE_AT_SQUARE(board, START_SQUARE(move)));
for (uint x = 0; x < BOARD_SIZE; x++) {
for (uint y = 0; y < BOARD_SIZE; y++) {
Square curr_square = SQUARE(x, y);
if (curr_square == START_SQUARE(move))
continue;
if (PIECE_TYPE(PIECE_AT_SQUARE(board, curr_square)) == type &&
legal_move(board, MOVE(curr_square, END_SQUARE(move)), true))
return curr_square;
}
}
return NULL_SQUARE;
}
// str should have space for at least 7 (MAX_ALGEBRAIC_NOTATION_LENGTH)
// characters, to be able to fit the longest of moves.
void algebraic_notation_for(Board *board, Move move, char *str)
{
uint i = 0;
Square start = START_SQUARE(move);
Square end = END_SQUARE(move);
Piece p = PIECE_AT_SQUARE(board, start);
Piece_type type = PIECE_TYPE(p);
// Castling
// TODO: Castling can cause a check or a mate - needs +/#
if (type == KING && abs(SQUARE_X(start) - SQUARE_X(end)) > 1) {
if (SQUARE_X(end) == 6)
strcpy(str, "O-O");
else
strcpy(str, "O-O-O");
return;
}
bool capture = PIECE_AT_SQUARE(board, END_SQUARE(move)) != EMPTY;
// Add the letter denoting the type of piece moving
if (type != PAWN)
str[i++] = "\0\0NBRQK"[type];
// Add the number/letter of the rank/file of the moving piece if necessary
Square ambig = ambiguous_piece(board, move);
// We always add the file if it's a pawn capture
if (ambig != NULL_SQUARE || (type == PAWN && capture)) {
char disambiguate;
if (SQUARE_X(ambig) == SQUARE_X(start))
disambiguate = RANK_CHAR(SQUARE_Y(start));
else
disambiguate = FILE_CHAR(SQUARE_X(start));
str[i++] = disambiguate;
}
// Add an 'x' if its a capture
if (capture)
str[i++] = 'x';
// Add the target square
str[i++] = FILE_CHAR(SQUARE_X(end));
str[i++] = RANK_CHAR(SQUARE_Y(end));
// Add a '#' if its mate
if (gives_mate(board, move, OTHER_PLAYER(PLAYER(p))))
str[i++] = '#';
// Add a '+' if its check
else if (gives_check(board, move, OTHER_PLAYER(PLAYER(p))))
str[i++] = '+';
str[i++] = '\0';
}
|
orodley/chessboard | test/pgn/test-pgn.c | <reponame>orodley/chessboard
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include "chess/pgn.h"
int main(int argc, char *argv[])
{
#if GLIB_MAJOR_VERION <= 2 && GLIB_MINOR_VERSION <= 34
g_type_init();
#endif
if (argc < 2) {
fprintf(stderr, "Usage: %s <pgn file>\n", argv[0]);
return 1;
}
PGN pgn;
GError *error = NULL;
if (!read_pgn(&pgn, argv[1], &error)) {
fprintf(stderr, "Failed to read PGN '%s'\n", argv[1]);
if (error != NULL)
fprintf(stderr, "%s\n", error->message);
return 1;
}
if (!write_pgn(&pgn, stdout)) {
fprintf(stderr, "Failed to write PGN '%s'\n", argv[1]);
return 1;
}
return 0;
}
|
orodley/chessboard | src/board_display.c | #include <gtk/gtk.h>
#include <librsvg/rsvg.h>
#ifndef RSVG_CAIRO_H
#include <librsvg/rsvg-cairo.h>
#endif
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "chess/board.h"
#include "chess/moves.h"
#include "chess/pgn.h"
#include "board_display.h"
#include "misc.h"
RsvgHandle *piece_images[2][6];
void load_svgs(char *dir, GError **err)
{
uint len = strlen(dir) + 8; // e.g.: "w_k.svg\0"
char str[len];
char piece_letters[] = "pnbrqk";
char side_letters[] = "bw";
for (uint i = 0; i < 2; i++) {
char side = side_letters[i];
for (uint j = 0; piece_letters[j] != '\0'; j++) {
sprintf(str, "%s%c_%c.svg", dir, side, piece_letters[j]);
piece_images[i][j] = rsvg_handle_new_from_file(str, err);
if (*err != NULL)
return;
}
}
}
static uint get_square_size(GtkWidget *board)
{
uint width = gtk_widget_get_allocated_width(board);
uint height = gtk_widget_get_allocated_height(board);
uint max_square_width = width / BOARD_SIZE;
uint max_square_height = height / BOARD_SIZE;
return max_square_width < max_square_height ?
max_square_width :
max_square_height;
}
Game *current_game;
GtkWidget *board_display;
GtkWidget *go_back_button;
GtkWidget *go_next_button;
bool board_flipped = false;
static Square drag_source = NULL_SQUARE;
static uint mouse_x;
static uint mouse_y;
void set_button_sensitivity()
{
gtk_widget_set_sensitive(go_back_button, current_game->parent != NULL);
gtk_widget_set_sensitive(go_next_button, has_children(current_game));
}
static void draw_piece(cairo_t *cr, Piece p, uint size)
{
RsvgHandle *piece_image =
piece_images[PLAYER(p)][PIECE_TYPE(p) - 1];
// 0.025 is a bit of a magic number. It's basically just the factor by
// which the pieces must be scaled in order to fit correctly with the
// default square size. We then scale that based on how big the squares
// actually are.
double scale = 0.025 * size / DEFAULT_SQUARE_SIZE;
cairo_scale(cr, scale, scale);
rsvg_handle_render_cairo(piece_image, cr);
cairo_scale(cr, 1 / scale, 1 / scale);
}
// This should be divisible by 2 so as not to leave a one pixel gap
#define HIGHLIGHT_LINE_WIDTH 4
gboolean board_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data)
{
IGNORE(data);
// Unless the width/height of the drawing area is exactly a multiple of 8,
// there's going to be some leftover space. We want to have the board
// completely centered, so we pad by half the leftover space.
// We rely on the widget being perfectly square in these calculations, as
// this is enforced by its containing aspect frame.
uint square_size = get_square_size(widget);
uint leftover_space =
gtk_widget_get_allocated_width(widget) - square_size * BOARD_SIZE;
uint padding = leftover_space / 2;
cairo_translate(cr, padding, padding);
// Color light squares one-by-one
cairo_set_line_width(cr, 0);
for (uint file = 0; file < BOARD_SIZE; file++) {
uint x = board_flipped ? BOARD_SIZE - file - 1 : file;
for (int rank = BOARD_SIZE - 1; rank >= 0; rank--) {
int y = board_flipped ? BOARD_SIZE - rank - 1 : rank;
if ((y + x) % 2 == 0) {
// dark squares
cairo_set_source_rgb(cr, 0.450980, 0.537255, 0.713725);
cairo_rectangle(cr, 0, 0, square_size, square_size);
cairo_fill(cr);
} else {
// light squares
cairo_set_source_rgb(cr, 0.952941, 0.952941, 0.952941);
cairo_rectangle(cr, 0, 0, square_size, square_size);
cairo_fill(cr);
}
// Highlight the source and target squares of the last move
Move last_move = current_game->move;
Square s = SQUARE(x, y);
if (last_move != NULL_MOVE &&
(s == START_SQUARE(last_move) || s == END_SQUARE(last_move))) {
cairo_set_source_rgb(cr, 0.225, 0.26, 0.3505);
cairo_set_line_width(cr, HIGHLIGHT_LINE_WIDTH);
cairo_translate(cr, HIGHLIGHT_LINE_WIDTH / 2, HIGHLIGHT_LINE_WIDTH / 2);
cairo_rectangle(cr, 0, 0, square_size - HIGHLIGHT_LINE_WIDTH,
square_size - HIGHLIGHT_LINE_WIDTH);
cairo_stroke(cr);
cairo_set_line_width(cr, 1);
cairo_translate(cr, -HIGHLIGHT_LINE_WIDTH / 2, -HIGHLIGHT_LINE_WIDTH / 2);
}
// Draw the piece, if there is one
Piece p;
if ((p = PIECE_AT(current_game->board, x, y)) != EMPTY &&
(drag_source == NULL_SQUARE || SQUARE(x, y) != drag_source)) {
draw_piece(cr, p, square_size);
}
cairo_translate(cr, 0, square_size);
}
cairo_translate(cr, square_size, -square_size * BOARD_SIZE);
}
if (drag_source != NULL_SQUARE) {
cairo_identity_matrix(cr);
cairo_translate(cr, padding + mouse_x - square_size / 2,
padding + mouse_y - square_size / 2);
draw_piece(cr, PIECE_AT_SQUARE(current_game->board, drag_source), square_size);
}
return FALSE;
}
static Square board_coords_to_square(GtkWidget *drawing_area, uint x, uint y)
{
uint square_size = get_square_size(drawing_area);
uint board_x = x / square_size;
uint board_y = y / square_size;
if (!board_flipped) {
board_y = BOARD_SIZE - 1 - board_y;
} else {
board_x = BOARD_SIZE - 1 - board_x;
}
return SQUARE(board_x, board_y);
}
// Start dragging a piece if the mouse is over one.
gboolean board_mouse_down_callback(GtkWidget *widget, GdkEvent *event,
gpointer user_data)
{
IGNORE(user_data);
GdkEventButton *e = (GdkEventButton *)event;
if (e->button != 1)
return FALSE;
Square clicked_square = board_coords_to_square(widget, e->x, e->y);
if (PIECE_AT_SQUARE(current_game->board, clicked_square) != EMPTY) {
drag_source = clicked_square;
}
return FALSE;
}
// Try to move a piece if we're currently dragging one
gboolean board_mouse_up_callback(GtkWidget *widget, GdkEvent *event,
gpointer user_data)
{
IGNORE(user_data);
GdkEventButton *e = (GdkEventButton *)event;
if (e->button != 1 || drag_source == NULL_SQUARE)
return FALSE;
Square drag_target = board_coords_to_square(widget, e->x, e->y);
Move m = MOVE(drag_source, drag_target);
if (legal_move(current_game->board, m, true)) {
char notation[MAX_ALGEBRAIC_NOTATION_LENGTH];
algebraic_notation_for(current_game->board, m, notation);
// TODO: Stop printing this when we have a proper move list GUI
if (current_game->board->turn == WHITE)
printf("%d. %s\n", current_game->board->move_number, notation);
else
printf(" ..%s\n", notation);
current_game = add_child(current_game, m);
set_button_sensitivity();
}
drag_source = NULL_SQUARE;
gtk_widget_queue_draw(widget);
return FALSE;
}
// Redraw if we're dragging a piece
gboolean board_mouse_move_callback(GtkWidget *widget, GdkEvent *event,
gpointer user_data)
{
IGNORE(user_data);
GdkEventButton *e = (GdkEventButton *)event;
// e->x and e->y are relative to the window, but we want coordinates
// relative to the chessboard drawing area.
// So we figure out where it is, and add that on.
gint wx, wy;
gtk_widget_translate_coordinates(widget, gtk_widget_get_toplevel(widget),
0, 0, &wx, &wy);
mouse_x = e->x + wx;
mouse_y = e->y + wy;
if (drag_source != NULL_SQUARE)
gtk_widget_queue_draw(widget);
return FALSE;
}
// Back up one move
gboolean go_back_button_click_callback(GtkWidget *widget, gpointer user_data)
{
IGNORE(widget);
IGNORE(user_data);
current_game = current_game->parent;
set_button_sensitivity();
gtk_widget_queue_draw(board_display);
return FALSE;
}
// Go forward one move
gboolean go_next_button_click_callback(GtkWidget *widget, gpointer user_data)
{
IGNORE(widget);
IGNORE(user_data);
current_game = first_child(current_game);
set_button_sensitivity();
gtk_widget_queue_draw(board_display);
return FALSE;
}
// Go to the start of the game
gboolean go_start_button_click_callback(GtkWidget *widget, gpointer user_data)
{
IGNORE(widget);
IGNORE(user_data);
current_game = root_node(current_game);
set_button_sensitivity();
gtk_widget_queue_draw(board_display);
return FALSE;
}
// Go to the end of the game
gboolean go_end_button_click_callback(GtkWidget *widget, gpointer user_data)
{
IGNORE(widget);
IGNORE(user_data);
current_game = last_node(current_game);
set_button_sensitivity();
gtk_widget_queue_draw(board_display);
return FALSE;
}
// Flip the board
gboolean flip_button_click_callback(GtkWidget *widget, gpointer user_data)
{
IGNORE(widget);
IGNORE(user_data);
board_flipped = !board_flipped;
gtk_widget_queue_draw(board_display);
return FALSE;
}
// Load a new game from a PGN file
void open_pgn_callback(GtkMenuItem *menu_item, gpointer user_data)
{
IGNORE(menu_item);
GtkWindow *parent = (GtkWindow *)user_data;
GtkWidget *dialog = gtk_file_chooser_dialog_new("Open PGN", parent,
GTK_FILE_CHOOSER_ACTION_OPEN,
"Cancel", GTK_RESPONSE_CANCEL,
"Open", GTK_RESPONSE_ACCEPT,
NULL);
GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog);
gtk_file_chooser_set_local_only(chooser, TRUE);
GtkFileFilter *just_pgns = gtk_file_filter_new();
gtk_file_filter_set_name(just_pgns, "PGN files");
gtk_file_filter_add_pattern(just_pgns, "*.pgn");
gtk_file_chooser_add_filter(chooser, just_pgns);
GtkFileFilter *all_files = gtk_file_filter_new();
gtk_file_filter_set_name(all_files, "All files");
gtk_file_filter_add_pattern(all_files, "*");
gtk_file_chooser_add_filter(chooser, all_files);
int result = gtk_dialog_run(GTK_DIALOG(dialog));
if (result == GTK_RESPONSE_ACCEPT) {
char *filename = gtk_file_chooser_get_filename(chooser);
PGN pgn;
GError *error = NULL;
bool success = read_pgn(&pgn, filename, &error);
g_free(filename);
if (!success) {
// TODO: Display an error dialog
puts("Failed to read the PGN");
return;
}
current_game = pgn.game;
gtk_widget_queue_draw(board_display);
set_button_sensitivity();
}
gtk_widget_destroy(dialog);
}
|
orodley/chessboard | src/board_display.h | #ifndef BOARD_DISPLAY_H_
#define BOARD_DISPLAY_H_
#include <stdbool.h>
#include <gtk/gtk.h>
#include "chess/board.h"
#include "chess/game.h"
#include "chess/moves.h"
#define DEFAULT_SQUARE_SIZE 50
void load_svgs(char *dir, GError **err);
void set_button_sensitivity();
gboolean board_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data);
gboolean board_mouse_down_callback(GtkWidget *widget, GdkEvent *event,
gpointer user_data);
gboolean board_mouse_up_callback(GtkWidget *widget, GdkEvent *event,
gpointer user_data);
gboolean board_mouse_move_callback(GtkWidget *widget, GdkEvent *event,
gpointer user_data);
gboolean go_back_button_click_callback(GtkWidget *widget, gpointer user_data);
gboolean go_next_button_click_callback(GtkWidget *widget, gpointer user_data);
gboolean go_start_button_click_callback(GtkWidget *widget, gpointer user_data);
gboolean go_end_button_click_callback(GtkWidget *widget, gpointer user_data);
gboolean flip_button_click_callback(GtkWidget *widget, gpointer user_data);
void open_pgn_callback(GtkMenuItem *menu_item, gpointer user_data);
extern Game *current_game;
extern GtkWidget *board_display;
extern GtkWidget *go_back_button;
extern GtkWidget *go_next_button;
#endif // include guard
|
orodley/chessboard | src/chess/moves.h | #ifndef MOVES_H_
#define MOVES_H_
//
// A move is represented as 4 bytes, with the start square in the two most
// significant bytes, and the end square in the two least significant
// bytes. Each pair of bytes has the file in the most significant byte, and
// the rank in the least significant byte.
typedef uint_fast32_t Move;
#define MOVE(start, end) ((Move)(((start) << 16) | (end)))
#define START_SQUARE(m) ((m) >> 16)
#define END_SQUARE(m) ((m) & 0xFFFF)
#define NULL_MOVE ((Move)(~((Move)0)))
#define FILE_CHAR(file) ('a' + (file))
#define CHAR_FILE(c) ((c) - 'a')
#define RANK_CHAR(rank) ('1' + (rank))
#define CHAR_RANK(c) ((c) - '1')
void perform_move(Board *board, Move move);
bool legal_move(Board *board, Move move, bool check_for_check);
bool gives_check(Board *board, Move move, Player player);
// Longest possible length of a move in algebraic notation.
// e.g. Raxd1+\0
#define MAX_ALGEBRAIC_NOTATION_LENGTH 7
void algebraic_notation_for(Board *board, Move move, char *str);
#endif // include guard
|
orodley/chessboard | src/chess/board.h | <gh_stars>1-10
#ifndef BOARD_H_
#define BOARD_H_
#include <stdbool.h>
#include <stdint.h>
#include "misc.h"
#define BOARD_SIZE 8
#define PLAYERS 2
typedef uint_fast16_t Square;
#define SQUARE(x, y) (((x) << 8) | (y))
#define SQUARE_X(s) ((s) >> 8)
#define SQUARE_Y(s) ((s) & 0xF)
#define NULL_SQUARE ((Square)(~((Square)0)))
// Pieces are represented as shorts, with the MSB used to store the color, and
// the rest equal to one of a bunch of constants for the type of piece.
typedef unsigned short Piece;
typedef enum Player
{
BLACK = 0,
WHITE = 1,
} Player;
#define OTHER_PLAYER(p) ((p) == WHITE ? BLACK : WHITE)
// The order of these matters
typedef enum Piece_type
{
EMPTY,
PAWN,
KNIGHT,
BISHOP,
ROOK,
QUEEN,
KING,
} Piece_type;
#define PIECE_TYPES 6
#define PLAYER(x) ((Player)((x) >> (sizeof(Piece) * 8 - 1)))
#define PIECE_TYPE(x) ((Piece_type)((x) & ~(1 << (sizeof(Piece) * 8 - 1))))
#define PIECE(p, t) ((Piece)(((p) << (sizeof(Piece) * 8 - 1)) | (t)))
#define NULL_PIECE ((unsigned short)-1)
typedef struct Castling
{
bool kingside;
bool queenside;
} Castling;
// The board is an array of pieces, plus some other information:
// * Whose turn it is
// * Castling availibility
// * En passant target square (if any)
// * Halfmoves since the last capture or pawn advance
// * Move number
//
// This is similar to FEN.
// The intention behind having all this information in the board object is so
// that no other information is required to determine any necessary information
// about a board position.
//
// However, this structure does not contain information necessary to determine
// if a draw can be claimed by threefold repetition. This is unlikely to
// matter, as the most common case of threefold repetition is perpetual check,
// in which case coming in part-way through does not matter. The other cases
// are rare enough that it doesn't seem worthwhile to overly complicate the
// board representation over them.
typedef struct Board
{
Player turn;
Castling castling[PLAYERS];
Square en_passant;
uint half_move_clock;
uint move_number;
Piece pieces[BOARD_SIZE * BOARD_SIZE];
} Board;
#define PIECE_AT(b, x, y) ((b)->pieces[((y) * BOARD_SIZE) + (x)])
#define PIECE_AT_SQUARE(b, square) PIECE_AT(b, SQUARE_X(square), SQUARE_Y(square))
void copy_board(Board *dst, Board *src);
Piece piece_from_char(char c);
char char_from_piece(Piece p);
bool from_fen(Board *board, const char *fen_str);
void print_board(Board *b);
bool in_check(Board *board, Player p);
bool checkmate(Board *board, Player p);
bool can_castle_kingside(Board *board, Player p);
bool can_castle_queenside(Board *board, Player p);
extern char *start_board_fen;
#endif // include guard
|
orodley/chessboard | src/chess/game.c | #include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include "board.h"
#include "game.h"
Game *new_game()
{
Game *game = malloc(sizeof(Game));
game->move = NULL_MOVE;
game->board = NULL;
game->parent = NULL;
game->children = NULL;
game->sibling = NULL;
return game;
}
Game *add_child(Game *game, Move move)
{
Board *board = malloc(sizeof *board);
copy_board(board, game->board);
perform_move(board, move);
Game *children = game->children;
while (children != NULL && children->sibling != NULL &&
children->move != move)
children = children->sibling;
if (children != NULL && children->move == move) {
free(board);
return children;
} else {
Game *new_node = new_game();
new_node->move = move;
new_node->board = board;
new_node->parent = game;
if (children == NULL)
game->children = new_node;
else
children->sibling = new_node;
return new_node;
}
}
Game *first_child(Game *game)
{
return game->children;
}
Game *root_node(Game *game)
{
while (game->parent != NULL)
game = game->parent;
return game;
}
Game *last_node(Game *game)
{
while (game->children != NULL)
game = game->children;
return game;
}
bool has_children(Game *game)
{
return game->children != NULL;
}
void free_game(Game *game)
{
free(game->board);
if (game->sibling != NULL)
free_game(game->sibling);
if (game->children != NULL)
free_game(game->sibling);
}
|
orodley/chessboard | src/chess/pgn.h | <reponame>orodley/chessboard
#include <glib.h>
#include "game.h"
// PGN spec, section 7
// Numbers are one higher to include null-termination
#define MAX_SYMBOL_LENGTH 256
#define MAX_STRING_LENGTH 256
typedef enum Result
{
WHITE_WINS,
BLACK_WINS,
DRAW,
OTHER,
} Result;
#define NULL_RESULT ((Result)~((Result)0))
typedef struct PGN
{
GHashTable *tags;
Result result;
Game *game;
} PGN;
bool read_pgn(PGN *pgn, const char *input_filename, GError **error);
bool write_pgn(PGN *pgn, FILE *file);
|
orodley/chessboard | src/chess/board.c | <gh_stars>1-10
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "board.h"
#include "misc.h"
#include "moves.h"
void copy_board(Board *dst, Board *src)
{
dst->turn = src->turn;
dst->castling[0] = src->castling[0];
dst->castling[1] = src->castling[1];
dst->en_passant = src->en_passant;
dst->half_move_clock = src->half_move_clock;
dst->move_number = src->move_number;
for (uint x = 0; x < BOARD_SIZE; x++)
for (uint y = 0; y < BOARD_SIZE; y++)
PIECE_AT(dst, x, y) = PIECE_AT(src, x, y);
}
// Converts a character into a piece, using the standard used in PGN and FEN.
Piece piece_from_char(char c)
{
Player player = isupper(c) ? WHITE : BLACK;
switch (tolower(c)) {
case 'p': return PIECE(player, PAWN);
case 'n': return PIECE(player, KNIGHT);
case 'b': return PIECE(player, BISHOP);
case 'r': return PIECE(player, ROOK);
case 'q': return PIECE(player, QUEEN);
case 'k': return PIECE(player, KING);
default: return EMPTY;
}
}
// Converts a piece into a char, using the standard used in PGN and FEN
char char_from_piece(Piece p)
{
switch (PIECE_TYPE(p)) {
case PAWN: return 'P';
case KNIGHT: return 'N';
case BISHOP: return 'B';
case ROOK: return 'R';
case QUEEN: return 'Q';
case KING: return 'K';
default: return ' ';
}
}
char *start_board_fen =
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
// Initializes a Board given a string containing Forsyth-Edwards Notation (FEN)
// See <http://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation> for a
// description, and <http://kirill-kryukov.com/chess/doc/fen.html> for the spec
// TODO: this is way too fucking long
bool from_fen(Board *board, const char *fen_str)
{
uint i = 0;
for (int y = BOARD_SIZE - 1; y >= 0; y--) {
char c;
uint x = 0;
while ((c = fen_str[i++]) != '/' && c != ' ') {
if (isdigit(c)) {
if (c == '0') // "Skip zero files" makes no sense
return false;
for (int n = 0; n < c - '0'; n++)
PIECE_AT(board, x + n, y) = EMPTY;
x += c - '0';
continue;
} else {
PIECE_AT(board, x, y) = piece_from_char(c);
}
x++;
}
}
char player = fen_str[i++];
if (player == 'w')
board->turn = WHITE;
else if (player == 'b')
board->turn = BLACK;
else
return false;
if (fen_str[i++] != ' ')
return false;
Castling b_castling = { false, false };
Castling w_castling = { false, false };
char c;
while ((c = fen_str[i++]) != ' ') {
switch (c) {
case 'K': w_castling.kingside = true; break;
case 'Q': w_castling.queenside = true; break;
case 'k': b_castling.kingside = true; break;
case 'q': b_castling.queenside = true; break;
case '-': break;
default: return false;
}
}
board->castling[BLACK] = b_castling;
board->castling[WHITE] = w_castling;
char file_char = fen_str[i++];
if (file_char == '-') {
board->en_passant = NULL_SQUARE;
} else {
if (file_char < 'a' || file_char > 'g')
return false;
char rank_char = fen_str[i++];
if (!isdigit(rank_char))
return false;
board->en_passant = SQUARE(file_char - 'a', rank_char - '1');
}
if (fen_str[i++] != ' ')
return false;
uint half_move_clock;
if (sscanf(fen_str + i, "%u", &half_move_clock) != 1)
return false;
board->half_move_clock = half_move_clock;
while (fen_str[i++] != ' ')
;
uint move_number;
if (sscanf(fen_str + i, "%u", &move_number) != 1)
return false;
board->move_number = move_number;
// TODO: check there's no trailing shit after a valid FEN string?
return true;
}
// For debugging
void print_board(Board *b)
{
puts("..........");
for (int y = BOARD_SIZE - 1; y >= 0; y--) {
putchar('.');
for (uint x = 0; x < BOARD_SIZE; x++) {
Piece p = PIECE_AT(b, x, y);
char c = char_from_piece(p);
putchar(PLAYER(p) == BLACK ? tolower(c) : c);
}
puts(".");
}
puts("..........");
printf("%s to move\n", b->turn == WHITE ? "White" : "Black");
}
static Square find_piece_looking_at(Board *board, Square square, Player piece_owner)
{
// We need to make sure we don't have infinite recursion in legal_move.
// This can happen with looking for checks - we need to see if there are
// any moves that put us in check to decide if the move is legal, but to
// see if we are in check we need to look at all the moves our opponent
// can make. And checking those moves will follow the same process.
//
// However, we don't actually need to see if the moves put us into check in
// this case, as it doesn't matter if taking their king puts us in check;
// we've already won.
bool care_about_check = PIECE_TYPE(PIECE_AT_SQUARE(board, square)) != KING;
Player initial_turn = board->turn;
board->turn = piece_owner;
Square ret = NULL_SQUARE;
for (uint y = 0; y < BOARD_SIZE; y++) {
for (uint x = 0; x < BOARD_SIZE; x++) {
Piece p = PIECE_AT(board, x, y);
Square s = SQUARE(x, y);
Move m = MOVE(s, square);
if (PLAYER(p) == piece_owner &&
legal_move(board, m, care_about_check)) {
ret = s;
goto cleanup;
}
}
}
cleanup:
board->turn = initial_turn;
return ret;
}
static Square find_attacking_piece(Board *board, Square square, Player attacker)
{
// The easiest way to do this without duplicating logic from legal_move
// is to put an enemy piece there and then check if moving there is legal.
// This will trigger the logic in legal_move for pawn captures.
Piece initial_piece = PIECE_AT_SQUARE(board, square);
PIECE_AT_SQUARE(board, square) =
PIECE(OTHER_PLAYER(attacker), PAWN);
Square s = find_piece_looking_at(board, square, attacker);
PIECE_AT_SQUARE(board, square) = initial_piece;
return s;
}
static bool under_attack(Board *board, Square square, Player attacker)
{
return find_attacking_piece(board, square, attacker) != NULL_SQUARE;
}
static Square find_king(Board *board, Player p)
{
Piece king = PIECE(p, KING);
for (uint y = 0; y < BOARD_SIZE; y++)
for (uint x = 0; x < BOARD_SIZE; x++)
if (PIECE_AT(board, x, y) == king)
return SQUARE(x, y);
return NULL_SQUARE;
}
bool in_check(Board *board, Player p)
{
Square king_location = find_king(board, p);
assert(king_location != NULL_SQUARE); // both players should have a king
return under_attack(board, king_location, OTHER_PLAYER(p));
}
// This could be more simply written as "number of legal moves = 0", if the
// enumeration of all legal moves is implemented at some point.
// As it is we don't have that, so this is simpler.
bool checkmate(Board *board, Player p)
{
// We must be in check
if (!in_check(board, p))
return false;
Square king_location = find_king(board, p);
Player other = OTHER_PLAYER(p);
int x = SQUARE_X(king_location);
int y = SQUARE_Y(king_location);
// Can the king move out of check?
for (int dx = -1; dx < 2; dx++) {
for (int dy = -1; dy < 2; dy++) {
if (x + dx < 0 || x + dx >= BOARD_SIZE ||
y + dy < 0 || y + dy >= BOARD_SIZE)
continue;
Move m = MOVE(king_location, SQUARE(x + dx, y + dy));
if (legal_move(board, m, true))
return false;
}
}
// Can the attacking piece be captured?
Square attacker = find_attacking_piece(board, king_location, other);
if (under_attack(board, attacker, p))
return false;
// Can we block?
Piece_type type = PIECE_TYPE(PIECE_AT_SQUARE(board, attacker));
if (type != KNIGHT) {
int dx = SQUARE_X(attacker) - x;
int dy = SQUARE_Y(attacker) - y;
int ax = abs(dx);
int ay = abs(dy);
int x_direction = ax == 0 ? 0 : dx / ax;
int y_direction = ay == 0 ? 0 : dy / ay;
uint x = SQUARE_X(king_location) + x_direction;
uint y = SQUARE_Y(king_location) + y_direction;
while (!(x == SQUARE_X(attacker) &&
y == SQUARE_Y(attacker))) {
Square blocker = find_piece_looking_at(board, SQUARE(x, y), p);
if (blocker != NULL_SQUARE &&
PIECE_TYPE(PIECE_AT_SQUARE(board, blocker)) != KING)
return false;
x += x_direction;
y += y_direction;
}
}
// All outta luck
return true;
}
bool can_castle_kingside(Board *board, Player p)
{
uint y = p == WHITE ? 0 : BOARD_SIZE - 1;
Player other = OTHER_PLAYER(p);
return board->castling[p].kingside && !in_check(board, p) &&
PIECE_AT(board, 5, y) == EMPTY &&
PIECE_AT(board, 6, y) == EMPTY &&
!under_attack(board, SQUARE(5, y), other) &&
!under_attack(board, SQUARE(6, y), other);
}
bool can_castle_queenside(Board *board, Player p)
{
uint y = p == WHITE ? 0 : BOARD_SIZE - 1;
Player other = OTHER_PLAYER(p);
return board->castling[p].queenside && !in_check(board, p) &&
PIECE_AT(board, 3, y) == EMPTY &&
PIECE_AT(board, 2, y) == EMPTY &&
PIECE_AT(board, 1, y) == EMPTY &&
!under_attack(board, SQUARE(3, y), other) &&
!under_attack(board, SQUARE(2, y), other) &&
!under_attack(board, SQUARE(1, y), other);
}
|
jacobussystems/IoTJackAC1 | src/StringList.h | <reponame>jacobussystems/IoTJackAC1<gh_stars>0
/*
StringList.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#else
#include "stdafx.h"
#endif
#include "Globals.h"
class Dynamic;
class StringList
{
protected:
char* _Buffer;
int _Length; // total length of all items
virtual bool Put_ExistingBuffer(int index, const char* text, int itemIncrease);
virtual bool Put_NewBuffer(int index, const char* text, int itemIncrease, char* newBuffer, int newSize);
public:
bool AutoExpand;
uint8_t Count;
int Size; // allocated length of '_Buffer'
StringList(int size = 20, bool autoExpand = true);
~StringList();
virtual bool Add(const char* text);
virtual bool Add(Dynamic* value);
virtual void Clear(bool full = false);
virtual const char* Get(int index, bool quiet = true);
virtual int IndexOf(const char* text, bool ignoreCase = true);
virtual void LogIt();
virtual bool Put(int index, const char* text);
virtual bool Remove(int index);
virtual bool SetBuffer(int size);
};
|
jacobussystems/IoTJackAC1 | ArdJackW/src/stdafx.h | <reponame>jacobussystems/IoTJackAC1<filename>ArdJackW/src/stdafx.h
#pragma once
#ifndef STRICT
#define STRICT
#endif
#ifndef WINVER
#define WINVER 0x0600
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x600
#endif
#ifndef _WIN32_WINDOWS
#define _WIN32_WINDOWS 0x600
#endif
#ifndef _WIN32_IE
#define _WIN32_IE 0x0600
#endif
#define VC_EXTRALEAN //Exclude rarely-used stuff from Windows headers
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS //some CString constructors will be explicit
#define _AFX_ALL_WARNINGS //turns off MFC's hiding of some common and often safely ignored warning messages
#define _ATL_NO_AUTOMATIC_NAMESPACE
#ifndef _SECURE_ATL
#define _SECURE_ATL 1 //Use the Secure C Runtime in ATL
#endif
#include <windows.h>
#include <atlstr.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
|
jacobussystems/IoTJackAC1 | src/Table.h | /*
Table.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#else
#include "stdafx.h"
#endif
#include "Globals.h"
struct TableColumnDef
{
uint8_t Alignment; // enumeration ARDJACK_HORZ_ALIGN_CENTRE, etc.
char Caption[ARDJACK_MAX_NAME_LENGTH];
uint8_t Padding; // padding (left and right)
uint8_t Width; // total width, including padding
};
// A 'pseudo Table', to aid formatting text output.
class Table
{
protected:
virtual char* AddLeftMargin(char* text);
public:
uint8_t ColumnCount;
TableColumnDef* ColumnDefs[ARDJACK_MAX_TABLE_COLUMNS];
char HorzLineChar;
uint8_t LeftMargin;
uint16_t TotalWidth;
char VertLineChar;
Table();
~Table();
virtual bool AddColumn(const char* caption, int width = 10, int align = ARDJACK_HORZ_ALIGN_LEFT, int padding = 1);
virtual char* Cell(char* text, const char* colText, int col);
virtual char* Header(char* text);
virtual char* HorizontalLine(char* text);
virtual char* Row(char* text, const char* col0 = "", const char* col1 = "", const char* col2 = "",
const char* col3 = "", const char* col4 = "", const char* col5 = "", const char* col6 = "", const char* col7 = "",
const char* col8 = "", const char* col9 = "", const char* col10 = "", const char* col11 = "");
};
|
jacobussystems/IoTJackAC1 | src/EthernetInterface.h | /*
EthernetInterface.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include "DetectBoard.h"
#include "Globals.h"
#ifdef ARDJACK_ETHERNET_AVAILABLE
#include <arduino.h>
#include <Ethernet.h>
#include "IoTObject.h"
#include "NetworkInterface.h"
class EthernetInterface : public NetworkInterface
{
protected:
EthernetClient _Client;
int _ConnectMode; // connect mode enumeration: ARDJACK_WIFI_CONNECT_OPEN, etc.
char _ConnectModeStr[20];
int _CSPin;
char _DHCPHostname[30];
int _Status;
virtual bool Connect();
virtual bool Disconnect();
virtual bool GetConnectionInfo();
virtual char* GetStatusAsString(int status, char *out);
public:
IPAddress DnsIp;
IPAddress GatewayIp;
IPAddress LocalIp;
byte MacAddress[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
IPAddress SubnetMask;
EthernetInterface(const char* name);
virtual bool Activate() override;
virtual bool AddConfig() override;
virtual bool Deactivate() override;
virtual DateTime* GetNetworkTime(DateTime* out) override;
virtual void LogStatus(bool refresh = false) override;
virtual bool LookupHost(const char* host, IPAddress& ipAddress) override;
virtual bool Ping(const char* host) override;
};
#endif
#endif
|
jacobussystems/IoTJackAC1 | src/RtcClock.h | /*
RtcClock.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
// Arduino only.
#ifdef ARDUINO
#include <arduino.h>
#include "DetectBoard.h"
#ifdef ARDJACK_RTC_AVAILABLE
#include "DateTime.h"
#include "IoTClock.h"
#ifdef ARDJACK_ARDUINO_DUE
#include <RTCDue.h>
#endif
#ifdef ARDJACK_ARDUINO_MKR
#include <RTCZero.h>
#endif
#ifdef ARDJACK_FEATHER_M0
#include <RTCZero.h>
#endif
class RtcClock : public IoTClock
{
protected:
unsigned long _RolloverMillis; // millis() when 'seconds roll-over' was last detected
DateTime _RolloverTime; // time when 'seconds roll-over' was last detected
#ifdef ARDJACK_USE_RTCZERO
RTCZero _RTClock;
#else
RTCDue _RTClock = RTCDue(XTAL);
#endif
virtual void AdjustMilliseconds();
virtual void CheckRollover(DateTime* dt);
virtual void Rollover(DateTime* dt);
public:
RtcClock();
~RtcClock();
virtual bool GetDate(int *day, int *month, int *year, bool utc = false) override;
virtual bool Now(DateTime* dt, bool utc = false) override;
virtual bool GetTime(int *hours, int *minutes, int *seconds, bool utc = false) override;
virtual bool SetDate(int day, int month, int year, bool utc = false) override;
virtual bool SetDateTime(DateTime* dt, bool utc = false) override;
virtual bool SetTime(int hours, int minutes, int seconds, bool utc = false) override;
virtual bool Start(int day, int month, int year, int hours, int minutes, int seconds, bool utc = false) override;
virtual bool Stop() override;
};
#endif
#endif
|
jacobussystems/IoTJackAC1 | src/Part.h | /*
Part.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#else
#include "stdafx.h"
#endif
#include "Dynamic.h"
#include "Globals.h"
class Configuration;
class Filter;
class StringList;
class Part
{
protected:
public:
Configuration* Config;
Filter* Filt;
char FilterName[ARDJACK_MAX_NAME_LENGTH];
bool IsNew;
uint8_t ItemCount;
#ifdef ARDJACK_INCLUDE_MULTI_PARTS
Part* Items[ARDJACK_MAX_MULTI_PART_ITEMS]; // array of 'Part'
#endif
bool LastChangeState; // last change state, for debounce filtering
int LastChangeTime; // last change time (ms), for debounce filtering
char Name[ARDJACK_MAX_NAME_LENGTH];
int NotifiedTime; // last notified time (ms)
Dynamic NotifiedValue; // last notified value
bool Notifying; // send a notification when this Part's value changes?
uint8_t Pin; // pin / GPIO channel / channel etc.
uint8_t Subtype;
uint8_t Type;
Dynamic Value; // normally, a numeric value
Part();
~Part();
virtual bool Activate();
virtual bool AddConfig();
virtual bool CheckChange();
virtual bool Configure(Device* dev, StringList* settings, int start, int count);
#ifdef ARDJACK_INCLUDE_MULTI_PARTS
virtual bool ConfigureMulti(const char* text);
#endif
virtual bool Deactivate();
virtual char* GetConfigStr(char* out);
virtual bool IsAnalog();
virtual bool IsAnalogInput();
virtual bool IsAnalogOutput();
virtual bool IsDigital();
virtual bool IsDigitalInput();
virtual bool IsDigitalOutput();
virtual bool IsInput();
virtual bool IsOutput();
virtual bool IsTextual();
virtual bool Poll();
virtual bool Read(Dynamic* value);
virtual bool Write(Dynamic* value);
};
|
jacobussystems/IoTJackAC1 | src/IoTObject.h | /*
IoTObject.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#else
#include "stdafx.h"
#endif
#include "Configuration.h"
#include "Globals.h"
class StringList;
class IoTObject
{
protected:
bool _Active;
virtual bool Activate();
virtual bool ConfigureProperty(const char* propName, const char* propValue, const char* text);
virtual bool Deactivate();
public:
Configuration* Config;
char Name[ARDJACK_MAX_NAME_LENGTH];
uint8_t Subtype; // enumeration, e.g. ARDJACK_CONNECTION_SUBTYPE_SERIAL
uint8_t Type; // enumeration, e.g. ARDJACK_OBJECT_TYPE_BRIDGE
IoTObject(const char* name);
~IoTObject();
virtual bool Active();
virtual bool AddConfig();
virtual bool ApplyConfig(bool quiet = false);
virtual bool Configure(const char* entity, StringList* settings, int start, int count);
virtual bool Poll();
virtual bool SetActive(bool state);
virtual bool Special(int action);
virtual const char* ToString(char* text);
virtual bool ValidateConfig(bool quiet = false);
};
|
jacobussystems/IoTJackAC1 | src/Route.h | <gh_stars>0
/*
Route.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#else
#include "stdafx.h"
#endif
#include "FifoBuffer.h"
#include "IoTMessage.h"
#include "MessageFilter.h"
class Connection;
class Device;
class Route;
class IoTMessage;
typedef void(*Route_Callback)(void* caller, Route* route, IoTMessage* msg);
class Route
{
protected:
public:
bool AlwaysUse;
FifoBuffer *Buffer; // a 'FifoBuffer' (for asynchronous working)
Route_Callback Callback; // a callback (for synchronous working)
void* CallbackObj; // callback object (for synchronous working)
MessageFilter Filter;
char Name[ARDJACK_MAX_NAME_LENGTH];
bool StopOnRouted;
Device* Target; // set if the Route is created by a Device
//char Target[ARDJACK_MAX_NAME_LENGTH]; // target object (for types: Command, Request, Response)
int Type;
Route(const char* name, int type = ARDJACK_ROUTE_TYPE_NONE);
static char* GetTypeName(int type, char* out);
virtual bool Handle(IoTMessage* msg);
virtual void SetTextFilter(const char* text, int operation = ARDJACK_STRING_COMPARE_STARTS_WITH);
};
|
jacobussystems/IoTJackAC1 | src/ArduinoClock.h | /*
ArduinoClock.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
// Arduino only.
#ifdef ARDUINO
#include <arduino.h>
//#include "DateTime.h"
#include "IoTClock.h"
class ArduinoClock : public IoTClock
{
protected:
unsigned long _InitialMillis; // millis() when 'Start' was last called
DateTime _InitialTime; // the set time when 'Start' was last called
public:
ArduinoClock();
~ArduinoClock();
virtual bool Now(DateTime* dt) override;
virtual long NowMs() override;
virtual bool NowUtc(DateTime* dt) override;
virtual bool SetDate(int day, int month, int year, bool utc = false) override;
virtual bool SetDateTime(DateTime* dt, bool utc = false) override;
virtual bool SetTime(int hours, int minutes, int seconds, bool utc = false) override;
virtual bool Start(int day, int month, int year, int hours, int minutes, int seconds, bool utc = false) override;
virtual bool Stop() override;
};
#endif
|
jacobussystems/IoTJackAC1 | src/PersistentFileManager.h | /*
PersistentFileManager.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#include "DetectBoard.h"
#include "FlashLibrary.h"
//#ifdef ARDJACK_FLASH_AVAILABLE
// #ifdef ARDJACK_ARDUINO_DUE
// #include <FlashAsEEPROM.h>
// #else
// #include <FlashStorage.h>
// #endif
//#endif
#else
#include "stdafx.h"
#endif
#include "Globals.h"
#ifdef ARDJACK_INCLUDE_PERSISTENCE
#include "DateTime.h"
#include "Log.h"
#include "PersistentFile.h"
#include "Utils.h"
class PersistentFileManager
{
protected:
#ifdef ARDUINO
int _LineCount; // total no.of persisted lines in flash
bool _Writing;
#ifdef ARDJACK_FLASH_AVAILABLE
FlashStorageClass<PersistentFileLine>* _Lines[ARDJACK_MAX_PERSISTED_LINES];
virtual bool WriteFlash(const char* line, int index);
#endif
#endif
public:
int FileCount;
PersistentFile Files[ARDJACK_MAX_PERSISTED_FILES];
PersistentFileManager();
#ifdef ARDUINO
virtual bool Close(PersistentFile* file);
virtual bool Puts(PersistentFile* file, const char* line);
virtual bool Scan();
virtual void SetWriting(bool value);
virtual bool Writing();
#ifdef ARDJACK_FLASH_AVAILABLE
virtual FlashStorageClass<PersistentFileLine>* GetLine(PersistentFile* file, int index);
#endif
#else
virtual bool Scan(const char* folder);
#endif
virtual bool Clear();
virtual bool List();
virtual bool LoadIniFile(const char* name);
virtual PersistentFile* Lookup(const char* name, bool autoCreate = false);
};
#endif
|
jacobussystems/IoTJackAC1 | ArdJackW/src/TestBase.h | #pragma once
#include "CppUnitTest.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
TEST_CLASS(TestBase);
|
jacobussystems/IoTJackAC1 | src/ArduinoMFShield.h | <reponame>jacobussystems/IoTJackAC1
/*
ArduinoMFShield.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#ifdef ARDJACK_INCLUDE_SHIELDS
#ifdef ARDJACK_INCLUDE_ARDUINO_MF_SHIELD
#include <MFShield.h>
#include "Shield.h"
class Device;
class Dynamic;
class ArduinoMFShield : public Shield
{
protected:
MFShield* _MFShield;
virtual void OnKeyPress(uint8_t key);
public:
ArduinoMFShield(const char* name);
~ArduinoMFShield();
virtual bool CreateInventory() override;
virtual bool Poll() override;
virtual bool ReadPart(Part* part, Dynamic* value, bool* handled) override;
virtual bool WritePart(Part* part, Dynamic* value, bool* handled) override;
};
#endif
#endif
#endif
|
jacobussystems/IoTJackAC1 | src/CommandSet.h | /*
CommandSet.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#else
#include "stdafx.h"
#endif
#include "Globals.h"
#include "IoTMessage.h"
class CommandSet;
#ifdef ARDJACK_INCLUDE_PERSISTENCE
class PersistentFile;
#endif
typedef bool (CommandSet::* CommandSetCallback)(const char* args);
struct CommandInfo
{
CommandSetCallback Callback;
char Name[ARDJACK_MAX_VERB_LENGTH];
};
class CommandSet
{
protected:
uint8_t _CommandCount;
CommandInfo* _Commands[ARDJACK_MAX_COMMANDS];
#ifdef ARDJACK_INCLUDE_PERSISTENCE
PersistentFile* _CurrentPersistentFile;
#endif
bool command_activate(const char* args);
bool command_add(const char* args);
bool command_beep(const char* args);
bool command_configure(const char* args);
bool command_connection(const char* args);
bool command_deactivate(const char* args);
bool command_define(const char* args);
bool command_delay(const char* args);
bool command_delete(const char* args);
bool command_device(const char* args);
bool command_display(const char* args);
bool command_exit(const char* args);
bool command_help(const char* args);
bool command_mem(const char* args);
bool command_nyi(const char* args);
bool command_reactivate(const char* args);
bool command_repeat(const char* args);
bool command_reset(const char* args);
bool command_send(const char* args);
bool command_set(const char* args);
#ifdef ARDJACK_INCLUDE_PERSISTENCE
bool command_file(const char* args);
bool command_restore(const char* args);
bool command_save(const char* args);
#endif
#ifdef ARDJACK_NETWORK_AVAILABLE
bool command_net(const char* args);
#endif
bool command_test(const char* args);
#ifdef ARDJACK_INCLUDE_TESTS
bool command_tests(const char* args);
#endif
public:
CommandSet();
~CommandSet();
CommandInfo* AddCommand(const char* name, CommandSetCallback callback);
bool Handle(const char* line, const char* verb, const char* remainder);
};
|
jacobussystems/IoTJackAC1 | src/IoTManager.h | /*
IoTManager.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#include "Globals.h"
class Connection;
class Enumeration;
class IoTManager
{
protected:
bool _PollBusy;
virtual void PollObjectsOfType(int type);
public:
uint8_t ObjectType;
Enumeration* Subtypes;
IoTManager();
~IoTManager();
virtual bool Interact(const char* text);
virtual int LookupSubtype(const char* name);
virtual void Poll();
virtual bool Remove(IoTObject* obj);
};
|
jacobussystems/IoTJackAC1 | src/pch.h | // pch.h
/*
Problems with headers in compilation?
Try commenting-out parts (or everything) below!
*/
#pragma once
#include "DetectBoard.h"
#include "Globals.h"
#include "ArduinoClock.h"
#include "ArduinoDevice.h"
#include "ArduinoDHT.h"
#include "ArduinoMFShield.h"
#include "ArduinoNeoPixel.h"
#include "ArrayHelpers.h"
#include "Beacon.h"
#include "BeaconManager.h"
#include "Bridge.h"
#include "BridgeManager.h"
#include "CmdInterpreter.h"
#include "CommandSet.h"
#include "ConfigProp.h"
#include "Configuration.h"
#include "Connection.h"
#include "ConnectionManager.h"
#include "cppQueue.h"
#include "DataLogger.h"
#include "DataLoggerManager.h"
#include "DateTime.h"
#include "Device.h"
#include "DeviceCodec1.h"
#include "DeviceManager.h"
#include "Dictionary.h"
#include "Displayer.h"
#include "Dynamic.h"
#include "Enumeration.h"
#include "EthernetInterface.h"
#include "FieldReplacer.h"
#include "FifoBuffer.h"
#include "Filter.h"
#include "FilterManager.h"
#include "HttpConnection.h"
#include "Int8List.h"
#include "IoTClock.h"
#include "IoTManager.h"
#include "IoTMessage.h"
#include "IoTObject.h"
#include "Log.h"
#include "LogConnection.h"
#include "MemoryFreeExt.h"
#include "MessageFilter.h"
#include "MessageFilterItem.h"
#include "NetworkInterface.h"
#include "NetworkManager.h"
#include "Part.h"
#include "PartManager.h"
#include "PersistentFile.h"
#include "PersistentFileManager.h"
#include "Register.h"
#include "Route.h"
#include "RtcClock.h"
#include "SerialConnection.h"
#include "Shield.h"
#include "ShieldManager.h"
#include "StringList.h"
#include "Table.h"
#include "TcpConnection.h"
#include "Tests.h"
#include "ThinkerShield.h"
#include "UdpConnection.h"
#include "UserPart.h"
#include "Utils.h"
#include "WiFiInterface.h"
#include "WiFiLibrary.h"
|
jacobussystems/IoTJackAC1 | src/UdpConnection.h | <filename>src/UdpConnection.h
/*
UdpConnection.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#include "DetectBoard.h"
#ifdef ARDJACK_ETHERNET_AVAILABLE
#include <Ethernet.h>
#include <EthernetUdp.h>
#endif
#ifdef ARDJACK_WIFI_AVAILABLE
#include "WiFiLibrary.h"
#include <WiFiUdp.h>
#endif
#else
#include "stdafx.h"
#include <winsock.h>
#endif
#include "Connection.h"
#include "DateTime.h"
#ifdef ARDJACK_NETWORK_AVAILABLE
class UdpConnection : public Connection
{
protected:
#ifdef ARDUINO
#ifdef ARDJACK_NETWORK_AVAILABLE
//char _PacketBuffer[255]; // buffer to hold incoming packet
#ifdef ARDJACK_ETHERNET_AVAILABLE
EthernetUDP* _Udp;
#endif
#ifdef ARDJACK_WIFI_AVAILABLE
WiFiUDP* _Udp;
#endif
#endif
virtual void Log_PollInputs(int packetSize);
virtual bool SendUdpReply(const char* buffer);
virtual bool WriteText(const char* text);
#else
struct sockaddr_in _InputAddress;
SOCKET _Listener;
struct sockaddr_in _OutputAddress;
SOCKET _Talker;
#endif
char _InputIp[20];
int _InputPort;
char _MulticastIp[20];
char _OutputIp[20];
int _OutputPort;
bool _UseMulticast;
virtual bool Activate() override;
virtual bool Deactivate() override;
#ifdef ARDUINO
#else
virtual bool StartListening();
virtual bool StartTalking();
virtual bool StopListening();
virtual bool StopTalking();
#endif
public:
UdpConnection(const char* name);
~UdpConnection();
virtual bool AddConfig() override;
#ifdef ARDUINO
virtual bool OutputMessage(IoTMessage* msg) override;
virtual bool OutputText(const char* text) override;
#endif
virtual bool PollInputs(int maxCount = 5) override;
virtual bool SendText(const char* text) override;
virtual bool SendTextQuiet(const char* text) override;
};
#endif
|
jacobussystems/IoTJackAC1 | src/stdafx.h | <gh_stars>0
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#ifdef ARDUINO
#else
#ifndef STRICT
#define STRICT
#endif
#ifndef WINVER
#define WINVER 0x0600
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x600
#endif
#ifndef _WIN32_WINDOWS
#define _WIN32_WINDOWS 0x600
#endif
#ifndef _WIN32_IE
#define _WIN32_IE 0x0600
#endif
#define VC_EXTRALEAN //Exclude rarely-used stuff from Windows headers
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS //some CString constructors will be explicit
#define _AFX_ALL_WARNINGS //turns off MFC's hiding of some common and often safely ignored warning messages
#define _ATL_NO_AUTOMATIC_NAMESPACE
#ifndef _SECURE_ATL
#define _SECURE_ATL 1 //Use the Secure C Runtime in ATL
#endif
#include "targetver.h"
#include <windows.h>
#include <atlstr.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// Additional headers.
#endif
|
jacobussystems/IoTJackAC1 | src/npipe.h | <reponame>jacobussystems/IoTJackAC1
#ifdef ARDUINO
#else
/*
Module : npipe.h
Purpose: Defines the interface for an C++ wrapper class for Win32 Named Pipes
Created: PJN / 2-08-1998
History: PJN / 21-02-2002 1. Updated copyright message in source code and documentation
2. Fixed a bug in Close method where the handle value was not being reset to INVALID_HANDLE_VALUE.
3. Tidied up the TRACE code
4. Tidied up build configurations for sample apps
PJN / 28-07-2002 1. Updated sample server app to do Flush of the pipe before we disconnect the client. Thanks to
"Martin" for spotting this problem.
PJN / 09-11-2002 1. ConnectClient now returns TRUE if the last error returns ERROR_PIPE_CONNECTED which indicates
that a client is already connected before we make the call. Thanks to <NAME> for
reporting this.
PJN / 05-03-2003 1. Changed the class to use exceptions rather than SDK style return values
PJN / 12-11-2003 1. Attach now includes an AutoClose parameter. This allows control over whether the pipe handle
should be closed when the pipe object goes out of scope or CNamedPipe::Close is called. Thanks
to <NAME> for reporting this issue.
PJN / 19-12-2003 1. Fixed ASSERT's at the start of most CNamedPipe functions which verify that the pipe handle
is valid. Thanks to <NAME> for reporting this issue.
PJN / 15-07-2006 1. Updated copyright details.
2. Renamed AfxThrowNamedPipeException to ThrowNamedPipeException and made it part of the
CNamedPipe class.
3. CNamedPipe is no longer derived from CObject as it was not really required.
4. Optimized CNamedPipe constructor code.
5. Code now uses new C++ style casts rather than old style C casts where necessary.
6. Optimized CNamedPipeException constructor code
7. Removed the unnecessary CNamedPipeException destructor
8. Removed some unreferenced variables in the sample app.
9. Updated the code to clean compile on VC 2005
10. Updated documentation to use the same style as the web site.
11. Addition of a CNAMEDPIPE_EXT_CLASS macro to allow the classes to be easily added to an
extension dll.
PJN / 28-12-2007 1. Updated copyright details.
2. Updated the sample apps to clean compile on VC 2005
3. Sample client app now defaults to "." (meaning the current machine) as the server to connect to.
4. CNamedPipeException::GetErrorMessage now uses the FORMAT_MESSAGE_IGNORE_INSERTS flag. For more
information please see <NAME>'s blog at
http://blogs.msdn.com/oldnewthing/archive/2007/11/28/6564257.aspx. Thanks to <NAME> for
reporting this issue.
5. CAppSettingsException::GetErrorMessage now uses Checked::tcsncpy_s if compiled using VC 2005 or
later.
6. Provision of new overloaded versions of the Peek, Write and Read methods which allows the
dwBytesRead/dwBytesWritten parameters to be returned as an output parameter as opposed to the return
value of the method. This helps resolve a situation where the underlying WriteFile / ReadFile call
fails but some data has actually been written / read from the pipe. Thanks to <NAME> for
reporting this issue.
7. dwBytesRead, dwTotalBytesAvail and dwBytesLeftThisMessage parameters to Peek are now pointers rather
than references. Thanks to Gintautas Kisonas for reporting this issue.
PJN / 30-12-2007 1. Updated the sample apps to clean compile on VC 2008
PJN / 12-07-2008 1. Updated copyright details.
2. Updated sample app to clean compile on VC 2008
3. The code has now been updated to support VC 2005 or later only.
4. Code now compiles cleanly using Code Analysis (/analyze)
5. Removed the m_bAutoClose member variable and concept from class
PJN / 01-06-2015 1. Updated copyright details.
2. Updated the sample app project settings to more modern default values.
3. Reworked the class to make it a header only implementation.
4. Added SAL annotations to all the code
5. Removed the static Call method as it did not provide any C++ encapsulation of the underlying API call
6. Reworked the class to not be exception based. Now the class merely wraps the underlying API calls
in a RAII fashion.
7. Removed the static ServerAvailable method as it did not provide any C++ encapsulation of the
underlying API call.
8. Updated the code to compile without taking a dependency on MFC.
9. The methods which call WriteFileEx have been renamed to WriteEx.
10. The methods which call ReadFileEx have been renamed to ReadEx.
11. The ConnectClient method has been renamed to Connect.
12. The DisconnectClient method has been renamed to Disconnect.
13. Added support for GetNamedPipeComputerName, GetNamedPipeClientProcessId, GetNamedPipeClientSessionId,
GetNamedPipeServerProcessId, GetNamedPipeServerSessionId & ImpersonateNamedPipeClient APIs.
PJN / 19-12-2017 1. Updated copyright details
2. Replaced CString::operator LPC*STR() calls throughout the codebase with CString::GetString calls
3. Replaced NULL throughout the codebase with nullptr. This means that the minimum requirement for the framework is now
VC 2010.
4. GetNamedPipeClientProcessId, GetNamedPipeClientSessionId, GetNamedPipeServerProcessId & GetNamedPipeServerSessionId
API functions are now called directly rather than through GetProcAddress.
5. Verified there has been no further additions to Named Pipes from the latest Windows 10 SDK
Copyright (c) 1998 - 2017 by <NAME> (Web: www.naughter.com, Email: <EMAIL>)
All rights reserved.
Copyright / Usage Details:
You are allowed to include the source code in any product (commercial, shareware, freeware or otherwise)
when your product is released in binary form. You are allowed to modify the source code in any way you want
except you cannot modify the copyright details at the top of each module. If you want to distribute source
code with your application, then you are only allowed to distribute versions released by the author. This is
to maintain a single distribution point for the source code.
*/
/////////////////////// Macros / Defines //////////////////////////////////////
#pragma once
#ifndef __NPIPE_H__
#define __NPIPE_H__
#ifndef CNAMEDPIPE_EXT_CLASS
#define CNAMEDPIPE_EXT_CLASS
#endif //#ifndef CNAMEDPIPE_EXT_CLASS
#ifndef _In_reads_bytes_opt_
#define _In_reads_bytes_opt_(size)
#endif //#ifndef _In_reads_bytes_opt_
#ifndef _Out_writes_bytes_to_opt_
#define _Out_writes_bytes_to_opt_(size,count)
#endif //#ifndef _Out_writes_bytes_to_opt_
#ifndef _Out_writes_bytes_opt_
#define _Out_writes_bytes_opt_(size)
#endif //#ifndef _Out_writes_bytes_opt_
#ifndef _Out_writes_opt_
#define _Out_writes_opt_(size)
#endif //#ifndef _Out_writes_opt_
#ifndef _Out_writes_bytes_
#define _Out_writes_bytes_(size)
#endif //#ifndef _Out_writes_bytes_
#ifndef ATLASSERT
#define ATLASSERT(expr) assert(expr)
#endif // ATLASSERT
//#include "stdafx.h"
#include <windows.h>
#include <assert.h>
// need link with Ws2_32.lib
#pragma comment(lib, "Ws2_32.lib")
/////////////////////// Classes ///////////////////////////////////////////////
//Wrapper class to encapsulate a named pipe
class CNAMEDPIPE_EXT_CLASS CNamedPipe
{
public:
//Constructors / Destructors
CNamedPipe() : m_hPipe(INVALID_HANDLE_VALUE)
{
}
~CNamedPipe()
{
Close();
}
//Creation & Opening
BOOL Create(_In_ LPCTSTR lpName, _In_ DWORD dwOpenMode, _In_ DWORD dwPipeMode, _In_ DWORD dwMaxInstances, _In_ DWORD dwOutBufferSize,
_In_ DWORD dwInBufferSize, _In_ DWORD dwDefaultTimeOut, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes = nullptr)
{
//Validate our parameters
ATLASSERT(!IsOpen());
m_hPipe = CreateNamedPipe(lpName, dwOpenMode, dwPipeMode, dwMaxInstances, dwOutBufferSize, dwInBufferSize, dwDefaultTimeOut, lpSecurityAttributes);
return (m_hPipe != INVALID_HANDLE_VALUE);
}
BOOL Open(_In_ LPCTSTR lpName, _In_ DWORD dwDesiredAccess, _In_ DWORD dwShareMode, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes = nullptr, DWORD dwFlagsAndAttributes = 0)
{
//Validate our parameters
ATLASSERT(!IsOpen());
m_hPipe = CreateFile(lpName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, OPEN_EXISTING, dwFlagsAndAttributes, nullptr);
return (m_hPipe != INVALID_HANDLE_VALUE);
}
operator HANDLE() const
{
return m_hPipe;
}
void Close()
{
if (IsOpen())
{
CloseHandle(m_hPipe);
m_hPipe = INVALID_HANDLE_VALUE;
}
}
void Attach(_In_opt_ HANDLE hPipe)
{
Close();
m_hPipe = hPipe;
}
HANDLE Detach()
{
HANDLE hReturn = m_hPipe;
m_hPipe = INVALID_HANDLE_VALUE;
return hReturn;
}
//General functions
BOOL IsOpen() const
{
return (m_hPipe != INVALID_HANDLE_VALUE);
}
BOOL Connect(_Inout_opt_ LPOVERLAPPED lpOverlapped = nullptr)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return ConnectNamedPipe(m_hPipe, lpOverlapped);
}
BOOL Disconnect()
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return DisconnectNamedPipe(m_hPipe);
}
BOOL Flush()
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return FlushFileBuffers(m_hPipe);
}
BOOL Write(_In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer,_In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten = nullptr, _Inout_opt_ LPOVERLAPPED lpOverlapped = nullptr)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return WriteFile(m_hPipe, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, lpOverlapped);
}
BOOL WriteEx(_In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Inout_ LPOVERLAPPED lpOverlapped, _In_ LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return WriteFileEx(m_hPipe, lpBuffer, nNumberOfBytesToWrite, lpOverlapped, lpCompletionRoutine);
}
BOOL Read(_Out_writes_bytes_to_opt_(nNumberOfBytesToRead, *lpNumberOfBytesRead) __out_data_source(FILE) LPVOID lpBuffer, _In_ DWORD nNumberOfBytesToRead, _Out_opt_ LPDWORD lpNumberOfBytesRead = nullptr, _Inout_opt_ LPOVERLAPPED lpOverlapped = nullptr)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return ReadFile(m_hPipe, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped);
}
BOOL ReadEx(_Out_writes_bytes_opt_(nNumberOfBytesToRead) __out_data_source(FILE) LPVOID lpBuffer, _In_ DWORD nNumberOfBytesToRead, _Inout_ LPOVERLAPPED lpOverlapped, _In_ LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return ReadFileEx(m_hPipe, lpBuffer, nNumberOfBytesToRead, lpOverlapped, lpCompletionRoutine);
}
BOOL Peek(_Out_writes_bytes_to_opt_(nBufferSize, *lpBytesRead) LPVOID lpBuffer, _In_ DWORD nBufferSize, _Out_opt_ LPDWORD lpBytesRead = nullptr, _Out_opt_ LPDWORD lpTotalBytesAvail = nullptr, _Out_opt_ LPDWORD lpBytesLeftThisMessage = nullptr)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return PeekNamedPipe(m_hPipe, lpBuffer, nBufferSize, lpBytesRead, lpTotalBytesAvail, lpBytesLeftThisMessage);
}
BOOL Transact(_In_reads_bytes_opt_(nInBufferSize) LPVOID lpInBuffer, _In_ DWORD nInBufferSize, _Out_writes_bytes_to_opt_(nOutBufferSize, *lpBytesRead) LPVOID lpOutBuffer, _In_ DWORD nOutBufferSize, _Out_ LPDWORD lpBytesRead, _Inout_opt_ LPOVERLAPPED lpOverlapped = nullptr)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return TransactNamedPipe(m_hPipe, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesRead, lpOverlapped);
}
BOOL GetState(_Out_opt_ LPDWORD lpState, _Out_opt_ LPDWORD lpCurInstances, _Out_opt_ LPDWORD lpMaxCollectionCount, _Out_opt_ LPDWORD lpCollectDataTimeout, _Out_writes_opt_(nMaxUserNameSize) LPTSTR lpUserName, _In_ DWORD nMaxUserNameSize)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return GetNamedPipeHandleState(m_hPipe, lpState, lpCurInstances, lpMaxCollectionCount, lpCollectDataTimeout, lpUserName, nMaxUserNameSize);
}
BOOL GetInfo(_Out_opt_ LPDWORD lpFlags, _Out_opt_ LPDWORD lpOutBufferSize = nullptr, _Out_opt_ LPDWORD lpInBufferSize = nullptr, _Out_opt_ LPDWORD lpMaxInstances = nullptr)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return GetNamedPipeInfo(m_hPipe, lpFlags, lpOutBufferSize, lpInBufferSize, lpMaxInstances);
}
BOOL SetState(_In_opt_ LPDWORD lpMode, _In_opt_ LPDWORD lpMaxCollectionCount, _In_opt_ LPDWORD lpCollectDataTimeout)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return SetNamedPipeHandleState(m_hPipe, lpMode, lpMaxCollectionCount, lpCollectDataTimeout);
}
#if (_WIN32_WINNT >= 0x0600)
_Success_(return != 0)
BOOL GetClientComputerName(_Out_writes_bytes_(ClientComputerNameLength) LPTSTR ClientComputerName, _In_ ULONG ClientComputerNameLength)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return GetNamedPipeClientComputerName(m_hPipe, ClientComputerName, ClientComputerNameLength);
}
#endif //#if (_WIN32_WINNT >= 0x0600)
#if (_WIN32_WINNT >= 0x0600)
_Success_(return != 0)
BOOL GetClientProcessId(_Out_ PULONG ClientProcessId)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return GetNamedPipeClientProcessId(m_hPipe, ClientProcessId);
}
#endif //#if (_WIN32_WINNT >= 0x0600)
#if (_WIN32_WINNT >= 0x0600)
_Success_(return != 0)
BOOL GetClientSessionId(_Out_ PULONG ClientSessionId)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return GetNamedPipeClientSessionId(m_hPipe, ClientSessionId);
}
#endif //#if (_WIN32_WINNT >= 0x0600)
#if (_WIN32_WINNT >= 0x0600)
_Success_(return != 0)
BOOL GetServerProcessId(_Out_ PULONG ServerProcessId)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return GetNamedPipeServerProcessId(m_hPipe, ServerProcessId);
}
#endif //#if (_WIN32_WINNT >= 0x0600)
#if (_WIN32_WINNT >= 0x0600)
_Success_(return != 0)
BOOL GetServerSessionId(_Out_ PULONG ServerSessionId)
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return GetNamedPipeServerSessionId(m_hPipe, ServerSessionId);
}
#endif //#if (_WIN32_WINNT >= 0x0600)
BOOL ImpersonateClient()
{
//Validate our parameters
ATLASSERT(IsOpen()); //Pipe must be open
return ImpersonateNamedPipeClient(m_hPipe);
}
protected:
//Member variables
HANDLE m_hPipe;
};
#endif //#ifndef __NPIPE_H__
#endif
|
jacobussystems/IoTJackAC1 | src/Globals.h | /*
Globals.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#include "DetectBoard.h"
#define _strlwr strlwr
#define _strupr strupr
#else
#include "stdafx.h"
#endif
#ifndef MAX_PATH
#define MAX_PATH 260
#endif
// Include required Shields, UserParts and features.
#undef ARDJACK_INCLUDE_ARDUINO_DHT
#undef ARDJACK_INCLUDE_ARDUINO_MF_SHIELD
#undef ARDJACK_INCLUDE_ARDUINO_NEOPIXEL
#undef ARDJACK_INCLUDE_BEACONS
#undef ARDJACK_INCLUDE_BRIDGES
#undef ARDJACK_INCLUDE_DATALOGGERS
#undef ARDJACK_INCLUDE_MULTI_PARTS
#undef ARDJACK_INCLUDE_PERSISTENCE
#undef ARDJACK_INCLUDE_SHIELDS
#undef ARDJACK_INCLUDE_TESTS
#undef ARDJACK_INCLUDE_THINKER_SHIELD
#undef ARDJACK_INCLUDE_WINDISK
#undef ARDJACK_INCLUDE_WINMEMORY
#ifdef ARDUINO
//#define ARDJACK_INCLUDE_ARDUINO_DHT
//#define ARDJACK_INCLUDE_ARDUINO_MF_SHIELD
//#define ARDJACK_INCLUDE_ARDUINO_NEOPIXEL
#define ARDJACK_INCLUDE_BEACONS
#define ARDJACK_INCLUDE_BRIDGES
#define ARDJACK_INCLUDE_DATALOGGERS
//#define ARDJACK_INCLUDE_MULTI_PARTS
//#define ARDJACK_INCLUDE_PERSISTENCE
#define ARDJACK_INCLUDE_SHIELDS
//#define ARDJACK_INCLUDE_TESTS
#define ARDJACK_INCLUDE_THINKER_SHIELD
#else
#define ARDJACK_INCLUDE_BEACONS
#define ARDJACK_INCLUDE_BRIDGES
#define ARDJACK_INCLUDE_DATALOGGERS
//#define ARDJACK_INCLUDE_MULTI_PARTS
#define ARDJACK_INCLUDE_PERSISTENCE
#define ARDJACK_INCLUDE_SHIELDS
#define ARDJACK_INCLUDE_TESTS
#define ARDJACK_INCLUDE_THINKER_SHIELD
#define ARDJACK_INCLUDE_WINDISK
#define ARDJACK_INCLUDE_WINMEMORY
#define ARDJACK_NETWORK_AVAILABLE
#endif
// Global limits / constants.
#define ARDJACK_MAX_COMMAND_BUFFER_ITEM_LENGTH 100 // max.no.of characters in a command
#define ARDJACK_MAX_COMMAND_BUFFER_ITEMS 10 // max.items in a command buffer
#define ARDJACK_MAX_COMMAND_LENGTH 110 // max.characters in a command
#define ARDJACK_MAX_COMMAND_SETS 1 // max.no.of CommandSets
#define ARDJACK_MAX_COMMANDS 24 // max.no.of commands
#define ARDJACK_MAX_CONFIG_PROPERTIES 30 // max.no.of items in a Configuration
#define ARDJACK_MAX_CONFIG_VALUE_LENGTH 40 // max.characters in a ConfigProp string
#define ARDJACK_MAX_CONNECTION_OUTPUT_BUFFER_ITEM_LENGTH 200 // max.characters in a Connection o/p buffer item
#define ARDJACK_MAX_CONNECTION_OUTPUT_BUFFER_ITEMS 10 // max.items in the Connection o/p buffer
#define ARDJACK_MAX_DATALOGGER_PARTS 10
#define ARDJACK_MAX_DESCRIPTION_LENGTH 60 // max.characters in a description
#define ARDJACK_MAX_DEVICE_BUFFER_ITEMS 10 // max.items in a device buffer
#define ARDJACK_MAX_DICTIONARY_ITEMS 6
#define ARDJACK_MAX_DICTIONARY_KEY_LENGTH 10
#define ARDJACK_MAX_DICTIONARY_VALUE_LENGTH 20
#define ARDJACK_MAX_DYNAMIC_STRING_LENGTH 20
#define ARDJACK_MAX_ENUMERATION_ITEM_LENGTH 20 // max.characters in an Enumeration item
#define ARDJACK_MAX_ENUMERATION_ITEMS 60 // max.no.of items in an Enumeration
#define ARDJACK_MAX_INPUT_ROUTES 4
// TEMPORARY:
#define ARDJACK_MAX_LOG_BUFFER_ITEM_LENGTH 4
#define ARDJACK_MAX_LOG_BUFFER_ITEMS 1
#define ARDJACK_MAX_MACRO_LENGTH 100 // max.characters in a Macro
#define ARDJACK_MAX_MACROS 30 // max.no.of Macros
#define ARDJACK_MAX_MESSAGE_PATH_LENGTH 30 // max.characters in an IoTMessage path
#define ARDJACK_MAX_MESSAGE_TEXT_LENGTH 160 // max.characters in IoTMessage 'Text'
#define ARDJACK_MAX_MESSAGE_WIRETEXT_LENGTH 220 // max.characters in IoTMessage 'WireText'
#define ARDJACK_MAX_MULTI_PART_ITEMS 1 // max.no.of Items in a 'Multi' Part
#define ARDJACK_MAX_NAME_LENGTH 32 // max.characters in a name
#define ARDJACK_MAX_OBJECTS 20 // max.no.of Objects in Register
#define ARDJACK_MAX_PART_VALUE_LENGTH 10 // max.characters in a Part's value
#define ARDJACK_MAX_PARTS 34 // max.no.of Parts
#define ARDJACK_MAX_PERSISTED_FILES 2
#define ARDJACK_MAX_PERSISTED_LINES 40
#define ARDJACK_MAX_TABLE_COLUMNS 10
#define ARDJACK_MAX_VALUE_LENGTH 120
#define ARDJACK_MAX_VALUES 10
#define ARDJACK_MAX_VERB_LENGTH 12
#define ARDJACK_PERSISTED_LINE_LENGTH 256
#ifdef ARDUINO
#define ARDJACK_MAX_COMMAND_BUFFER_ITEMS 4 // max.items in a command buffer
#define ARDJACK_MAX_CONNECTION_OUTPUT_BUFFER_ITEM_LENGTH 200 // max.characters in a Connection o/p buffer item
#define ARDJACK_MAX_CONNECTION_OUTPUT_BUFFER_ITEMS 4 // max.items in the Connection o/p buffer
#define ARDJACK_MAX_DEVICE_BUFFER_ITEMS 4 // max.items in a device buffer
#ifdef __arm__
#define ARDJACK_MAX_DATALOGGER_PARTS 8
#define ARDJACK_MAX_MACROS 6
#define ARDJACK_MAX_NAME_LENGTH 24
#else
#define ARDJACK_MAX_CONFIG_PROPERTIES 30
//#define ARDJACK_MAX_CONFIG_VALUE_LENGTH 24
#define ARDJACK_MAX_DATALOGGER_PARTS 6
#define ARDJACK_MAX_DESCRIPTION_LENGTH 60
#define ARDJACK_MAX_DICTIONARY_ITEMS 6
#define ARDJACK_MAX_ENUMERATION_ITEMS 34
#define ARDJACK_MAX_MACRO_LENGTH 80
#define ARDJACK_MAX_MACROS 6
//#define ARDJACK_MAX_MESSAGE_TEXT_LENGTH 160
//#define ARDJACK_MAX_MESSAGE_WIRETEXT_LENGTH 160
#define ARDJACK_MAX_MULTI_PART_ITEMS 1
#define ARDJACK_MAX_NAME_LENGTH 24
#define ARDJACK_MAX_OBJECTS 12
#define ARDJACK_MAX_VALUE_LENGTH 60
#define ARDJACK_MAX_VALUES 10
#endif
#endif
#define ARDJACK_BYTES_PER_KB 1024
#define ARDJACK_BYTES_PER_MB (1024 * 1024)
#define ARDJACK_BYTES_PER_GB (1024 * 1024 * 1024)
#include "DateTime.h"
#include "FifoBuffer.h"
#include "Register.h"
// Forward declarations.
#ifdef ARDJACK_INCLUDE_BEACONS
class Beacon;
class BeaconManager;
#endif
#ifdef ARDJACK_INCLUDE_BRIDGES
class Bridge;
class BridgeManager;
#endif
class CmdInterpreter;
class CommandSet;
class Connection;
class ConnectionManager;
#ifdef ARDJACK_INCLUDE_DATALOGGERS
class DataLogger;
class DataLoggerManager;
#endif
class Device;
class DeviceCodec1;
class DeviceManager;
class Filter;
class FilterManager;
class IoTClock;
class IoTManager;
class IoTMessage;
#ifdef ARDJACK_NETWORK_AVAILABLE
class NetworkInterface;
class NetworkManager;
#endif
class Part;
class PartManager;
#ifdef ARDJACK_INCLUDE_PERSISTENCE
class PersistentFile;
class PersistentFileManager;
#endif
class ShieldManager;
class UserPart;
// Setup string storage and RTC.
#ifdef ARDUINO
#define PRM(string_literal) ((const PROGMEM char *)(string_literal))
#ifdef ARDJACK_RTC_AVAILABLE
#include "RtcClock.h"
#else
#include "ArduinoClock.h"
#endif
#else
#define PRM(string_literal) ((const char* )(string_literal))
#endif
// Arduino DHT model types.
const static int ARDJACK_ARDUINO_DHT_MODEL_DHT11 = 0;
const static int ARDJACK_ARDUINO_DHT_MODEL_DHT22 = 1;
// Arduino DHT variable types.
const static int ARDJACK_ARDUINO_DHT_VAR_TEMPERATURE = 0;
const static int ARDJACK_ARDUINO_DHT_VAR_HUMIDITY = 1;
// Bridge Direction types.
const static int ARDJACK_BRIDGE_DIRECTION_BIDIRECTIONAL = 0;
const static int ARDJACK_BRIDGE_DIRECTION_UNIDIRECTIONAL_1TO2 = 1;
const static int ARDJACK_BRIDGE_DIRECTION_UNIDIRECTIONAL_2TO1 = 2;
// Connection subtypes.
#ifdef ARDUINO
#else
const static int ARDJACK_CONNECTION_SUBTYPE_CLIPBOARD = 0;
#endif
const static int ARDJACK_CONNECTION_SUBTYPE_HTTP = 1;
const static int ARDJACK_CONNECTION_SUBTYPE_LOG = 2;
const static int ARDJACK_CONNECTION_SUBTYPE_SERIAL = 3;
const static int ARDJACK_CONNECTION_SUBTYPE_TCP = 4;
const static int ARDJACK_CONNECTION_SUBTYPE_UDP = 5;
// Data types for 'ConfigProp' and 'Dynamic'.
const static int ARDJACK_DATATYPE_EMPTY = 0;
const static int ARDJACK_DATATYPE_BOOLEAN = 1;
const static int ARDJACK_DATATYPE_DATETIME = 2;
const static int ARDJACK_DATATYPE_INTEGER = 3;
const static int ARDJACK_DATATYPE_REAL = 4;
const static int ARDJACK_DATATYPE_STRING = 5;
// Device subtypes.
const static int ARDJACK_DEVICE_SUBTYPE_ARDUINO = 0;
const static int ARDJACK_DEVICE_SUBTYPE_VELLEMANK8055 = 1;
const static int ARDJACK_DEVICE_SUBTYPE_WINDOWS = 2;
// Horizontal Alignment types.
const static int ARDJACK_HORZ_ALIGN_CENTRE = 0;
const static int ARDJACK_HORZ_ALIGN_LEFT = 1;
const static int ARDJACK_HORZ_ALIGN_RIGHT = 2;
// Device Info types.
const static int ARDJACK_INFO_DEVICE_CLASS = 0;
const static int ARDJACK_INFO_DEVICE_TYPE = 1;
const static int ARDJACK_INFO_DEVICE_VERSION = 2;
// Message Format type.
const static int ARDJACK_MESSAGE_FORMAT_0 = 0;
const static int ARDJACK_MESSAGE_FORMAT_1 = 1;
// Message Path type.
const static int ARDJACK_MESSAGE_PATH_DEVICE = 0;
const static int ARDJACK_MESSAGE_PATH_NONE = 1;
// Message type.
const static int ARDJACK_MESSAGE_TYPE_COMMAND = 0;
const static int ARDJACK_MESSAGE_TYPE_DATA = 1;
const static int ARDJACK_MESSAGE_TYPE_HEARTBEAT = 2;
const static int ARDJACK_MESSAGE_TYPE_NONE = 3;
const static int ARDJACK_MESSAGE_TYPE_NOTIFICATION = 4;
const static int ARDJACK_MESSAGE_TYPE_REQUEST = 5;
const static int ARDJACK_MESSAGE_TYPE_RESPONSE = 6;
// Time constants.
const static int ARDJACK_MILLISECONDS_PER_SECOND = 1000;
const static int ARDJACK_SECONDS_PER_MINUTE = 60;
const static int ARDJACK_MINUTES_PER_HOUR = 60;
const static int ARDJACK_HOURS_PER_DAY = 24;
// Network Interface subtypes.
const static int ARDJACK_NETWORK_SUBTYPE_ETHERNET = 0;
const static int ARDJACK_NETWORK_SUBTYPE_UNKNOWN = 1;
const static int ARDJACK_NETWORK_SUBTYPE_WIFI = 2;
// Object subtypes, other than for Connections, Devices, Network Interfaces and Shields (which have specific subtypes).
const static int ARDJACK_OBJECT_SUBTYPE_BASIC = 0;
const static int ARDJACK_OBJECT_SUBTYPE_UNKNOWN = 127;
// Object types.
const static int ARDJACK_OBJECT_TYPE_BEACON = 0;
const static int ARDJACK_OBJECT_TYPE_BRIDGE = 1;
const static int ARDJACK_OBJECT_TYPE_CELL = 2; // NOT IMPLEMENTED
const static int ARDJACK_OBJECT_TYPE_CONNECTION = 3;
const static int ARDJACK_OBJECT_TYPE_DATALOGGER = 4;
const static int ARDJACK_OBJECT_TYPE_DEVICE = 5;
const static int ARDJACK_OBJECT_TYPE_FILTER = 6;
const static int ARDJACK_OBJECT_TYPE_NETWORKINTERFACE = 7;
const static int ARDJACK_OBJECT_TYPE_OBJECT = 8;
const static int ARDJACK_OBJECT_TYPE_SHIELD = 9;
const static int ARDJACK_OBJECT_TYPE_TRIGGER = 10; // NOT IMPLEMENTED
const static int ARDJACK_OBJECT_TYPE_UNKNOWN = 127;
// Device Operation types.
const static int ARDJACK_OPERATION_ACTIVATE = 0; // activate the Device
const static int ARDJACK_OPERATION_ADD = 1; // add a Part to the Device
const static int ARDJACK_OPERATION_BEEP = 2; // make the Device beep
const static int ARDJACK_OPERATION_CLEAR = 3; // clear the inventory on the Device (remove all Parts)
const static int ARDJACK_OPERATION_CONFIGURE = 4; // configure the Device
const static int ARDJACK_OPERATION_CONFIGUREPART = 5; // configure a Part or Part type on the Device
const static int ARDJACK_OPERATION_DEACTIVATE = 6; // activate the Device
const static int ARDJACK_OPERATION_ERROR = 7; // an error occurred
const static int ARDJACK_OPERATION_FLASH = 8; // flash a Part on the Device
const static int ARDJACK_OPERATION_GET_CONFIG = 9; // get one property of the Device's configuration
const static int ARDJACK_OPERATION_GET_COUNT = 10; // get the count of a Part type on the Device
const static int ARDJACK_OPERATION_GET_GLOBAL = 11; // get a global setting (of the computer)
const static int ARDJACK_OPERATION_GET_INFO = 12; // get Device info
const static int ARDJACK_OPERATION_GET_INVENTORY = 13; // get the Device inventory
const static int ARDJACK_OPERATION_GET_PART_CONFIG = 14; // get all of the configuration of a Part on the Device
const static int ARDJACK_OPERATION_NONE = 15;
const static int ARDJACK_OPERATION_REACTIVATE = 16; // reactivate = deactivate + activate
const static int ARDJACK_OPERATION_READ = 17; // read a Part on the Device
const static int ARDJACK_OPERATION_SET_GLOBAL = 18; // set a global setting (of the computer)
const static int ARDJACK_OPERATION_SUBSCRIBE = 19; // subscribe to change notifications from the Device
const static int ARDJACK_OPERATION_SUBSCRIBED = 20; // the Device signals that a Part or Part type is 'subscribed' to
const static int ARDJACK_OPERATION_UNSUBSCRIBE = 21; // unsubscribe to change notifications from the Device
const static int ARDJACK_OPERATION_UNSUBSCRIBED = 22; // the Device signals that a Part or Part type is 'unsubscribed'
const static int ARDJACK_OPERATION_UPDATE = 23; // update the Device
const static int ARDJACK_OPERATION_WRITE = 24; // write to a Part on the Device
// Part types.
const static int ARDJACK_PART_TYPE_ACCELEROMETER = 0;
const static int ARDJACK_PART_TYPE_ANALOG_INPUT = 1;
const static int ARDJACK_PART_TYPE_ANALOG_OUTPUT = 2;
const static int ARDJACK_PART_TYPE_BUTTON = 3;
const static int ARDJACK_PART_TYPE_DEVICE = 4;
const static int ARDJACK_PART_TYPE_DIGITAL_INPUT = 5;
const static int ARDJACK_PART_TYPE_DIGITAL_OUTPUT = 6;
const static int ARDJACK_PART_TYPE_DISK_SPACE = 7;
const static int ARDJACK_PART_TYPE_GRAPHIC_DISPLAY = 8;
const static int ARDJACK_PART_TYPE_GYROSCOPE = 9;
const static int ARDJACK_PART_TYPE_HUMIDITY_SENSOR = 10;
const static int ARDJACK_PART_TYPE_I2C = 11;
const static int ARDJACK_PART_TYPE_KEYBOARD = 12;
const static int ARDJACK_PART_TYPE_KEYPAD = 13;
const static int ARDJACK_PART_TYPE_LED = 14;
const static int ARDJACK_PART_TYPE_LIGHT_SENSOR = 15;
const static int ARDJACK_PART_TYPE_MAGNETIC_SENSOR = 16;
const static int ARDJACK_PART_TYPE_MEMORY = 17;
const static int ARDJACK_PART_TYPE_MOUSE = 18;
const static int ARDJACK_PART_TYPE_MULTI = 19;
const static int ARDJACK_PART_TYPE_NONE = 20;
const static int ARDJACK_PART_TYPE_ORIENTATION = 21;
const static int ARDJACK_PART_TYPE_POTENTIOMETER = 22;
const static int ARDJACK_PART_TYPE_PRESSURE_SENSOR = 23;
const static int ARDJACK_PART_TYPE_PROXIMITY_SENSOR = 24;
const static int ARDJACK_PART_TYPE_SOUND = 25;
const static int ARDJACK_PART_TYPE_SPECIAL = 26;
const static int ARDJACK_PART_TYPE_SWITCH = 27;
const static int ARDJACK_PART_TYPE_TEMPERATURE_SENSOR = 28;
const static int ARDJACK_PART_TYPE_TEXT_DISPLAY = 29;
const static int ARDJACK_PART_TYPE_TOUCHSCREEN = 30;
const static int ARDJACK_PART_TYPE_TTS = 31;
const static int ARDJACK_PART_TYPE_USER = 32;
const static int ARDJACK_MAX_PART_TYPE = ARDJACK_PART_TYPE_USER;
const static int ARDJACK_MIN_PART_TYPE = ARDJACK_PART_TYPE_ACCELEROMETER;
// Route types.
const static int ARDJACK_ROUTE_TYPE_NONE = 0;
const static int ARDJACK_ROUTE_TYPE_COMMAND = 1;
const static int ARDJACK_ROUTE_TYPE_REQUEST = 2;
const static int ARDJACK_ROUTE_TYPE_RESPONSE = 3;
// Shield subtypes.
const static int ARDJACK_SHIELD_SUBTYPE_ARDUINO_MF_SHIELD = 0;
const static int ARDJACK_SHIELD_SUBTYPE_THINKERSHIELD = 1;
// String Comparison type.
const static int ARDJACK_STRING_COMPARE_CONTAINS = 0;
const static int ARDJACK_STRING_COMPARE_ENDS_WITH = 1;
const static int ARDJACK_STRING_COMPARE_EQUALS = 2;
const static int ARDJACK_STRING_COMPARE_FALSE = 3; // result is always false
const static int ARDJACK_STRING_COMPARE_IN = 4;
const static int ARDJACK_STRING_COMPARE_NOT_CONTAINS = 5;
const static int ARDJACK_STRING_COMPARE_NOT_ENDS_WITH = 6;
const static int ARDJACK_STRING_COMPARE_NOT_EQUALS = 7;
const static int ARDJACK_STRING_COMPARE_NOT_IN = 8;
const static int ARDJACK_STRING_COMPARE_NOT_STARTS_WITH = 9;
const static int ARDJACK_STRING_COMPARE_STARTS_WITH = 10;
const static int ARDJACK_STRING_COMPARE_TRUE = 11; // result is always true
// UserPart subtypes.
const static int ARDJACK_USERPART_SUBTYPE_NONE = 0;
const static int ARDJACK_USERPART_SUBTYPE_ARDUINO_DHT = 1;
const static int ARDJACK_USERPART_SUBTYPE_ARDUINO_NEOPIXEL = 2;
const static int ARDJACK_USERPART_SUBTYPE_WINDISK = 3;
const static int ARDJACK_USERPART_SUBTYPE_WINMEMORY = 4;
// WiFi connect types.
const static int ARDJACK_WIFI_CONNECT_OPEN = 0;
const static int ARDJACK_WIFI_CONNECT_WEP = 1;
const static int ARDJACK_WIFI_CONNECT_WPA = 2;
// WinDisk subtypes.
const static int ARDJACK_WINDISK_DRIVE_A = 0;
const static int ARDJACK_WINDISK_DRIVE_B = 1;
const static int ARDJACK_WINDISK_DRIVE_C = 2;
const static int ARDJACK_WINDISK_DRIVE_D = 3;
const static int ARDJACK_WINDISK_DRIVE_E = 4;
const static int ARDJACK_WINDISK_DRIVE_F = 5;
const static int ARDJACK_WINDISK_DRIVE_G = 6;
const static int ARDJACK_WINDISK_DRIVE_H = 7;
// WinMemory subtypes.
const static int ARDJACK_WINMEMORY_FREE_PHYSICAL = 0;
const static int ARDJACK_WINMEMORY_TOTAL_PHYSICAL = 1;
const static int ARDJACK_WINMEMORY_FREE_VIRTUAL = 2;
struct CommandBufferItem
{
Device* Dev = NULL;
char Text[ARDJACK_MAX_COMMAND_BUFFER_ITEM_LENGTH] = "";
};
struct ConnectionOutputBufferItem
{
Connection* Conn = NULL;
char Text[ARDJACK_MAX_CONNECTION_OUTPUT_BUFFER_ITEM_LENGTH] = "";
};
struct MacroDef
{
char Content[ARDJACK_MAX_MACRO_LENGTH] = "";
char Name[ARDJACK_MAX_NAME_LENGTH] = "";
};
class Globals
{
protected:
public:
static char AppName[ARDJACK_MAX_NAME_LENGTH];
//static bool AutoClearCommandLine;
#ifdef ARDJACK_INCLUDE_BEACONS
static BeaconManager* BeaconMgr;
#endif
#ifdef ARDJACK_INCLUDE_BRIDGES
static BridgeManager* BridgeMgr;
#endif
static IoTClock* Clock;
static FifoBuffer* CommandBuffer;
static char CommandPrefix[12];
static char CommandSeparator[6];
static CommandSet* CommandSet0;
static char CommentPrefix[4];
static char CompileDate[14];
static char CompileTime[14];
static char ComputerName[ARDJACK_MAX_NAME_LENGTH];
static ConnectionManager* ConnectionMgr;
#ifdef ARDJACK_INCLUDE_DATALOGGERS
static DataLoggerManager* DataLoggerMgr;
#endif
static FifoBuffer* DeviceBuffer; // shared by Devices
static DeviceCodec1* DeviceCodec;
static DeviceManager* DeviceMgr;
static char EmptyString[2];
static bool EnableSound;
static char ExecPrefix[4]; // prefix for executing a command file
static FilterManager* FilterMgr;
static char FromName[20]; // 'from' name to use in messages sent
static void* HeapBase;
static bool IncludeArduinoDHT;
static bool IncludeArduinoMFShield;
static bool IncludeArduinoNeoPixel;
static bool IncludeBeacons;
static bool IncludeBridges;
static bool IncludeDataLoggers;
static bool IncludePersistence;
static bool IncludeShields;
static bool IncludeThinkerShield;
static bool IncludeWinDisk;
static bool IncludeWinMemory;
static bool InitialisedStatic; // has static initialzation finished?
static CmdInterpreter* Interpreter;
static char IpAddress[20];
static Connection* LogTarget; // a Connection to log to
static bool NetworkAvailable;
#ifdef ARDJACK_NETWORK_AVAILABLE
static NetworkManager* NetworkMgr;
#endif
static IoTManager* ObjectMgr;
static Register* ObjectRegister;
static char OneCommandPrefix[4];
static PartManager* PartMgr;
#ifdef ARDJACK_INCLUDE_PERSISTENCE
static PersistentFileManager* PersistentFileMgr;
#endif
//static FifoBuffer *RequestBuffer;
static bool RtcAvailable;
#ifdef ARDJACK_INCLUDE_SHIELDS
static ShieldManager* ShieldMgr;
#endif
static char SpecialFieldPrefix[10];
static bool UserExit; // user wishes to exit this program
static int Verbosity;
#ifdef ARDUINO
static int SerialSpeed; // baud rate
#else
static char AppDocsFolder[MAX_PATH];
static char HostName[ARDJACK_MAX_NAME_LENGTH];
static bool WinsockStarted;
#endif
static bool ActivateObjects(const char* args, bool state);
static IoTObject* AddObject(const char* args);
static IoTObject* AddObject(int type, int subtype, const char* name);
static bool CheckCommandBuffer();
static bool CheckDeviceBuffer();
static bool DeleteObjects(const char* args);
static bool DeleteSingleObject(IoTObject* obj);
static bool HandleDeviceRequest(Device *dev, const char* line);
static bool Init();
static bool QueueCommand(const char* line);
static bool ReactivateObjects(const char* args);
static bool Set(const char* name, const char* value, bool* handled);
static bool SetupStandardRoutes(Connection *pConn);
#ifdef ARDJACK_INCLUDE_PERSISTENCE
static bool LoadIniFile(const char* name);
static bool ReadExecuteCommandFile(PersistentFile* file);
static bool ReadExecuteStartupFile();
static bool SaveIniFile(const char* filename);
#endif
};
|
jacobussystems/IoTJackAC1 | ArdJackW/src/MemoryHelpers.h | <filename>ArdJackW/src/MemoryHelpers.h<gh_stars>0
#pragma once
#ifdef ARDUINO
#else
#include "stdafx.h"
#include "Globals.h"
class MemoryHelpers
{
protected:
public:
static long HeapUsed();
};
#endif
|
jacobussystems/IoTJackAC1 | src/Dictionary.h | <reponame>jacobussystems/IoTJackAC1
/*
Dictionary.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#else
#include "stdafx.h"
#endif
#include "Dictionary.h"
#include "Globals.h"
#include "StringList.h"
class Dictionary
{
protected:
bool IgnoreCase;
virtual int Lookup(const char* key);
public:
StringList Keys;
StringList Values;
Dictionary(bool ignoreCase = true);
~Dictionary();
virtual bool Add(const char* key, const char* value);
virtual bool ContainsKey(const char* key);
virtual int Count();
virtual const char* Get(const char* key);
virtual const char* Get(int index, char* key);
virtual bool Remove(const char* key, bool quiet = true);
};
|
jacobussystems/IoTJackAC1 | ArdJackW/UnitTest1/pch.h | <filename>ArdJackW/UnitTest1/pch.h
// pch.h: This is a precompiled header file.
// Files listed below are compiled only once, improving build performance for future builds.
// This also affects IntelliSense performance, including code completion and many code browsing features.
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
// Do not add files here that you will be updating frequently as this negates the performance advantage.
#pragma once
#include "ArrayHelpers.h"
#include "Beacon.h"
#include "BeaconManager.h"
#include "Bridge.h"
#include "BridgeManager.h"
#include "ClipboardConnection.h"
#include "CmdInterpreter.h"
#include "CommandSet.h"
#include "ConfigProp.h"
#include "Configuration.h"
#include "Connection.h"
#include "ConnectionManager.h"
#include "DataLogger.h"
#include "DataLoggerManager.h"
#include "DateTime.h"
#include "Device.h"
#include "DeviceCodec1.h"
#include "DeviceManager.h"
#include "Dictionary.h"
#include "Displayer.h"
#include "Dynamic.h"
#include "Enumeration.h"
#include "FieldReplacer.h"
#include "FifoBuffer.h"
#include "Filter.h"
#include "FilterManager.h"
#include "Globals.h"
#include "HttpConnection.h"
#include "IniFiler.h"
#include "Int8List.h"
#include "IoTClock.h"
#include "IoTManager.h"
#include "IoTMessage.h"
#include "IoTObject.h"
#include "Log.h"
#include "LogConnection.h"
#include "MessageFilter.h"
#include "MessageFilterItem.h"
#include "NetworkInterface.h"
#include "NetworkManager.h"
#include "Part.h"
#include "PartManager.h"
#include "PersistentFile.h"
#include "PersistentFileManager.h"
#include "Register.h"
#include "RingBuf.h"
#include "Route.h"
#include "SerialConnection.h"
#include "Shield.h"
#include "ShieldManager.h"
#include "StringList.h"
#include "Table.h"
#include "TcpConnection.h"
#include "Tests.h"
#include "ThinkerShield.h"
#include "UdpConnection.h"
#include "UrlEncoder.h"
#include "UserPart.h"
#include "Utils.h"
#include "VellemanK8055Device.h"
#include "WinClock.h"
#include "WinDevice.h"
#include "WinDisk.h"
#include "WinMemory.h"
|
jacobussystems/IoTJackAC1 | src/FieldReplacer.h | /*
FieldReplacer.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#else
#include "stdafx.h"
#endif
#include "Dictionary.h"
#include "Globals.h"
#include "IoTObject.h"
struct ReplaceFieldParams
{
char DateFormat[20];
char Intro[6];
char Outro[6];
bool ReplaceSpecialFields;
char SpecialFieldPrefix[6];
char TimeFormat[20];
};
typedef void (*ReplaceFieldCallback)(const char* fieldExpr, Dictionary* args, char* value, ReplaceFieldParams* params);
char* FieldReplacer_GetTimeString(char* value, const char* format = "HH:mm:ss", bool utc = false);
void FieldReplacer_ReplaceField(const char* fieldExpr, Dictionary* args, char* value, ReplaceFieldParams* params);
char* FieldReplacer_ReplaceSpecialField(const char* fieldExpr, char* value, ReplaceFieldParams* params);
class FieldReplacer
{
protected:
virtual const char* FindMatchingOutro(const char* text);
//virtual bool ProcessEscapes_1(const char* text, char* out);
//virtual bool ProcessEscapes_2(const char* text, char* out);
public:
ReplaceFieldParams Params;
FieldReplacer();
virtual bool ReplaceFields(const char* text, Dictionary* args, ReplaceFieldCallback callback, char* value);
};
|
jacobussystems/IoTJackAC1 | src/MessageFilterItem.h | <reponame>jacobussystems/IoTJackAC1
/*
MessageFilterItem.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#else
#include "stdafx.h"
#endif
class MessageFilterItem
{
protected:
public:
bool IgnoreCase;
int Operation; // enumeration, e.g. ARDJACK_STRING_COMPARE_EQUALS
char Text[20];
MessageFilterItem();
bool Active();
bool Evaluate(const char* value);
char* ToString(char* out);
};
|
jacobussystems/IoTJackAC1 | src/HttpConnection.h | /*
HttpConnection.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
// HTTP method types.
const static int HTTP_METHOD_GET = 0;
const static int HTTP_METHOD_POST = 1;
#ifdef ARDUINO
#include <arduino.h>
#include "DetectBoard.h"
#endif
#include "TcpConnection.h"
#ifdef ARDJACK_NETWORK_AVAILABLE
class HttpConnection : public TcpConnection
{
protected:
#ifdef ARDUINO
virtual bool PollRequests(DateTime* now);
virtual bool PollResponses(DateTime* now);
virtual bool ProcessRequest(const char* line) override;
#ifdef ARDJACK_WIFI_AVAILABLE
virtual bool SendServerResponse(WiFiClient client, char* line);
#endif
#endif
public:
HttpConnection(const char* name);
~HttpConnection();
#ifdef ARDUINO
virtual bool SendText(const char* text) override;
#endif
};
#endif
|
jacobussystems/IoTJackAC1 | src/PartManager.h | /*
PartManager.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#define _strlwr strlwr
#else
#include "stdafx.h"
#include <typeinfo>
#endif
class Enumeration;
class Part;
class PartManager
{
protected:
public:
static Enumeration* PartSubtypes;
static Enumeration* PartTypes;
PartManager();
~PartManager();
virtual Part* CreatePart(const char* name, int type, int subtype);
virtual Part* CreateUserPart(const char* name, int type, int subtype);
static const char* GetPartTypeName(int partType);
static bool IsAnalogType(int type);
static bool IsDigitalType(int type);
static bool IsInputType(int type);
static bool IsOutputType(int type);
static bool IsTextualType(int type);
static int LookupSubtype(const char* name, bool quiet = false);
static int LookupType(const char* name, bool quiet = false);
static const char* PartSubtypeName(int subtype, const char* defaultName = "");
static const char* PartTypeName(int subtype, const char* defaultName = "?");
};
|
jacobussystems/IoTJackAC1 | src/Log.h | <reponame>jacobussystems/IoTJackAC1
/*
Log.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#else
#include "stdafx.h"
#endif
#include "FifoBuffer.h"
typedef void(*Logger_Callback)(const char* text);
static const int ARDJACK_LOG_ERROR = 0;
static const int ARDJACK_LOG_EXCEPTION = 1;
static const int ARDJACK_LOG_INFO = 2;
static const int ARDJACK_LOG_WARNING = 3;
class Log
{
protected:
#ifdef ARDUINO
static char _CurLine[240];
#else
static char _CurLine[1000];
#endif
static FifoBuffer _OutputBuffer;
static bool CheckOutputBuffer(int maxCount = 6);
static bool Output(const char* text);
static void Write(const char* text);
static void WriteInternal(const char* caption, const char* arg0, const char* arg1, const char* arg2, const char* arg3,
const char* arg4, const char* arg5, const char* arg6, const char* arg7, const char* arg8, const char* arg9);
static void WriteMemory();
static void WriteString(const char* caption, const char* text);
static void WriteTime();
public:
static bool Buffered;
static bool IncludeMemory;
static bool IncludeTime;
static bool InUnitTest;
static char Prefix[20];
static bool UseSerial;
static bool UseSerialUSB;
#ifdef ARDUINO
#else
static Logger_Callback LoggerCallback; // a callback for output during Unit Tests
#endif
static void Flush();
static bool Init();
static void LogError(const char* arg0 = NULL, const char* arg1 = NULL, const char* arg2 = NULL,
const char* arg3 = NULL, const char* arg4 = NULL, const char* arg5 = NULL, const char* arg6 = NULL,
const char* arg7 = NULL, const char* arg8 = NULL, const char* arg9 = NULL);
static void LogErrorF(const char* format, ...);
static void LogException(const char* source, int code = -1, const char* arg0 = NULL, const char* arg1 = NULL,
const char* arg2 = NULL, const char* arg3 = NULL, const char* arg4 = NULL, const char* arg5 = NULL,
const char* arg6 = NULL, const char* arg7 = NULL, const char* arg8 = NULL, const char* arg9 = NULL);
static void LogInfo(const char* arg0 = NULL, const char* arg1 = NULL, const char* arg2 = NULL,
const char* arg3 = NULL, const char* arg4 = NULL, const char* arg5 = NULL, const char* arg6 = NULL,
const char* arg7 = NULL, const char* arg8 = NULL, const char* arg9 = NULL);
static void LogInfoF(const char* format, ...);
static void LogItem(int type, const char* arg0 = NULL, const char* arg1 = NULL, const char* arg2 = NULL,
const char* arg3 = NULL, const char* arg4 = NULL, const char* arg5 = NULL, const char* arg6 = NULL,
const char* arg7 = NULL, const char* arg8 = NULL, const char* arg9 = NULL);
static void LogItemF(int type, const char* format, ...);
static void LogWarning(const char* arg0 = NULL, const char* arg1 = NULL, const char* arg2 = NULL,
const char* arg3 = NULL, const char* arg4 = NULL, const char* arg5 = NULL, const char* arg6 = NULL,
const char* arg7 = NULL, const char* arg8 = NULL, const char* arg9 = NULL);
static void LogWarningF(const char* format, ...);
static void Poll();
};
|
jacobussystems/IoTJackAC1 | src/ArduinoDHT.h | <reponame>jacobussystems/IoTJackAC1
/*
ArduinoDHT.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#ifdef ARDJACK_INCLUDE_ARDUINO_DHT
/*
Uses the 'SimpleDHT' library from:
https://github.com/winlinvip/SimpleDHT
By default uses pin 2 for the DHT sensor data, so connect:
'+' +5V (or +3.3V)
'out' pin 2
'-' Ground
Can reconfigure 'Pin' for the DHT Part, e.g. to swap input 'di0' (usually pin 3) and the DHT sensor (usually pin 2)
on Device 'ard':
configure ard.di0 pin=2
configure ard.dht0 pin=3
*/
#include <SimpleDHT.h>
#include "UserPart.h"
class ArduinoDHT : public UserPart
{
protected:
SimpleDHT11* _Dht11;
int _Dht11_MinInterval;
SimpleDHT22* _Dht22;
int _Dht22_MinInterval;
int _Interval;
int _Model;
char _ModelName[ARDJACK_MAX_NAME_LENGTH];
long _NextSampleTime;
int _Variable;
char _VariableName[ARDJACK_MAX_NAME_LENGTH];
virtual bool DeleteObjects();
public:
ArduinoDHT();
~ArduinoDHT();
virtual bool Activate() override;
virtual bool AddConfig() override;
virtual bool Deactivate() override;
virtual bool Read(Dynamic* value) override;
};
#endif
#endif
|
jacobussystems/IoTJackAC1 | src/TcpConnection.h | <reponame>jacobussystems/IoTJackAC1
/*
TcpConnection.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#include "DetectBoard.h"
#ifdef ARDJACK_ETHERNET_AVAILABLE
#include <Ethernet.h>
#endif
#ifdef ARDJACK_WIFI_AVAILABLE
#include <WiFiClient.h>
#include <WiFiServer.h>
#endif
#else
#endif
#include "Connection.h"
#include "DateTime.h"
#ifdef ARDJACK_NETWORK_AVAILABLE
class TcpConnection : public Connection
{
protected:
bool _ClientConnected;
int _InputPort;
char _OutputIp[20];
int _OutputPort;
#ifdef ARDUINO
#ifdef ARDJACK_ETHERNET_AVAILABLE
EthernetClient* _Client;
EthernetServer* _Server;
#endif
#ifdef ARDJACK_WIFI_AVAILABLE
WiFiClient* _Client; // local TCP client for 'talking' (sending output)
WiFiServer* _Server; // local TCP server for 'listening' (receiving input)
#endif
virtual bool Activate() override;
virtual bool Deactivate() override;
virtual bool PollInputs(int maxCount) override;
virtual bool PollRequests();
virtual bool PollResponses();
virtual bool ProcessRequest(const char* line);
virtual bool ProcessServerResponse(const char* line);
virtual bool StartListening();
virtual bool StartTalking();
virtual bool StopListening();
virtual bool StopTalking();
#endif
public:
TcpConnection(const char* name);
~TcpConnection();
virtual bool AddConfig() override;
#ifdef ARDUINO
virtual bool SendText(const char* text) override;
#endif
};
#endif
|
jacobussystems/IoTJackAC1 | src/WiFiLibrary.h | /*
WiFiLibrary.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
// Arduino only.
#include <arduino.h>
#include "DetectBoard.h"
#include "Globals.h"
//--------------------------------------------------------------------------------------------------------------------------
// IMPORTANT:
//--------------------------------------------------------------------------------------------------------------------------
// FOR VISUAL STUDIO + VISUAL MICRO, YOU NEED TO COMMENT/UNCOMMENT THE FOLLOWING THREE #includes TO MATCH THE BOARD IN USE.
// We tried using the ArdJack conditionals, but got weird errors when compiling in Visual Studio + Visual Micro.
// - Comment all 3 #includes for Arduino Due.
// - Repeat this in ArdJack.ino.
// MKR1010 etc.
#include <WiFiNINA.h>
// ESP32 boards.
//#include <WiFi.h>
// Other boards with WiFi.
//#include <WiFi101.h>
//--------------------------------------------------------------------------------------------------------------------------
#endif
|
jacobussystems/IoTJackAC1 | src/ArduinoDevice.h | /*
ArduinoDevice.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include "DetectBoard.h"
#include "Device.h"
class Dynamic;
class ArduinoDevice : public Device
{
protected:
virtual bool ApplyConfig(bool quiet) override;
#ifdef ARDJACK_ARDUINO_DUE
bool ConfigureDUE();
#endif
#ifdef ARDJACK_ARDUINO_MEGA2560
bool ConfigureMega2560();
#endif
#ifdef ARDJACK_ARDUINO_MKR
bool ConfigureArduinoMKR();
#endif
#ifdef ARDJACK_ARDUINO_SAMD_ZERO
bool ConfigureSparkFunRedBoardTurbo();
#endif
#ifdef ARDJACK_ARDUINO_UNO
bool ConfigureUno();
#endif
#ifdef ARDJACK_ESP32
bool ConfigureEspressifESP32();
#endif
#ifdef ARDJACK_FEATHER_M0
bool ConfigureFeatherM0();
#endif
virtual bool CreateDefaultInventory() override;
virtual bool ReadAnalog(Part* part, Dynamic* value);
virtual bool ReadDigital(Part* part, Dynamic* value);
virtual bool WriteAnalog(Part* part, Dynamic* value);
virtual bool WriteDigital(Part* part, Dynamic* value);
public:
ArduinoDevice(const char* name);
~ArduinoDevice();
virtual bool AddConfig() override;
virtual Part* AddPart(const char* name, int type, int subtype, int pin) override;
virtual bool Read(Part* part, Dynamic* value) override;
virtual bool Write(Part* part, Dynamic* value) override;
};
#endif
|
jacobussystems/IoTJackAC1 | src/Utils.h | /*
Utils.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#include "DetectBoard.h"
#ifdef ARDJACK_ESP32
//#include <uinstd.h>
#else
#ifdef ARDJACK_ARM
// should use uinstd.h to define sbrk but Due causes a conflict
extern "C" char* sbrk(int incr);
#else
extern char *__brkval;
#endif
#endif
#ifdef ARDJACK_NETWORK_AVAILABLE
#include "WiFiLibrary.h"
#endif
#else
#include "stdafx.h"
#endif
#include "DateTime.h"
#include "Globals.h"
#include "StringList.h"
#ifdef ARDUINO
struct MemoryInfo
{
uint32_t FreeRAM;
uint32_t HeapFree;
uint32_t HeapMax;
uint32_t HeapUsed;
uint32_t MallocMargin;
void* RAMBase;
uint32_t RAMSize;
void* SP;
void* StackStart;
};
#endif
static const uint8_t _DaysInMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static const char* _ShortMonthNames = "JanFebMarAprMayJunJulAugSepOctNovDec";
class Utils
{
protected:
static char Buffer_Bool2[6];
static char Buffer_Int2String[10];
public:
static void AddTime_Ms(DateTime* time, long interval);
static char* Bool210(bool value);
static char* Bool210(bool value, char* result);
static char* Bool2yesno(bool value);
static char* Bool2yesno(bool value, char* result);
static bool CanTrim(const char* text);
static bool CheckMem(bool logIt = false, const char* caption = "");
static bool CompareStrings(const char* value1, int type, const char* value2, bool ignoreCase);
static int CompareTimes(DateTime* time1, DateTime* time2);
static void CopyTime(DateTime* src, DateTime* dest);
//static int DaysInMonth(int month, int year);
static bool DecodeNetworkPath(const char* path, char* computer, char* resource, bool quiet = false);
static void DelayMs(int delay_ms);
static void DelayUs(int delay_us);
static bool DoBeep(int freq_hz = 1000, int dur_ms = 200);
static char* EncodeNetworkPath(char* out, const char* computer, const char* resource);
static const char* FindFirstNonWhitespace(const char* text);
static char* FindNextMulti(const char* text, char chars[], int count, int* index);
static char* FormatTime(char* value, DateTime* dt, const char* format);
static void GetArgs(const char* text, char* firstPart, const char** remainder, char separator = ' ');
static char* GetDateString(char* date, const char* format = NULL, bool utc = false);
static bool GetFirstField(char* pSrc, char separator, char* result, int maxSize, bool trim = true);
static char* GetNow(char* datetime, const char* format = NULL, bool utc = false);
static char* GetTimeString(char* time, const char* format = NULL, bool utc = false);
static unsigned long HostID_To_Address(const char* s);
static const char* Int2String(long value, int radix = 10);
//static bool IsLeapYear(int year);
static bool IsWhite(char ch);
static bool IsWhitespace(char ch);
static bool JoinFields(char* line, char separator, StringList* fields, int start, int count);
static bool JoinFieldsOld(char* line, char separator, char fields[][ARDJACK_MAX_VALUE_LENGTH], int start, int count);
static char* MacAddressToString(uint8_t *mac, char *out);
static int MaxInt(int i, int j);
static void MemFree(void* block);
static void* MemMalloc(size_t size);
static int MinInt(int i, int j);
static int Nint(double value);
static bool Now(DateTime* now, bool utc = false);
static long NowMs();
static char* RepeatChar(char *text, char ch, int count);
static DateTime* SecondsToTime(long seconds, DateTime* dt);
static bool SetDate(const char* text);
static bool SetTime(const char* text);
static bool SplitAtNumber(const char* text, char *name, int *number, int default_Value);
static int SplitText(const char* text, char separator, StringList* fields, int maxCount, int maxSize,
bool trimFields = true);
static int SplitText2Array(const char* text, char separator, char fields[][ARDJACK_MAX_VALUE_LENGTH], int maxCount,
int maxLength, bool trimFields = true);
static bool String2Bool(const char* text, bool defValue = false);
static int String2Comparison(const char* name, int defValue = ARDJACK_STRING_COMPARE_TRUE, bool quiet = false);
static double String2Double(const char* text, double defValue = 0.0);
static float String2Float(const char* text, float defValue = 0.0);
static int String2Int(const char* text, int defValue = 0);
static long String2Long(const char* text, long defValue = 0);
static char* StringComparisonTypeName(int type, char* out);
static bool StringContains(const char* value1, const char* value2, bool ignoreCase = true);
static bool StringEndsWith(const char* value1, const char* value2, bool ignoreCase = true);
static bool StringEquals(const char* value1, const char* value2, bool ignoreCase = true);
static bool StringIsNullOrEmpty(const char* text);
static int StringLen(const char* text);
static char* StringReplace(const char* source, const char* str1, const char* str2,
bool ignoreCase, char* out, int size);
static char* StringReplaceMultiHex(const char* source, char chars[], int replacements[], int count, char* out, int size);
static bool StringStartsWith(const char* value1, const char* value2, bool ignoreCase = true);
static char* TimeToDateString(DateTime* dt, char *out, const char* format = "%d/%d/%d");
static char* TimeToString(DateTime* dt, char *out, const char* format = "%d/%d/%d %02d:%02d:%02d");
static char* TimeToTimeString(DateTime* dt, char *out, const char* format = "%02d:%02d:%02d.%03d");
static char *Trim(char *text);
#ifdef ARDUINO
static size_t GetFreeRAM();
static bool GetMemoryInfo(MemoryInfo* memInfo);
#ifdef ARDJACK_NETWORK_AVAILABLE
static char* IpAddressToString(IPAddress ip, char *out);
#endif
#else
static bool CreateFolder(const char* folder);
static bool FileExists(const char* filename);
static bool FolderExists(const char* folder);
static char* GetAppDocsFolder(char* folder, int size);
static bool GetComputerInfo(char* hostName, char* ipAddress);
static bool GetTimeOfDay(struct timeval* tp, struct timezone* tzp);
static char* GetUserDocsFolder(char* folder, int size);
static bool InitializeWinsock();
//static void PostString(HWND hwnd, const char* text);
static bool TerminateWinsock();
#endif
};
|
jacobussystems/IoTJackAC1 | src/IniFiler.h | <reponame>jacobussystems/IoTJackAC1
/*
IniFiler.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#include "Globals.h"
#include "IoTObject.h"
#include "Log.h"
#include "Utils.h"
const static int INIFILER_SECTION_NONE = 0;
const static int INIFILER_SECTION_DESCRIPTION = 1;
const static int INIFILER_SECTION_GENERAL = 2;
const static int INIFILER_SECTION_OBJECT = 3;
class IniFiler
{
protected:
IoTObject* _CurObject;
uint8_t _CurSectionType; // enumeration: INIFILER_SECTION_NONE etc.
virtual bool ReadLine_Description(const char* line);
virtual bool ReadLine_General(const char* line);
virtual bool ReadLine_Object(const char* line);
virtual bool ReadLine_SectionStart(const char* line);
public:
char CommentPrefix[8];
IniFiler();
virtual bool ReadLine(const char* line); // caller provides the next line to read in 'line'
};
|
jacobussystems/IoTJackAC1 | src/UrlEncoder.h | // UrlEncoder.h
#pragma once
// Implements the encoding/decoding described at:
// https://www.lifewire.com/encoding-urls-3467463
//
// : %3B
// / %2F
// # %23
// ? %3F
// & %24
// @ %40
// % %25
// + %2B
// %20 or + in query strings
class UrlEncoder
{
protected:
char _Chars[10];
int _Codes[10];
char _CodeStrings[10][4];
int _Count;
public:
UrlEncoder();
virtual char* Decode(const char* text, char* out, int size);
virtual char* Encode(const char* text, char* out, int size);
};
|
jacobussystems/IoTJackAC1 | src/DateTime.h | /*
DateTime.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#include <stdint.h>
class DateTime
{
protected:
public:
uint8_t Day; // day of the month [1, 31]
bool DST; // Daylight Savings Time flag
uint8_t Hours; // hours since midnight [0, 23]
uint16_t Milliseconds; // milliseconds after the second [0, 999]
uint8_t Minutes; // minutes after the hour [0, 59]
uint8_t Month; // months since January [0, 11]
uint8_t Seconds; // seconds after the minute [0, 59]
bool UTC;
uint16_t Year; // year, e.g. 2019
DateTime();
virtual void Clear();
virtual void Copy(DateTime* src);
};
|
jacobussystems/IoTJackAC1 | src/Filter.h | <gh_stars>0
/*
Filter.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#else
#include "stdafx.h"
#endif
#include "Globals.h"
#include "IoTObject.h"
// This is a signal filter, used to debounce digital inputs, or slow the data rate for analog inputs.
// Not to be confused with a Message Filter used in routing - see MessageFilter.h / MessageFilter.cpp.
class Filter : public IoTObject
{
protected:
int _MaxInterval;
int _MinInterval; // for debounce filtering
double _MinDiff;
virtual bool Activate() override;
public:
Filter(const char* name);
~Filter();
virtual bool AddConfig() override;
virtual bool ApplyConfig(bool quiet = false) override;
virtual bool EvaluateAnalog(double newValue, double lastNotifiedValue, long lastNotifiedMs);
virtual bool EvaluateDigital(bool newState, bool lastNotifiedState, long lastNotifiedMs,
bool lastChangeState, long lastChangeMs);
};
|
jacobussystems/IoTJackAC1 | src/WiFiInterface.h | <gh_stars>0
/*
WiFiInterface.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#include "DetectBoard.h"
#include "Globals.h"
#ifdef ARDJACK_WIFI_AVAILABLE
#include "IoTObject.h"
#include "NetworkInterface.h"
#include "WiFiLibrary.h"
class WiFiInterface : public NetworkInterface
{
protected:
int _ConnectMode; // connect mode enumeration: ARDJACK_WIFI_CONNECT_OPEN, etc.
Enumeration* _ConnectModes;
char _ConnectModeStr[20];
char _DHCPHostname[30];
int _KeyIndex; // key index (for WEP only)
char _Password[30];
char _SSID[30];
int _Status;
int _Timeout; // timeout (ms)
virtual bool Connect();
virtual bool Disconnect();
virtual bool GetConnectionInfo();
virtual char* GetStatusAsString(int status, char *out);
public:
char BSSIDStr[20];
int Channel;
int Encryption; // encryption type enumeration: ENC_TYPE_AUTO, etc.
IPAddress GatewayIp;
IPAddress LocalIp;
char MacStr[20];
IPAddress SubnetMask;
WiFiInterface(const char* name);
virtual bool Activate() override;
virtual bool AddConfig() override;
virtual bool Deactivate() override;
static char* GetEncryptionTypeName(int type, char* out);
virtual DateTime* GetNetworkTime(DateTime* out) override;
virtual void LogStatus(bool refresh = false) override;
virtual bool LookupHost(const char* host, IPAddress& ipAddress) override;
virtual bool Ping(const char* host) override;
virtual bool ScanWiFi() override;
virtual int SignalStrength();
};
#endif
#endif
|
jacobussystems/IoTJackAC1 | src/IoTMessage.h | /*
IoTMessage.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#else
#include "stdafx.h"
#endif
#include "Globals.h"
class StringList;
class IoTMessage
{
protected:
// Indexes in '_Items'.
static const uint8_t MESSAGE_FROM_PATH = 0; // source path (format 1 only)
static const uint8_t MESSAGE_RETURN_PATH = 1; // return path (format 1 only, and only
// if not equal to the 'From' path)
static const uint8_t MESSAGE_TEXT = 2; // the text, e.g. a command, request or response
static const uint8_t MESSAGE_TO_PATH = 3; // destination path (format 1 only)
static const uint8_t MESSAGE_TYPE = 4; // the message type
static const uint8_t MESSAGE_WIRETEXT = 5; // full transmitted/received text,
// e.g. text (format 0), header + text (format 1)
StringList* _Items;
virtual void Clear();
//virtual bool DecodeFormat0(const char* line);
virtual bool DecodeFormat1(const char* line);
virtual bool EncodeFormat0();
virtual bool EncodeFormat1();
public:
uint8_t Format; // enumeration: ARDJACK_MESSAGE_FORMAT_0 etc.
IoTMessage();
~IoTMessage();
static bool CreateMessageToSend(const char* type, int format, const char* text, IoTMessage* msg, const char* fromPath = "",
const char* toPath = "", const char* returnPath = "");
virtual bool Decode(const char* line);
virtual bool Encode();
virtual const char* FromPath();
virtual void LogIt();
virtual const char* ReturnPath();
virtual bool SetFromPath(const char* text);
virtual bool SetReturnPath(const char* text);
virtual bool SetText(const char* text);
virtual bool SetToPath(const char* text);
virtual bool SetType(const char* text);
virtual bool SetWireText(const char* text);
virtual const char* Text();
virtual const char* ToPath();
virtual const char* ToString(char* text);
virtual const char* Type();
virtual const char* WireText();
};
|
jacobussystems/IoTJackAC1 | src/MemoryFreeExt.h | /*
MemoryFreeExt.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#include "Utils.h"
#ifdef ARDUINO
// Based on 'MemoryFree' downloaded 8 Aug 2019 from:
// https://github.com/McNeight/MemoryFree
// MemoryFree library based on code posted here:
// http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1213583720/15
// Extended by Matthew Murdoch to include walking of the free list.
extern "C" { bool GetHeapInfo(MemoryInfo* memInfo); }
#endif
|
jacobussystems/IoTJackAC1 | src/Configuration.h | <reponame>jacobussystems/IoTJackAC1<filename>src/Configuration.h<gh_stars>0
/*
Configuration.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#include "DetectBoard.h"
#else
#include "stdafx.h"
#endif
#include "Globals.h"
class ConfigProp;
class Configuration
{
protected:
virtual bool GetSizes(int *nameSize, int *valueSize, int *descSize);
public:
char Name[ARDJACK_MAX_NAME_LENGTH];
uint8_t PropCount;
ConfigProp* Properties[ARDJACK_MAX_CONFIG_PROPERTIES];
Configuration();
~Configuration();
virtual ConfigProp* Add(const char* name, int dataType, const char* desc, const char* unit = "");
virtual ConfigProp* AddBooleanProp(const char* name, const char* desc, bool value = false, const char* unit = "");
//virtual ConfigProp* AddChild(const char* name, ConfigProp* parent, int dataType, const char* desc, const char* unit = "");
virtual ConfigProp* AddIntegerProp(const char* name, const char* desc, int value = 0, const char* unit = "");
virtual ConfigProp* AddRealProp(const char* name, const char* desc, double value = 0.0, const char* unit = "");
virtual ConfigProp* AddStringProp(const char* name, const char* desc, const char* value = "", const char* unit = "");
virtual bool GetAsBoolean(const char* path, bool* value);
virtual bool GetAsInteger(const char* path, int* value);
virtual bool GetAsReal(const char* path, double* value);
virtual bool GetAsString(const char* path, char* value);
virtual bool LogIt();
virtual ConfigProp* LookupPath(const char* path);
virtual bool SetFromString(const char* path, const char* value);
virtual bool SortItems();
};
|
jacobussystems/IoTJackAC1 | src/ConfigProp.h | /*
ConfigProp.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#include "DetectBoard.h"
#else
#include "stdafx.h"
#endif
#include <stdint.h>
#include "Globals.h"
class StringList;
class ConfigProp
{
protected:
StringList* _Strings; // [0] Name, [1] Description, [2] Unit, [3] Value
public:
uint8_t DataType; // enumeration ARDJACK_DATATYPE_BOOLEAN etc.
//ConfigProp* Parent;
bool Value_Boolean;
long Value_Integer;
double Value_Real;
ConfigProp();
~ConfigProp();
virtual const char* Description();
virtual bool GetAsBoolean(bool* value);
virtual bool GetAsInteger(int* value);
virtual bool GetAsReal(double* value);
virtual bool GetAsString(char* value);
virtual const char* Name();
//virtual char* Path(char* out);
virtual bool SetDescription(const char* value);
virtual bool SetFromString(const char* value);
virtual bool SetName(const char* value);
virtual bool SetUnit(const char* value);
virtual const char* StringValue();
virtual const char* Unit();
};
|
jacobussystems/IoTJackAC1 | src/PipeConnection.h | <filename>src/PipeConnection.h
#pragma once
#ifdef ARDUINO
#else
#include "stdafx.h"
#include "npipe.h"
#include "Connection.h"
#include "Globals.h"
class PipeConnection :
public Connection
{
private:
CNamedPipe InPipe;
CNamedPipe OutPipe;
public:
char InPipeName[MAX_NAME_SIZE];
char OutPipeName[MAX_NAME_SIZE];
PipeConnection(const char *name);
~PipeConnection();
bool OutputMessage(IoTMessage *msg);
bool PollInput(int maxCount=5);
bool PollOutput(int maxCount=5);
bool SendQueuedOutput(IoTMessage *msg);
};
#endif
|
jacobussystems/IoTJackAC1 | src/Device.h | <reponame>jacobussystems/IoTJackAC1
/*
Device.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#else
#include "stdafx.h"
#endif
#include "Filter.h"
#include "Globals.h"
#include "IoTMessage.h"
#include "IoTObject.h"
class Connection;
class DeviceCodec1;
//class Dictionary;
class Dynamic;
class FieldReplacer;
class Shield;
class StringList;
class Device : public IoTObject
{
protected:
bool _IsOpen;
int _MessageFormat;
char _MessagePrefix[10];
char _MessageToPath[20];
IoTMessage _ResponseMsg;
#ifdef ARDJACK_INCLUDE_SHIELDS
char _ShieldName[ARDJACK_MAX_NAME_LENGTH];
#endif
virtual bool Activate() override;
virtual bool ApplyConfig(bool quiet = false) override;
virtual bool CheckInput(Part* part, bool* change);
virtual bool CloseParts();
virtual bool Deactivate() override;
virtual bool OpenParts();
virtual bool PollInputs();
virtual bool PollOutputs();
virtual bool PollParts();
virtual bool ValidateConfig(bool quiet = false) override;
public:
char DeviceClass[ARDJACK_MAX_NAME_LENGTH];
DeviceCodec1* DeviceCodec;
#ifdef ARDJACK_INCLUDE_SHIELDS
Shield* DeviceShield;
#endif
char DeviceType[ARDJACK_MAX_NAME_LENGTH];
char DeviceVersion[ARDJACK_MAX_NAME_LENGTH];
Connection* InputConnection;
int InputTimeout; // ms
Connection* OutputConnection;
uint8_t PartCount;
Part* Parts[ARDJACK_MAX_PARTS];
int ReadEvents;
int WriteEvents;
Device(const char* name);
~Device();
virtual bool AddConfig() override;
virtual Part* AddPart(const char* name, int type, int subtype, int pin);
virtual bool AddParts(const char* prefix, int count, int type, int subtype, int startIndex, int startPin);
virtual bool ClearInventory();
virtual bool Close();
virtual bool Configure(const char* entity, StringList* settings, int start, int count) override;
#ifdef ARDJACK_INCLUDE_SHIELDS
virtual bool ConfigureForShield();
#endif
virtual bool ConfigureParts(const char* partExpr, StringList* settings, int start, int count);
virtual bool CreateDefaultInventory();
virtual bool DoBeep(int index, int freqHz, int durMs);
virtual bool DoFlash(const char* name = "led0", int durMs = 20);
virtual int GetCount(int partType);
virtual bool GetParts(const char* expr, Part* parts[], uint8_t* count, bool quiet = false);
virtual bool GetPartsOfType(int partType, Part* parts[], uint8_t* count);
static int LookupOperation(const char* name);
virtual Part* LookupPart(const char* name, bool quiet = false);
virtual Part* LookupPart(const char* name, int type, int subtype, bool quiet = false);
virtual bool LookupParts(const char* names, Part* parts[], uint8_t* count);
virtual bool Open();
virtual bool Poll() override;
virtual bool PrepareForCreateInventory();
virtual bool Read(Part* part, Dynamic* value);
#ifdef ARDJACK_INCLUDE_MULTI_PARTS
virtual bool ReadMulti(Part* part, char* value);
#endif
virtual bool RemoveOldParts();
virtual bool ScanInputs(bool* changes, int count, int delayMs);
virtual bool ScanInputsOnce(bool* changes, bool signal = false);
//virtual bool Send(int oper, int partType, int index, char values[][ARDJACK_MAX_VALUE_LENGTH]);
virtual bool SendInventory(bool includePartConfig = true, bool includeZeroCounts = false);
virtual bool SendPartConfig(Part* part);
virtual bool SignalChange_Configuration(Part* part);
virtual bool SignalChange_Value(Part* part);
virtual bool SendResponse(int oper, const char* aName, const char* text);
virtual bool SetNotify(Part* part, bool state);
virtual bool SetNotify(int partType, bool state);
virtual bool Update();
virtual bool Write(Part* part, Dynamic* value);
#ifdef ARDJACK_INCLUDE_MULTI_PARTS
virtual bool WriteMulti(Part* part, const char* value);
#endif
};
|
jacobussystems/IoTJackAC1 | ArdJackW/src/VellemanK8055Device.h | /*
VellermanK8055Device.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
// Windows only.
#ifdef ARDUINO
#else
#include "stdafx.h"
#include "Device.h"
#include "Globals.h"
// WARNING - Can't create more than one instance of 'VellemanK8055Device' until '_hDLL' and 'Velleman_ClearAllAnalog' etc.
// are re-designed (static?).
class VellemanK8055Device :
public Device
{
protected:
HINSTANCE _hDLL;
virtual bool InitDLL();
virtual bool ReadAnalog(Part* part, Dynamic* value);
virtual bool ReadDigital(Part* part, Dynamic* value);
virtual bool WriteAnalog(Part* part, Dynamic* value);
virtual bool WriteDigital(Part* part, Dynamic* value);
typedef void(CALLBACK* t_func)(int);
typedef void(CALLBACK* t_func0)();
typedef int(CALLBACK* t_func1)();
typedef void(CALLBACK* t_func2)(int*, int*);
typedef void(CALLBACK* t_func3)(int, int);
typedef int(CALLBACK* t_func4)(int);
typedef bool(CALLBACK* t_func5)(int);
t_func0 Velleman_ClearAllAnalog;
t_func0 Velleman_ClearAllDigital;
t_func Velleman_ClearAnalogChannel;
t_func Velleman_ClearDigitalChannel;
t_func0 Velleman_CloseDevice;
t_func4 Velleman_OpenDevice;
t_func3 Velleman_OutputAllAnalog;
t_func3 Velleman_OutputAnalogChannel;
t_func2 Velleman_ReadAllAnalog;
t_func1 Velleman_ReadAllDigital;
t_func4 Velleman_ReadAnalogChannel;
t_func5 Velleman_ReadDigitalChannel;
t_func0 Velleman_SetAllAnalog;
t_func0 Velleman_SetAllDigital;
t_func Velleman_SetAnalogChannel;
t_func Velleman_SetDigitalChannel;
t_func0 Velleman_Version;
t_func Velleman_WriteAllDigital;
public:
VellemanK8055Device(const char* name);
~VellemanK8055Device();
virtual bool CreateDefaultInventory() override;
virtual bool Open() override;
virtual bool Read(Part* part, Dynamic* value) override;
virtual bool Write(Part* part, Dynamic* value) override;
};
#endif
|
jacobussystems/IoTJackAC1 | src/Dynamic.h | /*
Dynamic.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#include "Globals.h"
class Filter;
class DateTime;
class Dynamic
{
protected:
union
{
bool _BoolVal;
//DateTime _DateTimeVal;
double _DoubleVal;
int _IntVal;
char _StringVal[ARDJACK_MAX_DYNAMIC_STRING_LENGTH];
};
uint8_t _DataType;
//int _DataType;
public:
Dynamic();
~Dynamic();
bool AsBool();
//DateTime AsDateTime();
double AsDouble();
int AsInt();
char* AsString(char* value);
void Clear();
bool Copy(Dynamic* src);
int DataType();
bool Equals(Dynamic* src, bool ignoreCase = false);
bool IsEmpty();
bool SetBool(bool value);
//bool SetDateTime(DateTime value);
bool SetDouble(double value);
bool SetInt(int value);
bool SetString(const char* value);
const char* String();
const char* ToString(char* text);
bool ValuesDiffer(Dynamic* src, bool ignoreCase = false, Filter* filter = NULL, bool lastChangeState = false,
long lastChangeMs = 0, long lastNotifiedMs = 0);
};
|
jacobussystems/IoTJackAC1 | src/PersistentFile.h | <filename>src/PersistentFile.h<gh_stars>0
/*
PersistentFile.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#ifdef ARDUINO
#include <arduino.h>
#include "DetectBoard.h"
#include "FlashLibrary.h"
//#ifdef ARDJACK_FLASH_AVAILABLE
// #ifdef ARDJACK_ARDUINO_DUE
// #include <FlashAsEEPROM.h>
// #else
// #include <FlashStorage.h>
// #endif
//#endif
#else
//#include "WProgram.h"
#endif
#include "Globals.h"
#ifdef ARDJACK_INCLUDE_PERSISTENCE
class PersistentFileManager;
// The struct that is persisted (multiple times) by the 'PersistentFile' class.
typedef struct
{
char Line[ARDJACK_PERSISTED_LINE_LENGTH];
} PersistentFileLine;
class PersistentFile
{
protected:
int _LineIndex; // read line index (0-based)
bool _WriteMode;
#ifdef ARDUINO
#else
FILE* _File;
#endif
public:
int LineCount; // no.of lines read, or written so far
PersistentFileManager* Manager;
char Name[ARDJACK_MAX_NAME_LENGTH];
#ifdef ARDUINO
int StartLineInFlash;
#else
char Filename[MAX_PATH];
#endif
PersistentFile();
virtual bool Close();
virtual bool Eof();
virtual bool Gets(char* line, int size);
virtual bool IsOpen();
virtual bool Open(const char* mode);
virtual bool PutNameValuePair(const char* name, const char* value);
virtual bool Puts(const char* line);
};
#endif
|
jacobussystems/IoTJackAC1 | src/Enumeration.h | <reponame>jacobussystems/IoTJackAC1<gh_stars>0
/*
Enumeration.h
By <NAME>
Jacobus Systems, Brighton & Hove, UK
http://www.jacobus.co.uk
Provided under the MIT license: https://github.com/jacobussystems/ArdJack/blob/master/LICENSE
Copyright (c) 2019 <NAME>, Jacobus Systems, Brighton & Hove, UK
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#pragma once
#include "Globals.h"
#include "Int8List.h"
#include "StringList.h"
class Enumeration
{
protected:
public:
char Name[ARDJACK_MAX_NAME_LENGTH];
StringList Names;
Int8List Values;
Enumeration(const char* name);
~Enumeration();
virtual bool Add(const char* name, int8_t value);
virtual void Clear();
virtual int Count();
virtual int8_t LookupName(const char* name, int8_t defaultValue = -1, bool quiet = false);
virtual const char* LookupValue(int8_t value, const char* defaultName = "?", bool quiet = false); // returns the first match
};
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.